feat: add sora video retrieve task
This commit is contained in:
@@ -47,6 +47,11 @@ func updateVideoTaskAll(ctx context.Context, platform constant.TaskPlatform, cha
|
|||||||
if adaptor == nil {
|
if adaptor == nil {
|
||||||
return fmt.Errorf("video adaptor not found")
|
return fmt.Errorf("video adaptor not found")
|
||||||
}
|
}
|
||||||
|
info := &relaycommon.RelayInfo{}
|
||||||
|
info.ChannelMeta = &relaycommon.ChannelMeta{
|
||||||
|
ChannelBaseUrl: cacheGetChannel.GetBaseURL(),
|
||||||
|
}
|
||||||
|
adaptor.Init(info)
|
||||||
for _, taskId := range taskIds {
|
for _, taskId := range taskIds {
|
||||||
if err := updateVideoSingleTask(ctx, adaptor, cacheGetChannel, taskId, taskM); err != nil {
|
if err := updateVideoSingleTask(ctx, adaptor, cacheGetChannel, taskId, taskM); err != nil {
|
||||||
logger.LogError(ctx, fmt.Sprintf("Failed to update video task %s: %s", taskId, err.Error()))
|
logger.LogError(ctx, fmt.Sprintf("Failed to update video task %s: %s", taskId, err.Error()))
|
||||||
|
|||||||
@@ -37,22 +37,20 @@ type responsePayload struct {
|
|||||||
|
|
||||||
type responseTask struct {
|
type responseTask struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
Object string `json:"object"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Content struct {
|
Progress int `json:"progress"`
|
||||||
VideoURL string `json:"video_url"`
|
|
||||||
} `json:"content"`
|
|
||||||
Seed int `json:"seed"`
|
|
||||||
Resolution string `json:"resolution"`
|
|
||||||
Duration int `json:"duration"`
|
|
||||||
AspectRatio string `json:"aspect_ratio"`
|
|
||||||
Usage struct {
|
|
||||||
PromptTokens int `json:"prompt_tokens"`
|
|
||||||
CompletionTokens int `json:"completion_tokens"`
|
|
||||||
TotalTokens int `json:"total_tokens"`
|
|
||||||
} `json:"usage"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
CompletedAt int64 `json:"completed_at,omitempty"`
|
||||||
|
ExpiresAt int64 `json:"expires_at,omitempty"`
|
||||||
|
Seconds string `json:"seconds,omitempty"`
|
||||||
|
Size string `json:"size,omitempty"`
|
||||||
|
RemixedFromVideoID string `json:"remixed_from_video_id,omitempty"`
|
||||||
|
Error *struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
} `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================
|
// ============================
|
||||||
@@ -131,15 +129,13 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
|
|||||||
return nil, fmt.Errorf("invalid task_id")
|
return nil, fmt.Errorf("invalid task_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/v1/videos/generations/%s", baseUrl, taskID)
|
uri := fmt.Sprintf("%s/v1/videos/%s", baseUrl, taskID)
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, uri, nil)
|
req, err := http.NewRequest(http.MethodGet, uri, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
req.Header.Set("Authorization", "Bearer "+key)
|
req.Header.Set("Authorization", "Bearer "+key)
|
||||||
|
|
||||||
return service.GetHttpClient().Do(req)
|
return service.GetHttpClient().Do(req)
|
||||||
@@ -163,29 +159,25 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
|
|||||||
Code: 0,
|
Code: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map Sora status to internal status
|
|
||||||
switch resTask.Status {
|
switch resTask.Status {
|
||||||
case "pending", "queued":
|
case "queued", "pending":
|
||||||
taskResult.Status = model.TaskStatusQueued
|
taskResult.Status = model.TaskStatusQueued
|
||||||
taskResult.Progress = "10%"
|
case "processing", "in_progress":
|
||||||
case "processing", "running":
|
|
||||||
taskResult.Status = model.TaskStatusInProgress
|
taskResult.Status = model.TaskStatusInProgress
|
||||||
taskResult.Progress = "50%"
|
case "completed":
|
||||||
case "succeeded", "completed":
|
|
||||||
taskResult.Status = model.TaskStatusSuccess
|
taskResult.Status = model.TaskStatusSuccess
|
||||||
taskResult.Progress = "100%"
|
taskResult.Url = fmt.Sprintf("%s/v1/videos/%s/content", a.baseURL, resTask.ID)
|
||||||
taskResult.Url = resTask.Content.VideoURL
|
|
||||||
// Parse usage information for billing
|
|
||||||
taskResult.CompletionTokens = resTask.Usage.CompletionTokens
|
|
||||||
taskResult.TotalTokens = resTask.Usage.TotalTokens
|
|
||||||
case "failed", "cancelled":
|
case "failed", "cancelled":
|
||||||
taskResult.Status = model.TaskStatusFailure
|
taskResult.Status = model.TaskStatusFailure
|
||||||
taskResult.Progress = "100%"
|
if resTask.Error != nil {
|
||||||
|
taskResult.Reason = resTask.Error.Message
|
||||||
|
} else {
|
||||||
taskResult.Reason = "task failed"
|
taskResult.Reason = "task failed"
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// Unknown status, treat as processing
|
}
|
||||||
taskResult.Status = model.TaskStatusInProgress
|
if resTask.Progress > 0 && resTask.Progress < 100 {
|
||||||
taskResult.Progress = "30%"
|
taskResult.Progress = fmt.Sprintf("%d%%", resTask.Progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &taskResult, nil
|
return &taskResult, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user