fix: fixed bug for register error with parse args

This commit is contained in:
RockYang 2023-09-26 09:30:18 +08:00
parent 48393e0e83
commit db0a79da93
6 changed files with 20 additions and 10 deletions

View File

@ -548,10 +548,17 @@ func (h *MidJourneyHandler) JobList(c *gin.Context) {
if err != nil { if err != nil {
continue continue
} }
if item.Progress < 100 && item.ImgURL != "" { // 正在运行中任务使用代理访问图片 if item.Progress < 100 {
image, err := utils.DownloadImage(item.ImgURL, h.App.Config.ProxyURL) // 30 分钟还没完成的任务直接删除
if err == nil { if time.Now().Sub(item.CreatedAt) > time.Minute*30 {
job.ImgURL = "data:image/png;base64," + base64.StdEncoding.EncodeToString(image) h.db.Delete(&item)
continue
}
if item.ImgURL != "" { // 正在运行中任务使用代理访问图片
image, err := utils.DownloadImage(item.ImgURL, h.App.Config.ProxyURL)
if err == nil {
job.ImgURL = "data:image/png;base64," + base64.StdEncoding.EncodeToString(image)
}
} }
} }
jobs = append(jobs, job) jobs = append(jobs, job)

View File

@ -109,18 +109,16 @@ func (s *MjService) Run() {
} }
if err != nil { if err != nil {
logger.Error("绘画任务执行失败:", err) logger.Error("绘画任务执行失败:", err)
if task.RetryCount > 5 { if task.RetryCount <= 5 {
// 取消并删除任务 s.taskQueue.RPush(task)
s.db.Where("id = ?", task.Id).Delete(&model.MidJourneyJob{})
continue
} }
task.RetryCount += 1 task.RetryCount += 1
s.taskQueue.RPush(task)
// TODO: 执行失败通知聊天客户端
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
continue continue
} }
// 更新任务的执行状态
s.db.Model(&model.MidJourneyJob{}).Where("id = ?", task.Id).UpdateColumn("started", true)
// 锁定任务执行通道直到任务超时5分钟 // 锁定任务执行通道直到任务超时5分钟
s.redis.Set(ctx, MjRunningJobKey, utils.JsonEncode(task), time.Minute*5) s.redis.Set(ctx, MjRunningJobKey, utils.JsonEncode(task), time.Minute*5)
} }

View File

@ -12,6 +12,7 @@ type MidJourneyJob struct {
Hash string // message hash Hash string // message hash
Progress int Progress int
Prompt string Prompt string
Started bool
CreatedAt time.Time CreatedAt time.Time
} }

View File

@ -13,4 +13,5 @@ type MidJourneyJob struct {
Progress int `json:"progress"` Progress int `json:"progress"`
Prompt string `json:"prompt"` Prompt string `json:"prompt"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Started bool `json:"started"`
} }

View File

@ -0,0 +1,2 @@
ALTER TABLE `chatgpt_mj_jobs` ADD `started` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '任务是否开始' AFTER `progress`;
UPDATE `chatgpt_mj_jobs` SET started = 1

View File

@ -143,6 +143,7 @@ const register = function () {
if (enableMsg.value && formData.value.code === '') { if (enableMsg.value && formData.value.code === '') {
return ElMessage.error('请输入短信验证码'); return ElMessage.error('请输入短信验证码');
} }
formData.value.code = parseInt(formData.value.code)
httpPost('/api/user/register', formData.value).then(() => { httpPost('/api/user/register', formData.value).then(() => {
ElMessage.success({"message": "注册成功,即将跳转到登录页...", onClose: () => router.push("/login")}) ElMessage.success({"message": "注册成功,即将跳转到登录页...", onClose: () => router.push("/login")})
}).catch((e) => { }).catch((e) => {