diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9704f06f..8209e37f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,8 +3,10 @@
## v4.2.1
- 功能新增:新增支持可灵生成视频。
+- Bug修复:修复移动端聊天页面新建对话时候角色没有更模型绑定的 Bug。
- 功能优化:优化聊天页面代码块样式,优化公式的解析。
-- Bug 修复:优化 Redis 连接池配置,增加连接池超时时间,单核服务器报错 `redis: connection pool timeout`。
+- 功能优化:在绘图,视频相关 API 增加提示词长度的检查,防止提示词超出导致写入数据库失败。
+- Bug修复:优化 Redis 连接池配置,增加连接池超时时间,单核服务器报错 `redis: connection pool timeout`。
## v4.2.0
diff --git a/api/handler/dalle_handler.go b/api/handler/dalle_handler.go
index f3079e27..9e0ceda9 100644
--- a/api/handler/dalle_handler.go
+++ b/api/handler/dalle_handler.go
@@ -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 {
diff --git a/api/handler/mj_handler.go b/api/handler/mj_handler.go
index a845d740..48399cbd 100644
--- a/api/handler/mj_handler.go
+++ b/api/handler/mj_handler.go
@@ -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
diff --git a/api/handler/prompt_handler.go b/api/handler/prompt_handler.go
index 596d0a45..7c062ffe 100644
--- a/api/handler/prompt_handler.go
+++ b/api/handler/prompt_handler.go
@@ -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, `"`))
diff --git a/api/handler/sd_handler.go b/api/handler/sd_handler.go
index 93ca386e..55893fad 100644
--- a/api/handler/sd_handler.go
+++ b/api/handler/sd_handler.go
@@ -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)
diff --git a/api/handler/video_handler.go b/api/handler/video_handler.go
index 1fa8cf86..d09a746c 100644
--- a/api/handler/video_handler.go
+++ b/api/handler/video_handler.go
@@ -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{
diff --git a/api/service/types.go b/api/service/types.go
index e8b48203..aa55873f 100644
--- a/api/service/types.go
+++ b/api/service/types.go
@@ -54,7 +54,7 @@ Here is an example of how the final prompt should look:
- Mood: Intense, mysterious
- Lighting: Dramatic contrast with light filtering through leaves
- **Output Prompt**: "A realistic rendering of a white tiger stealthily moving through a dense jungle, with an intense, mysterious mood. The lighting creates strong contrasts as beams of sunlight filter through a thick canopy of leaves."
+ **Output Prompt**: "A realistic rendering of a white tiger, stealthily moving through a dense jungle, with an intense, mysterious mood. The lighting creates strong contrasts as beams of sunlight filter through a thick canopy of leaves."
2. **Input**:
- Subject: An enchanted castle on a floating island
diff --git a/web/src/utils/libs.js b/web/src/utils/libs.js
index ef7933d7..7bb6054f 100644
--- a/web/src/utils/libs.js
+++ b/web/src/utils/libs.js
@@ -244,7 +244,7 @@ export function showLoginDialog(router) {
export const replaceImg = (img) => {
if (!img.startsWith("http")) {
- img = `${location.protocol}//${location.host}/${img}`;
+ img = `${location.protocol}//${location.host}${img}`;
}
const devHost = process.env.VUE_APP_API_HOST;
const localhost = "http://localhost:5678";
diff --git a/web/src/views/Dalle.vue b/web/src/views/Dalle.vue
index 9852485e..51684985 100644
--- a/web/src/views/Dalle.vue
+++ b/web/src/views/Dalle.vue
@@ -66,6 +66,7 @@
:autosize="{ minRows: 4, maxRows: 6 }"
type="textarea"
ref="promptRef"
+ maxlength="2000"
placeholder="请在此输入绘画提示词,您也可以点击下面的提示词助手生成绘画提示词"
v-loading="isGenerating"
/>
diff --git a/web/src/views/ImageMj.vue b/web/src/views/ImageMj.vue
index e612c770..2fa6b3a6 100644
--- a/web/src/views/ImageMj.vue
+++ b/web/src/views/ImageMj.vue
@@ -175,6 +175,7 @@