Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b1db1264
authored
Oct 09, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add sora video retrieve task
parent
1d1759aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
36 deletions
+33
-36
controller/task_video.go
+5
-0
relay/channel/task/sora/adaptor.go
+28
-36
No files found.
controller/task_video.go
View file @
b1db1264
...
@@ -47,6 +47,11 @@ func updateVideoTaskAll(ctx context.Context, platform constant.TaskPlatform, cha
...
@@ -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
()))
...
...
relay/channel/task/sora/adaptor.go
View file @
b1db1264
...
@@ -36,23 +36,21 @@ type responsePayload struct {
...
@@ -36,23 +36,21 @@ type responsePayload struct {
}
}
type
responseTask
struct
{
type
responseTask
struct
{
ID
string
`json:"id"`
ID
string
`json:"id"`
Model
string
`json:"model"`
Object
string
`json:"object"`
Status
string
`json:"status"`
Model
string
`json:"model"`
Content
struct
{
Status
string
`json:"status"`
VideoURL
string
`json:"video_url"`
Progress
int
`json:"progress"`
}
`json:"content"`
CreatedAt
int64
`json:"created_at"`
Seed
int
`json:"seed"`
CompletedAt
int64
`json:"completed_at,omitempty"`
Resolution
string
`json:"resolution"`
ExpiresAt
int64
`json:"expires_at,omitempty"`
Duration
int
`json:"duration"`
Seconds
string
`json:"seconds,omitempty"`
AspectRatio
string
`json:"aspect_ratio"`
Size
string
`json:"size,omitempty"`
Usage
struct
{
RemixedFromVideoID
string
`json:"remixed_from_video_id,omitempty"`
PromptTokens
int
`json:"prompt_tokens"`
Error
*
struct
{
CompletionTokens
int
`json:"completion_tokens"`
Message
string
`json:"message"`
TotalTokens
int
`json:"total_tokens"`
Code
string
`json:"code"`
}
`json:"usage"`
}
`json:"error,omitempty"`
CreatedAt
int64
`json:"created_at"`
UpdatedAt
int64
`json:"updated_at"`
}
}
// ============================
// ============================
...
@@ -131,15 +129,13 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
...
@@ -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
...
@@ -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
=
"task failed"
taskResult
.
Reason
=
resTask
.
Error
.
Message
}
else
{
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment