mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-06 17:23:42 +08:00
feat: add midjourney message receive handler
This commit is contained in:
@@ -24,6 +24,7 @@ type Image struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Size int `json:"size"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
type MidJourneyHandler struct {
|
||||
@@ -44,18 +45,30 @@ func (h *MidJourneyHandler) Notify(c *gin.Context) {
|
||||
}
|
||||
|
||||
var data struct {
|
||||
Image Image `json:"image"`
|
||||
Content string `json:"content"`
|
||||
Status TaskStatus `json:"status"`
|
||||
Type string `json:"type"`
|
||||
MessageId string `json:"message_id"`
|
||||
Image Image `json:"image"`
|
||||
Content string `json:"content"`
|
||||
Prompt string `json:"prompt"`
|
||||
Status TaskStatus `json:"status"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
if err := c.ShouldBindJSON(&data); err != nil || data.Prompt == "" {
|
||||
resp.ERROR(c, types.InvalidArgs)
|
||||
return
|
||||
}
|
||||
key := utils.Sha256(data.Prompt)
|
||||
data.Key = key
|
||||
// TODO: 如果绘画任务完成了则将该消息保存到当前会话的聊天历史记录
|
||||
|
||||
sessionId := "u7blnft9zqisyrwidjb22j6b78iqc30lv9jtud3k9o"
|
||||
wsClient := h.App.ChatClients.Get(sessionId)
|
||||
utils.ReplyMessage(wsClient, "")
|
||||
logger.Infof("Data: %+v", data)
|
||||
wsClient := h.App.MjTaskClients.Get(key)
|
||||
if wsClient == nil { // 客户端断线,则丢弃
|
||||
resp.SUCCESS(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 推送消息到客户端
|
||||
// TODO: 增加绘画消息类型
|
||||
utils.ReplyChunkMessage(wsClient, types.WsMessage{Type: types.WsImg, Content: data})
|
||||
resp.ERROR(c, "Error with CallBack")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user