feat: channel kling support New API
This commit is contained in:
@@ -114,3 +114,23 @@ type KlingImage2VideoRequest struct {
|
||||
CallbackURL string `json:"callback_url,omitempty" example:"https://your.domain/callback"`
|
||||
ExternalTaskId string `json:"external_task_id,omitempty" example:"custom-task-002"`
|
||||
}
|
||||
|
||||
// KlingImage2videoTaskId godoc
|
||||
// @Summary 可灵任务查询--图生视频
|
||||
// @Description Query the status and result of a Kling video generation task by task ID
|
||||
// @Tags Origin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param task_id path string true "Task ID"
|
||||
// @Router /kling/v1/videos/image2video/{task_id} [get]
|
||||
func KlingImage2videoTaskId(c *gin.Context) {}
|
||||
|
||||
// KlingText2videoTaskId godoc
|
||||
// @Summary 可灵任务查询--文生视频
|
||||
// @Description Query the status and result of a Kling text-to-video generation task by task ID
|
||||
// @Tags Origin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param task_id path string true "Task ID"
|
||||
// @Router /kling/v1/videos/text2video/{task_id} [get]
|
||||
func KlingText2videoTaskId(c *gin.Context) {}
|
||||
|
||||
@@ -2,13 +2,16 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"one-api/common"
|
||||
"one-api/constant"
|
||||
"one-api/dto"
|
||||
"one-api/model"
|
||||
"one-api/relay"
|
||||
"one-api/relay/channel"
|
||||
relaycommon "one-api/relay/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -77,13 +80,21 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
|
||||
return fmt.Errorf("readAll failed for task %s: %w", taskId, err)
|
||||
}
|
||||
|
||||
taskResult, err := adaptor.ParseTaskResult(responseBody)
|
||||
if err != nil {
|
||||
taskResult := &relaycommon.TaskInfo{}
|
||||
// try parse as New API response format
|
||||
var responseItems dto.TaskResponse[model.Task]
|
||||
if err = json.Unmarshal(responseBody, &responseItems); err == nil {
|
||||
t := responseItems.Data
|
||||
taskResult.TaskID = t.TaskID
|
||||
taskResult.Status = string(t.Status)
|
||||
taskResult.Url = t.FailReason
|
||||
taskResult.Progress = t.Progress
|
||||
taskResult.Reason = t.FailReason
|
||||
} else if taskResult, err = adaptor.ParseTaskResult(responseBody); err != nil {
|
||||
return fmt.Errorf("parseTaskResult failed for task %s: %w", taskId, err)
|
||||
} else {
|
||||
task.Data = responseBody
|
||||
}
|
||||
//if taskResult.Code != 0 {
|
||||
// return fmt.Errorf("video task fetch failed for task %s", taskId)
|
||||
//}
|
||||
|
||||
now := time.Now().Unix()
|
||||
if taskResult.Status == "" {
|
||||
@@ -128,8 +139,6 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
|
||||
if taskResult.Progress != "" {
|
||||
task.Progress = taskResult.Progress
|
||||
}
|
||||
|
||||
task.Data = responseBody
|
||||
if err := task.Update(); err != nil {
|
||||
common.SysError("UpdateVideoTask task error: " + err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user