mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-08 02:03:42 +08:00
fix: add unique key for MidJourney task_id
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"chatplus/service"
|
||||
"chatplus/store/model"
|
||||
"chatplus/utils"
|
||||
"chatplus/utils/resp"
|
||||
@@ -10,14 +11,19 @@ import (
|
||||
)
|
||||
|
||||
type TestHandler struct {
|
||||
db *gorm.DB
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user