fix: add unique key for MidJourney task_id

This commit is contained in:
RockYang 2024-01-03 18:06:10 +08:00
parent 434fbb3463
commit d8e4308b1b
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 {
TaskId string `json:"task_id"`
Index int `json:"index"`
ChannelId string `json:"channel_id"`
MessageId string `json:"message_id"`
@ -206,11 +205,12 @@ func (h *MidJourneyHandler) Upscale(c *gin.Context) {
idValue, _ := c.Get(types.LoginUserID)
jobId := 0
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, _ := h.snowflake.Next(true)
job := model.MidJourneyJob{
Type: types.TaskUpscale.String(),
ReferenceId: data.MessageId,
UserId: userId,
TaskId: data.TaskId,
TaskId: taskId,
Progress: 0,
Prompt: data.Prompt,
CreatedAt: time.Now(),
@ -253,13 +253,13 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) {
idValue, _ := c.Get(types.LoginUserID)
jobId := 0
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
taskId, _ := h.snowflake.Next(true)
job := model.MidJourneyJob{
Type: types.TaskVariation.String(),
ChannelId: data.ChannelId,
ReferenceId: data.MessageId,
UserId: userId,
TaskId: data.TaskId,
TaskId: taskId,
Progress: 0,
Prompt: data.Prompt,
CreatedAt: time.Now(),

View File

@ -1,6 +1,7 @@
package handler
import (
"chatplus/service"
"chatplus/store/model"
"chatplus/utils"
"chatplus/utils/resp"
@ -11,13 +12,18 @@ import (
type TestHandler struct {
db *gorm.DB
snowflake *service.Snowflake
}
func NewTestHandler(db *gorm.DB) *TestHandler {
return &TestHandler{db: db}
func NewTestHandler(db *gorm.DB, snowflake *service.Snowflake) *TestHandler {
return &TestHandler{db: db, snowflake: snowflake}
}
func (h *TestHandler) Test(c *gin.Context) {
h.initMjTaskId(c)
}
func (h *TestHandler) initUserNickname(c *gin.Context) {
var users []model.User
tx := h.db.Find(&users)
if tx.Error != nil {
@ -32,3 +38,20 @@ func (h *TestHandler) Test(c *gin.Context) {
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
}
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 != "" {
tx = tx.Where("reference_id = ?", data.ReferenceId)
} else {
tx = tx.Where("task_id = ?", split[0])
}
res = tx.First(&job)
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_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>
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">
@ -45,18 +46,21 @@ html, body {
text-overflow: ellipsis;
white-space: nowrap;
}
.sl {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.sl3 {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
.sl4 {
display: -webkit-box;
-webkit-box-orient: vertical;
@ -71,6 +75,7 @@ html, body {
left: 50%;
transform: translate(-50%, -50%);
}
.h_center {
width: 100%;
position: absolute;
@ -78,6 +83,7 @@ html, body {
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}
.w_center {
position: absolute;
left: 50%;

View File

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

View File

@ -109,7 +109,7 @@
</el-tooltip>
</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-tooltip
effect="dark"