feat: add sora video fetch task
This commit is contained in:
@@ -184,6 +184,9 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
|
|||||||
modelRequest.Model = values[0]
|
modelRequest.Model = values[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if c.Request.Method == http.MethodGet {
|
||||||
|
relayMode = relayconstant.RelayModeVideoFetchByID
|
||||||
|
shouldSelectChannel = false
|
||||||
}
|
}
|
||||||
c.Set("relay_mode", relayMode)
|
c.Set("relay_mode", relayMode)
|
||||||
} else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
|
} else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
|
||||||
|
|||||||
@@ -32,12 +32,9 @@ type ImageURL struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type responsePayload struct {
|
|
||||||
ID string `json:"id"` // task_id
|
|
||||||
}
|
|
||||||
|
|
||||||
type responseTask struct {
|
type responseTask struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
TaskID string `json:"task_id,omitempty"` //兼容旧接口
|
||||||
Object string `json:"object"`
|
Object string `json:"object"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
@@ -108,18 +105,22 @@ func (a *TaskAdaptor) DoResponse(c *gin.Context, resp *http.Response, _ *relayco
|
|||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
|
|
||||||
// Parse Sora response
|
// Parse Sora response
|
||||||
var dResp responsePayload
|
var dResp responseTask
|
||||||
if err := json.Unmarshal(responseBody, &dResp); err != nil {
|
if err := json.Unmarshal(responseBody, &dResp); err != nil {
|
||||||
taskErr = service.TaskErrorWrapper(errors.Wrapf(err, "body: %s", responseBody), "unmarshal_response_body_failed", http.StatusInternalServerError)
|
taskErr = service.TaskErrorWrapper(errors.Wrapf(err, "body: %s", responseBody), "unmarshal_response_body_failed", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if dResp.ID == "" {
|
if dResp.ID == "" {
|
||||||
|
if dResp.TaskID == "" {
|
||||||
taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError)
|
taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dResp.ID = dResp.TaskID
|
||||||
|
dResp.TaskID = ""
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"task_id": dResp.ID})
|
c.JSON(http.StatusOK, dResp)
|
||||||
return dResp.ID, responseBody, nil
|
return dResp.ID, responseBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func SetVideoRouter(router *gin.Engine) {
|
|||||||
// docs: https://platform.openai.com/docs/api-reference/videos/create
|
// docs: https://platform.openai.com/docs/api-reference/videos/create
|
||||||
{
|
{
|
||||||
videoV1Router.POST("/videos", controller.RelayTask)
|
videoV1Router.POST("/videos", controller.RelayTask)
|
||||||
|
videoV1Router.GET("/videos/:id", controller.RelayTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
klingV1Router := router.Group("/kling/v1")
|
klingV1Router := router.Group("/kling/v1")
|
||||||
|
|||||||
Reference in New Issue
Block a user