🎨 新增封禁用户返回,新增批量上传机器人功能
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/bot"
|
||||
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
)
|
||||
@@ -165,3 +166,33 @@ func (btService *BotService) generateKeywordVariants(input string) []string {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (btService *BotService) BulkBot(p botReq.BulkBot, userName string) (err error) {
|
||||
var bots []bot.Bot
|
||||
|
||||
for _, a := range p.Files {
|
||||
content := "<p><img src=" + a + " alt=\"" + a + "\" data-href=\"\" style=\"width: 100%;height: auto;\"/></p>"
|
||||
bots = append(bots, bot.Bot{
|
||||
Keyword: getBotKeyWorld(a),
|
||||
Content: &content,
|
||||
CreateBy: userName,
|
||||
})
|
||||
}
|
||||
|
||||
if len(bots) > 0 {
|
||||
if dbErr := global.GVA_DB.Create(&bots).Error; dbErr != nil {
|
||||
global.GVA_LOG.Error("批量上传文章失败", zap.Error(dbErr))
|
||||
return dbErr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBotKeyWorld(url string) string {
|
||||
lastSlash := strings.LastIndex(url, "/")
|
||||
underscore := strings.Index(url[lastSlash+1:], "_")
|
||||
if lastSlash == -1 || underscore == -1 {
|
||||
return ""
|
||||
}
|
||||
return url[lastSlash+1 : lastSlash+1+underscore]
|
||||
}
|
||||
|
Reference in New Issue
Block a user