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"
@ -10,14 +11,19 @@ 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">
@ -41,155 +42,160 @@ html, body {
/* 省略显示 */ /* 省略显示 */
.ellipsis { .ellipsis {
overflow: hidden; overflow: hidden;
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;
-webkit-line-clamp: 3; -webkit-line-clamp: 3;
overflow: hidden; overflow: hidden;
} }
/* 居中布局 */ /* 居中布局 */
.auto_center{ .auto_center {
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%,-50%); transform: translate(-50%, -50%);
} }
.h_center{
width: 100%; .h_center {
position: absolute; width: 100%;
top: 50%; position: absolute;
transform: translateY(-50%); top: 50%;
-webkit-transform: translateY(-50%); transform: translateY(-50%);
-webkit-transform: translateY(-50%);
} }
.w_center{
position: absolute; .w_center {
left: 50%; position: absolute;
transform: translateX(-50%); left: 50%;
-webkit-transform: translateX(-50%); transform: translateX(-50%);
-webkit-transform: translateX(-50%);
} }
/* flex布局 */ /* flex布局 */
.flex-row { .flex-row {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
} }
.flex-col { .flex-col {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.justify-start { .justify-start {
justify-content: flex-start; justify-content: flex-start;
} }
.justify-end { .justify-end {
justify-content: flex-end; justify-content: flex-end;
} }
.justify-center { .justify-center {
justify-content: center; justify-content: center;
} }
.justify-between { .justify-between {
justify-content: space-between; justify-content: space-between;
} }
.justify-around { .justify-around {
justify-content: space-around; justify-content: space-around;
} }
.justify-evenly { .justify-evenly {
justify-content: space-evenly; justify-content: space-evenly;
} }
.items-start { .items-start {
align-items: flex-start; align-items: flex-start;
} }
.items-end { .items-end {
align-items: flex-end; align-items: flex-end;
} }
.items-center { .items-center {
align-items: center; align-items: center;
} }
.items-baseline { .items-baseline {
align-items: baseline; align-items: baseline;
} }
.items-stretch { .items-stretch {
align-items: stretch; align-items: stretch;
} }
.self-start { .self-start {
align-self: flex-start; align-self: flex-start;
} }
.self-end { .self-end {
align-self: flex-end; align-self: flex-end;
} }
.self-center { .self-center {
align-self: center; align-self: center;
} }
.self-baseline { .self-baseline {
align-self: baseline; align-self: baseline;
} }
.self-stretch { .self-stretch {
align-self: stretch; align-self: stretch;
} }
.flex-1 { .flex-1 {
flex: 1 1 0%; flex: 1 1 0%;
} }
.flex-auto { .flex-auto {
flex: 1 1 auto; flex: 1 1 auto;
} }
.grow { .grow {
flex-grow: 1; flex-grow: 1;
} }
.grow-0 { .grow-0 {
flex-grow: 0; flex-grow: 0;
} }
.shrink { .shrink {
flex-shrink: 1; flex-shrink: 1;
} }
.shrink-0 { .shrink-0 {
flex-shrink: 0; flex-shrink: 0;
} }
.shrink-1 { .shrink-1 {
flex-shrink: 1; flex-shrink: 1;
} }
.relative { .relative {
position: relative; position: relative;
} }
</style> </style>

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"