🎨 新增封禁用户返回,新增批量上传机器人功能
This commit is contained in:
@@ -131,6 +131,11 @@ func (*AppUserApi) WechatLogin(ctx *gin.Context) {
|
|||||||
r.FailWithMessage("登录失败:"+err.Error(), ctx)
|
r.FailWithMessage("登录失败:"+err.Error(), ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Status == 0 {
|
||||||
|
r.Banned("用户已被禁用", ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
// 生成token
|
// 生成token
|
||||||
token, claims, err := user_jwt.LoginToken(user)
|
token, claims, err := user_jwt.LoginToken(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -208,6 +213,11 @@ func (*AppUserApi) PwdLogin(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Status == 0 {
|
||||||
|
r.Banned("用户已被禁用", ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 生成token
|
// 生成token
|
||||||
token, claims, err := user_jwt.LoginToken(user)
|
token, claims, err := user_jwt.LoginToken(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"git.echol.cn/loser/lckt/model/bot"
|
"git.echol.cn/loser/lckt/model/bot"
|
||||||
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
||||||
"git.echol.cn/loser/lckt/model/common/response"
|
"git.echol.cn/loser/lckt/model/common/response"
|
||||||
|
"git.echol.cn/loser/lckt/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@@ -191,3 +192,22 @@ func (btApi *BotApi) FindKey(c *gin.Context) {
|
|||||||
|
|
||||||
response.OkWithDetailed(bt, "获取成功", c)
|
response.OkWithDetailed(bt, "获取成功", c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BulkBot 批量创建机器人
|
||||||
|
func (btApi *BotApi) BulkBot(c *gin.Context) {
|
||||||
|
var p botReq.BulkBot
|
||||||
|
if err := c.ShouldBind(&p); err != nil {
|
||||||
|
response.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
name := utils.GetUserName(c)
|
||||||
|
|
||||||
|
err := btService.BulkBot(p, name)
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("批量创建失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("批量创建失败:"+err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OkWithMessage("批量创建成功", c)
|
||||||
|
}
|
||||||
|
@@ -14,3 +14,7 @@ type BotSearch struct {
|
|||||||
type FindKey struct {
|
type FindKey struct {
|
||||||
KeyWord string `json:"keyWord" form:"keyWord"`
|
KeyWord string `json:"keyWord" form:"keyWord"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BulkBot struct {
|
||||||
|
Files []string `json:"files" form:"files" binding:"required"`
|
||||||
|
}
|
||||||
|
@@ -61,3 +61,12 @@ func NoAuth(message string, c *gin.Context) {
|
|||||||
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||||
Result(ERROR, data, message, c)
|
Result(ERROR, data, message, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Banned 被封禁
|
||||||
|
func Banned(message string, c *gin.Context) {
|
||||||
|
c.JSON(403, Response{
|
||||||
|
4,
|
||||||
|
nil,
|
||||||
|
message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -17,6 +17,7 @@ func (s *BotRouter) InitBotRouter(Router *gin.RouterGroup, PublicRouter *gin.Rou
|
|||||||
btRouter.DELETE("deleteBot", btApi.DeleteBot) // 删除机器人
|
btRouter.DELETE("deleteBot", btApi.DeleteBot) // 删除机器人
|
||||||
btRouter.DELETE("deleteBotByIds", btApi.DeleteBotByIds) // 批量删除机器人
|
btRouter.DELETE("deleteBotByIds", btApi.DeleteBotByIds) // 批量删除机器人
|
||||||
btRouter.PUT("updateBot", btApi.UpdateBot) // 更新机器人
|
btRouter.PUT("updateBot", btApi.UpdateBot) // 更新机器人
|
||||||
|
btRouter.POST("bulkBot", btApi.BulkBot) // 机器人批量操作
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
btRouterWithoutRecord.GET("findBot", btApi.FindBot) // 根据ID获取机器人
|
btRouterWithoutRecord.GET("findBot", btApi.FindBot) // 根据ID获取机器人
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"git.echol.cn/loser/lckt/global"
|
"git.echol.cn/loser/lckt/global"
|
||||||
"git.echol.cn/loser/lckt/model/bot"
|
"git.echol.cn/loser/lckt/model/bot"
|
||||||
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
||||||
|
"go.uber.org/zap"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -165,3 +166,33 @@ func (btService *BotService) generateKeywordVariants(input string) []string {
|
|||||||
|
|
||||||
return result
|
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