mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-11 11:43:43 +08:00
feat: add midjouney api implements, optimize function calls
This commit is contained in:
61
api/handler/mj_handler.go
Normal file
61
api/handler/mj_handler.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"chatplus/core"
|
||||
"chatplus/core/types"
|
||||
"chatplus/utils"
|
||||
"chatplus/utils/resp"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TaskStatus string
|
||||
|
||||
const (
|
||||
Start = TaskStatus("Started")
|
||||
Running = TaskStatus("Running")
|
||||
Stopped = TaskStatus("Stopped")
|
||||
Finished = TaskStatus("Finished")
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
URL string `json:"url"`
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
Filename string `json:"filename"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
type MidJourneyHandler struct {
|
||||
BaseHandler
|
||||
}
|
||||
|
||||
func NewMidJourneyHandler(app *core.AppServer) *MidJourneyHandler {
|
||||
h := MidJourneyHandler{}
|
||||
h.App = app
|
||||
return &h
|
||||
}
|
||||
|
||||
func (h *MidJourneyHandler) Notify(c *gin.Context) {
|
||||
token := c.GetHeader("Authorization")
|
||||
if token != h.App.Config.ExtConfig.Token {
|
||||
resp.NotAuth(c)
|
||||
return
|
||||
}
|
||||
|
||||
var data struct {
|
||||
Image Image `json:"image"`
|
||||
Content string `json:"content"`
|
||||
Status TaskStatus `json:"status"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
resp.ERROR(c, types.InvalidArgs)
|
||||
return
|
||||
}
|
||||
|
||||
sessionId := "u7blnft9zqisyrwidjb22j6b78iqc30lv9jtud3k9o"
|
||||
wsClient := h.App.ChatClients.Get(sessionId)
|
||||
utils.ReplyMessage(wsClient, "")
|
||||
logger.Infof("Data: %+v", data)
|
||||
resp.ERROR(c, "Error with CallBack")
|
||||
}
|
||||
Reference in New Issue
Block a user