feat: add sora video fetch task

This commit is contained in:
feitianbubu
2025-10-10 15:25:29 +08:00
parent 3c57cfbf71
commit 2479da4986
3 changed files with 13 additions and 8 deletions

View File

@@ -184,6 +184,9 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
modelRequest.Model = values[0]
}
}
} else if c.Request.Method == http.MethodGet {
relayMode = relayconstant.RelayModeVideoFetchByID
shouldSelectChannel = false
}
c.Set("relay_mode", relayMode)
} else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {

View File

@@ -32,12 +32,9 @@ type ImageURL struct {
URL string `json:"url"`
}
type responsePayload struct {
ID string `json:"id"` // task_id
}
type responseTask struct {
ID string `json:"id"`
TaskID string `json:"task_id,omitempty"` //兼容旧接口
Object string `json:"object"`
Model string `json:"model"`
Status string `json:"status"`
@@ -108,18 +105,22 @@ func (a *TaskAdaptor) DoResponse(c *gin.Context, resp *http.Response, _ *relayco
_ = resp.Body.Close()
// Parse Sora response
var dResp responsePayload
var dResp responseTask
if err := json.Unmarshal(responseBody, &dResp); err != nil {
taskErr = service.TaskErrorWrapper(errors.Wrapf(err, "body: %s", responseBody), "unmarshal_response_body_failed", http.StatusInternalServerError)
return
}
if dResp.ID == "" {
taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError)
return
if dResp.TaskID == "" {
taskErr = service.TaskErrorWrapper(fmt.Errorf("task_id is empty"), "invalid_response", http.StatusInternalServerError)
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
}

View File

@@ -19,6 +19,7 @@ func SetVideoRouter(router *gin.Engine) {
// docs: https://platform.openai.com/docs/api-reference/videos/create
{
videoV1Router.POST("/videos", controller.RelayTask)
videoV1Router.GET("/videos/:id", controller.RelayTask)
}
klingV1Router := router.Group("/kling/v1")