fix: add unique key for MidJourney task_id

This commit is contained in:
RockYang 2024-01-03 18:06:10 +08:00
parent 023dc89c3e
commit 3d75093b2c
7 changed files with 103 additions and 70 deletions

View File

@ -179,7 +179,6 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
} }
type reqVo struct { type reqVo struct {
TaskId string `json:"task_id"`
Index int `json:"index"` Index int `json:"index"`
ChannelId string `json:"channel_id"` ChannelId string `json:"channel_id"`
MessageId string `json:"message_id"` MessageId string `json:"message_id"`
@ -206,11 +205,12 @@ func (h *MidJourneyHandler) Upscale(c *gin.Context) {
idValue, _ := c.Get(types.LoginUserID) idValue, _ := c.Get(types.LoginUserID)
jobId := 0 jobId := 0
userId := utils.IntValue(utils.InterfaceToString(idValue), 0) userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, _ := h.snowflake.Next(true)
job := model.MidJourneyJob{ job := model.MidJourneyJob{
Type: types.TaskUpscale.String(), Type: types.TaskUpscale.String(),
ReferenceId: data.MessageId, ReferenceId: data.MessageId,
UserId: userId, UserId: userId,
TaskId: data.TaskId, TaskId: taskId,
Progress: 0, Progress: 0,
Prompt: data.Prompt, Prompt: data.Prompt,
CreatedAt: time.Now(), CreatedAt: time.Now(),
@ -253,13 +253,13 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) {
idValue, _ := c.Get(types.LoginUserID) idValue, _ := c.Get(types.LoginUserID)
jobId := 0 jobId := 0
userId := utils.IntValue(utils.InterfaceToString(idValue), 0) userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, _ := h.snowflake.Next(true)
job := model.MidJourneyJob{ job := model.MidJourneyJob{
Type: types.TaskVariation.String(), Type: types.TaskVariation.String(),
ChannelId: data.ChannelId, ChannelId: data.ChannelId,
ReferenceId: data.MessageId, ReferenceId: data.MessageId,
UserId: userId, UserId: userId,
TaskId: data.TaskId, TaskId: taskId,
Progress: 0, Progress: 0,
Prompt: data.Prompt, Prompt: data.Prompt,
CreatedAt: time.Now(), CreatedAt: time.Now(),

View File

@ -1,6 +1,7 @@
package handler package handler
import ( import (
"chatplus/service"
"chatplus/store/model" "chatplus/store/model"
"chatplus/utils" "chatplus/utils"
"chatplus/utils/resp" "chatplus/utils/resp"
@ -11,13 +12,18 @@ import (
type TestHandler struct { type TestHandler struct {
db *gorm.DB db *gorm.DB
snowflake *service.Snowflake
} }
func NewTestHandler(db *gorm.DB) *TestHandler { func NewTestHandler(db *gorm.DB, snowflake *service.Snowflake) *TestHandler {
return &TestHandler{db: db} return &TestHandler{db: db, snowflake: snowflake}
} }
func (h *TestHandler) Test(c *gin.Context) { func (h *TestHandler) Test(c *gin.Context) {
h.initMjTaskId(c)
}
func (h *TestHandler) initUserNickname(c *gin.Context) {
var users []model.User var users []model.User
tx := h.db.Find(&users) tx := h.db.Find(&users)
if tx.Error != nil { if tx.Error != nil {
@ -32,3 +38,20 @@ func (h *TestHandler) Test(c *gin.Context) {
resp.SUCCESS(c) resp.SUCCESS(c)
} }
func (h *TestHandler) initMjTaskId(c *gin.Context) {
var jobs []model.MidJourneyJob
tx := h.db.Find(&jobs)
if tx.Error != nil {
resp.ERROR(c, tx.Error.Error())
return
}
for _, job := range jobs {
id, _ := h.snowflake.Next(true)
job.TaskId = id
h.db.Updates(&job)
}
resp.SUCCESS(c)
}

View File

@ -121,9 +121,11 @@ func (s *Service) Notify(data CBReq) {
return return
} }
tx := s.db.Where("task_id = ? AND progress < 100", split[0]).Session(&gorm.Session{}).Order("id ASC") tx := s.db.Session(&gorm.Session{}).Order("id ASC")
if data.ReferenceId != "" { if data.ReferenceId != "" {
tx = tx.Where("reference_id = ?", data.ReferenceId) tx = tx.Where("reference_id = ?", data.ReferenceId)
} else {
tx = tx.Where("task_id = ?", split[0])
} }
res = tx.First(&job) res = tx.First(&job)
if res.Error != nil { if res.Error != nil {

View File

@ -1,2 +1,5 @@
ALTER TABLE `chatgpt_users` ADD `nickname` VARCHAR(30) NOT NULL COMMENT '昵称' AFTER `mobile`; ALTER TABLE `chatgpt_users` ADD `nickname` VARCHAR(30) NOT NULL COMMENT '昵称' AFTER `mobile`;
ALTER TABLE `chatgpt_rewards` ADD `exchange` VARCHAR(255) NOT NULL COMMENT '兑换详情json' AFTER `status`; ALTER TABLE `chatgpt_rewards` ADD `exchange` VARCHAR(255) NOT NULL COMMENT '兑换详情json' AFTER `status`;
ALTER TABLE `chatgpt_api_keys` ADD `api_url` VARCHAR(255) NULL COMMENT 'API 地址' AFTER `last_used_at`, ADD `enabled` TINYINT(1) NULL COMMENT '是否启用' AFTER `api_url`;
ALTER TABLE `chatgpt_api_keys` DROP INDEX `value`;
ALTER TABLE `chatgpt_mj_jobs` ADD UNIQUE(`task_id`);

View File

@ -6,7 +6,8 @@
<script setup> <script setup>
import {ElConfigProvider} from 'element-plus'; import {ElConfigProvider} from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';</script> import zhCn from 'element-plus/es/locale/lang/zh-cn';
</script>
<style lang="stylus"> <style lang="stylus">
@ -45,18 +46,21 @@ html, body {
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.sl { .sl {
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
overflow: hidden; overflow: hidden;
} }
.sl3 { .sl3 {
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
-webkit-line-clamp: 3; -webkit-line-clamp: 3;
overflow: hidden; overflow: hidden;
} }
.sl4 { .sl4 {
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
@ -71,6 +75,7 @@ html, body {
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
.h_center { .h_center {
width: 100%; width: 100%;
position: absolute; position: absolute;
@ -78,6 +83,7 @@ html, body {
transform: translateY(-50%); transform: translateY(-50%);
-webkit-transform: translateY(-50%); -webkit-transform: translateY(-50%);
} }
.w_center { .w_center {
position: absolute; position: absolute;
left: 50%; left: 50%;

View File

@ -711,7 +711,6 @@ const variation = (index, item) => {
const send = (url, index, item) => { const send = (url, index, item) => {
httpPost(url, { httpPost(url, {
index: index, index: index,
task_id: item.task_id,
channel_id: item.channel_id, channel_id: item.channel_id,
message_id: item.message_id, message_id: item.message_id,
message_hash: item.hash, message_hash: item.hash,

View File

@ -109,7 +109,7 @@
</el-tooltip> </el-tooltip>
</el-form-item> </el-form-item>
<el-form-item label="显示公告" prop="show_demo_notice"> <el-form-item label="显示演示公告" prop="show_demo_notice">
<el-switch v-model="system['show_demo_notice']"/> <el-switch v-model="system['show_demo_notice']"/>
<el-tooltip <el-tooltip
effect="dark" effect="dark"