限制绘画提示词长度,修复移动端角色和模型绑定失败问题

This commit is contained in:
RockYang
2025-02-23 06:56:38 +08:00
parent 63fd125439
commit a3f0576535
17 changed files with 91 additions and 17 deletions

View File

@@ -56,6 +56,11 @@ func (h *DallJobHandler) Image(c *gin.Context) {
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
// 检查用户剩余算力
user, err := h.GetLoginUser(c)
if err != nil {

View File

@@ -91,6 +91,11 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
var params = ""
if data.Rate != "" && !strings.Contains(params, "--ar") {
params += " --ar " + data.Rate

View File

@@ -56,11 +56,15 @@ func (h *PromptHandler) Lyric(c *gin.Context) {
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成歌词",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, content)
@@ -82,11 +86,15 @@ func (h *PromptHandler) Image(c *gin.Context) {
}
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成绘画提示词",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, strings.Trim(content, `"`))
}
@@ -108,11 +116,15 @@ func (h *PromptHandler) Video(c *gin.Context) {
if h.App.SysConfig.PromptPower > 0 {
userId := h.GetLoginUserId(c)
h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
err = h.userService.DecreasePower(int(userId), h.App.SysConfig.PromptPower, model.PowerLog{
Type: types.PowerConsume,
Model: h.getPromptModel(),
Remark: "生成视频脚本",
})
if err != nil {
resp.ERROR(c, err.Error())
return
}
}
resp.SUCCESS(c, strings.Trim(content, `"`))

View File

@@ -102,6 +102,10 @@ func (h *SdJobHandler) Image(c *gin.Context) {
if data.Sampler == "" {
data.Sampler = "Euler a"
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
idValue, _ := c.Get(types.LoginUserID)
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, err := h.snowflake.Next(true)

View File

@@ -56,6 +56,15 @@ func (h *VideoHandler) LumaCreate(c *gin.Context) {
resp.ERROR(c, types.InvalidArgs)
return
}
// 检查 Prompt 长度
if data.Prompt == "" {
resp.ERROR(c, "prompt is needed")
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
user, err := h.GetLoginUser(c)
if err != nil {
@@ -68,11 +77,6 @@ func (h *VideoHandler) LumaCreate(c *gin.Context) {
return
}
if data.Prompt == "" {
resp.ERROR(c, "prompt is needed")
return
}
userId := int(h.GetLoginUserId(c))
params := types.LumaVideoParams{
PromptOptimize: data.ExpandPrompt,
@@ -156,6 +160,10 @@ func (h *VideoHandler) KeLingCreate(c *gin.Context) {
resp.ERROR(c, "prompt is needed")
return
}
if len(data.Prompt) > 2000 {
resp.ERROR(c, "提示词太长,请删减提示词。")
return
}
userId := int(h.GetLoginUserId(c))
params := types.KeLingVideoParams{