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
69f497e3
authored
Oct 10, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: openAI video use OpenAIVideoConverter
parent
a92afd7a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
1 deletions
+49
-1
relay/channel/adapter.go
+5
-0
relay/channel/task/sora/adaptor.go
+9
-0
relay/common/relay_info.go
+19
-0
relay/relay_task.go
+16
-1
No files found.
relay/channel/adapter.go
View file @
69f497e3
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"io"
"io"
"net/http"
"net/http"
"one-api/dto"
"one-api/dto"
"one-api/model"
relaycommon
"one-api/relay/common"
relaycommon
"one-api/relay/common"
"one-api/types"
"one-api/types"
...
@@ -49,3 +50,7 @@ type TaskAdaptor interface {
...
@@ -49,3 +50,7 @@ type TaskAdaptor interface {
ParseTaskResult
(
respBody
[]
byte
)
(
*
relaycommon
.
TaskInfo
,
error
)
ParseTaskResult
(
respBody
[]
byte
)
(
*
relaycommon
.
TaskInfo
,
error
)
}
}
type
OpenAIVideoConverter
interface
{
ConvertToOpenAIVideo
(
originTask
*
model
.
Task
)
(
*
relaycommon
.
OpenAIVideo
,
error
)
}
relay/channel/task/sora/adaptor.go
View file @
69f497e3
...
@@ -184,3 +184,12 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
...
@@ -184,3 +184,12 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
return
&
taskResult
,
nil
return
&
taskResult
,
nil
}
}
func
(
a
*
TaskAdaptor
)
ConvertToOpenAIVideo
(
task
*
model
.
Task
)
(
*
relaycommon
.
OpenAIVideo
,
error
)
{
openAIVideo
:=
&
relaycommon
.
OpenAIVideo
{}
err
:=
json
.
Unmarshal
(
task
.
Data
,
openAIVideo
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"unmarshal to OpenAIVideo failed"
)
}
return
openAIVideo
,
nil
}
relay/common/relay_info.go
View file @
69f497e3
...
@@ -550,3 +550,22 @@ func RemoveDisabledFields(jsonData []byte, channelOtherSettings dto.ChannelOther
...
@@ -550,3 +550,22 @@ func RemoveDisabledFields(jsonData []byte, channelOtherSettings dto.ChannelOther
}
}
return
jsonDataAfter
,
nil
return
jsonDataAfter
,
nil
}
}
type
OpenAIVideo
struct
{
ID
string
`json:"id"`
TaskID
string
`json:"task_id,omitempty"`
//兼容旧接口
Object
string
`json:"object"`
Model
string
`json:"model"`
Status
string
`json:"status"`
Progress
int
`json:"progress"`
CreatedAt
int64
`json:"created_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"`
}
relay/relay_task.go
View file @
69f497e3
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"one-api/constant"
"one-api/constant"
"one-api/dto"
"one-api/dto"
"one-api/model"
"one-api/model"
"one-api/relay/channel"
relaycommon
"one-api/relay/common"
relaycommon
"one-api/relay/common"
relayconstant
"one-api/relay/constant"
relayconstant
"one-api/relay/constant"
"one-api/service"
"one-api/service"
...
@@ -367,7 +368,21 @@ func videoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *d
...
@@ -367,7 +368,21 @@ func videoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *d
}
}
if
strings
.
HasPrefix
(
c
.
Request
.
RequestURI
,
"/v1/videos/"
)
{
if
strings
.
HasPrefix
(
c
.
Request
.
RequestURI
,
"/v1/videos/"
)
{
respBody
=
originTask
.
Data
adaptor
:=
GetTaskAdaptor
(
originTask
.
Platform
)
if
adaptor
==
nil
{
taskResp
=
service
.
TaskErrorWrapperLocal
(
fmt
.
Errorf
(
"invalid channel id: %d"
,
originTask
.
ChannelId
),
"invalid_channel_id"
,
http
.
StatusBadRequest
)
return
}
if
converter
,
ok
:=
adaptor
.
(
channel
.
OpenAIVideoConverter
);
ok
{
openAIVideo
,
err
:=
converter
.
ConvertToOpenAIVideo
(
originTask
)
if
err
!=
nil
{
taskResp
=
service
.
TaskErrorWrapper
(
err
,
"convert_to_openai_video_failed"
,
http
.
StatusInternalServerError
)
return
}
respBody
,
_
=
json
.
Marshal
(
openAIVideo
)
return
}
taskResp
=
service
.
TaskErrorWrapperLocal
(
errors
.
New
(
fmt
.
Sprintf
(
"not_implemented:%s"
,
originTask
.
Platform
)),
"not_implemented"
,
http
.
StatusNotImplemented
)
return
return
}
}
respBody
,
err
=
json
.
Marshal
(
dto
.
TaskResponse
[
any
]{
respBody
,
err
=
json
.
Marshal
(
dto
.
TaskResponse
[
any
]{
...
...
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