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
b3c4d972
authored
Jul 22, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: opt video channel and platform
parent
2f55960b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
63 deletions
+42
-63
constant/task.go
+0
-2
controller/relay.go
+1
-1
controller/task.go
+3
-3
middleware/distributor.go
+5
-14
relay/constant/relay_mode.go
+2
-25
relay/relay_adaptor.go
+18
-5
relay/relay_task.go
+4
-1
web/src/components/table/task-logs/TaskLogsColumnDefs.js
+9
-12
No files found.
constant/task.go
View file @
b3c4d972
...
@@ -5,8 +5,6 @@ type TaskPlatform string
...
@@ -5,8 +5,6 @@ type TaskPlatform string
const
(
const
(
TaskPlatformSuno
TaskPlatform
=
"suno"
TaskPlatformSuno
TaskPlatform
=
"suno"
TaskPlatformMidjourney
=
"mj"
TaskPlatformMidjourney
=
"mj"
TaskPlatformKling
TaskPlatform
=
"kling"
TaskPlatformJimeng
TaskPlatform
=
"jimeng"
)
)
const
(
const
(
...
...
controller/relay.go
View file @
b3c4d972
...
@@ -428,7 +428,7 @@ func RelayTask(c *gin.Context) {
...
@@ -428,7 +428,7 @@ func RelayTask(c *gin.Context) {
func
taskRelayHandler
(
c
*
gin
.
Context
,
relayMode
int
)
*
dto
.
TaskError
{
func
taskRelayHandler
(
c
*
gin
.
Context
,
relayMode
int
)
*
dto
.
TaskError
{
var
err
*
dto
.
TaskError
var
err
*
dto
.
TaskError
switch
relayMode
{
switch
relayMode
{
case
relayconstant
.
RelayModeSunoFetch
,
relayconstant
.
RelayModeSunoFetchByID
,
relayconstant
.
RelayMode
Kling
FetchByID
:
case
relayconstant
.
RelayModeSunoFetch
,
relayconstant
.
RelayModeSunoFetchByID
,
relayconstant
.
RelayMode
Video
FetchByID
:
err
=
relay
.
RelayTaskFetch
(
c
,
relayMode
)
err
=
relay
.
RelayTaskFetch
(
c
,
relayMode
)
default
:
default
:
err
=
relay
.
RelayTaskSubmit
(
c
,
relayMode
)
err
=
relay
.
RelayTaskSubmit
(
c
,
relayMode
)
...
...
controller/task.go
View file @
b3c4d972
...
@@ -75,10 +75,10 @@ func UpdateTaskByPlatform(platform constant.TaskPlatform, taskChannelM map[int][
...
@@ -75,10 +75,10 @@ func UpdateTaskByPlatform(platform constant.TaskPlatform, taskChannelM map[int][
//_ = UpdateMidjourneyTaskAll(context.Background(), tasks)
//_ = UpdateMidjourneyTaskAll(context.Background(), tasks)
case
constant
.
TaskPlatformSuno
:
case
constant
.
TaskPlatformSuno
:
_
=
UpdateSunoTaskAll
(
context
.
Background
(),
taskChannelM
,
taskM
)
_
=
UpdateSunoTaskAll
(
context
.
Background
(),
taskChannelM
,
taskM
)
case
constant
.
TaskPlatformKling
,
constant
.
TaskPlatformJimeng
:
_
=
UpdateVideoTaskAll
(
context
.
Background
(),
platform
,
taskChannelM
,
taskM
)
default
:
default
:
common
.
SysLog
(
"未知平台"
)
if
err
:=
UpdateVideoTaskAll
(
context
.
Background
(),
platform
,
taskChannelM
,
taskM
);
err
!=
nil
{
common
.
SysLog
(
fmt
.
Sprintf
(
"UpdateVideoTaskAll fail: %s"
,
err
))
}
}
}
}
}
...
...
middleware/distributor.go
View file @
b3c4d972
...
@@ -174,22 +174,13 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
...
@@ -174,22 +174,13 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
c
.
Set
(
"relay_mode"
,
relayMode
)
c
.
Set
(
"relay_mode"
,
relayMode
)
}
else
if
strings
.
Contains
(
c
.
Request
.
URL
.
Path
,
"/v1/video/generations"
)
{
}
else
if
strings
.
Contains
(
c
.
Request
.
URL
.
Path
,
"/v1/video/generations"
)
{
err
=
common
.
UnmarshalBodyReusable
(
c
,
&
modelRequest
)
err
=
common
.
UnmarshalBodyReusable
(
c
,
&
modelRequest
)
var
platform
string
relayMode
:=
relayconstant
.
RelayModeUnknown
var
relayMode
int
if
c
.
Request
.
Method
==
http
.
MethodPost
{
if
strings
.
HasPrefix
(
modelRequest
.
Model
,
"jimeng"
)
{
relayMode
=
relayconstant
.
RelayModeVideoSubmit
platform
=
string
(
constant
.
TaskPlatformJimeng
)
}
else
if
c
.
Request
.
Method
==
http
.
MethodGet
{
relayMode
=
relayconstant
.
Path2RelayJimeng
(
c
.
Request
.
Method
,
c
.
Request
.
URL
.
Path
)
relayMode
=
relayconstant
.
RelayModeVideoFetchByID
if
relayMode
==
relayconstant
.
RelayModeJimengFetchByID
{
shouldSelectChannel
=
false
shouldSelectChannel
=
false
}
}
}
else
{
platform
=
string
(
constant
.
TaskPlatformKling
)
relayMode
=
relayconstant
.
Path2RelayKling
(
c
.
Request
.
Method
,
c
.
Request
.
URL
.
Path
)
if
relayMode
==
relayconstant
.
RelayModeKlingFetchByID
{
shouldSelectChannel
=
false
}
}
c
.
Set
(
"platform"
,
platform
)
c
.
Set
(
"relay_mode"
,
relayMode
)
c
.
Set
(
"relay_mode"
,
relayMode
)
}
else
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/v1beta/models/"
)
||
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/v1/models/"
)
{
}
else
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/v1beta/models/"
)
||
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/v1/models/"
)
{
// Gemini API 路径处理: /v1beta/models/gemini-2.0-flash:generateContent
// Gemini API 路径处理: /v1beta/models/gemini-2.0-flash:generateContent
...
...
relay/constant/relay_mode.go
View file @
b3c4d972
...
@@ -40,11 +40,8 @@ const (
...
@@ -40,11 +40,8 @@ const (
RelayModeSunoFetchByID
RelayModeSunoFetchByID
RelayModeSunoSubmit
RelayModeSunoSubmit
RelayModeKlingFetchByID
RelayModeVideoFetchByID
RelayModeKlingSubmit
RelayModeVideoSubmit
RelayModeJimengFetchByID
RelayModeJimengSubmit
RelayModeRerank
RelayModeRerank
...
@@ -145,23 +142,3 @@ func Path2RelaySuno(method, path string) int {
...
@@ -145,23 +142,3 @@ func Path2RelaySuno(method, path string) int {
}
}
return
relayMode
return
relayMode
}
}
func
Path2RelayKling
(
method
,
path
string
)
int
{
relayMode
:=
RelayModeUnknown
if
method
==
http
.
MethodPost
&&
strings
.
HasSuffix
(
path
,
"/video/generations"
)
{
relayMode
=
RelayModeKlingSubmit
}
else
if
method
==
http
.
MethodGet
&&
(
strings
.
Contains
(
path
,
"/video/generations"
))
{
relayMode
=
RelayModeKlingFetchByID
}
return
relayMode
}
func
Path2RelayJimeng
(
method
,
path
string
)
int
{
relayMode
:=
RelayModeUnknown
if
method
==
http
.
MethodPost
&&
strings
.
HasSuffix
(
path
,
"/video/generations"
)
{
relayMode
=
RelayModeJimengSubmit
}
else
if
method
==
http
.
MethodGet
&&
strings
.
Contains
(
path
,
"/video/generations/"
)
{
relayMode
=
RelayModeJimengFetchByID
}
return
relayMode
}
relay/relay_adaptor.go
View file @
b3c4d972
package
relay
package
relay
import
(
import
(
"github.com/gin-gonic/gin"
"one-api/constant"
"one-api/constant"
commonconstant
"one-api/constant"
"one-api/relay/channel"
"one-api/relay/channel"
"one-api/relay/channel/ali"
"one-api/relay/channel/ali"
"one-api/relay/channel/aws"
"one-api/relay/channel/aws"
...
@@ -34,6 +34,7 @@ import (
...
@@ -34,6 +34,7 @@ import (
"one-api/relay/channel/xunfei"
"one-api/relay/channel/xunfei"
"one-api/relay/channel/zhipu"
"one-api/relay/channel/zhipu"
"one-api/relay/channel/zhipu_4v"
"one-api/relay/channel/zhipu_4v"
"strconv"
)
)
func
GetAdaptor
(
apiType
int
)
channel
.
Adaptor
{
func
GetAdaptor
(
apiType
int
)
channel
.
Adaptor
{
...
@@ -100,16 +101,28 @@ func GetAdaptor(apiType int) channel.Adaptor {
...
@@ -100,16 +101,28 @@ func GetAdaptor(apiType int) channel.Adaptor {
return
nil
return
nil
}
}
func
GetTaskAdaptor
(
platform
commonconstant
.
TaskPlatform
)
channel
.
TaskAdaptor
{
func
GetTaskPlatform
(
c
*
gin
.
Context
)
constant
.
TaskPlatform
{
channelType
:=
c
.
GetInt
(
"channel_type"
)
if
channelType
>
0
{
return
constant
.
TaskPlatform
(
strconv
.
Itoa
(
channelType
))
}
return
constant
.
TaskPlatform
(
c
.
GetString
(
"platform"
))
}
func
GetTaskAdaptor
(
platform
constant
.
TaskPlatform
)
channel
.
TaskAdaptor
{
switch
platform
{
switch
platform
{
//case constant.APITypeAIProxyLibrary:
//case constant.APITypeAIProxyLibrary:
// return &aiproxy.Adaptor{}
// return &aiproxy.Adaptor{}
case
co
mmonco
nstant
.
TaskPlatformSuno
:
case
constant
.
TaskPlatformSuno
:
return
&
suno
.
TaskAdaptor
{}
return
&
suno
.
TaskAdaptor
{}
case
commonconstant
.
TaskPlatformKling
:
}
if
channelType
,
err
:=
strconv
.
ParseInt
(
string
(
platform
),
10
,
64
);
err
==
nil
{
switch
channelType
{
case
constant
.
ChannelTypeKling
:
return
&
kling
.
TaskAdaptor
{}
return
&
kling
.
TaskAdaptor
{}
case
commonconstant
.
TaskPlatform
Jimeng
:
case
constant
.
ChannelType
Jimeng
:
return
&
taskjimeng
.
TaskAdaptor
{}
return
&
taskjimeng
.
TaskAdaptor
{}
}
}
}
return
nil
return
nil
}
}
relay/relay_task.go
View file @
b3c4d972
...
@@ -24,6 +24,9 @@ Task 任务通过平台、Action 区分任务
...
@@ -24,6 +24,9 @@ Task 任务通过平台、Action 区分任务
*/
*/
func
RelayTaskSubmit
(
c
*
gin
.
Context
,
relayMode
int
)
(
taskErr
*
dto
.
TaskError
)
{
func
RelayTaskSubmit
(
c
*
gin
.
Context
,
relayMode
int
)
(
taskErr
*
dto
.
TaskError
)
{
platform
:=
constant
.
TaskPlatform
(
c
.
GetString
(
"platform"
))
platform
:=
constant
.
TaskPlatform
(
c
.
GetString
(
"platform"
))
if
platform
==
""
{
platform
=
GetTaskPlatform
(
c
)
}
relayInfo
:=
relaycommon
.
GenTaskRelayInfo
(
c
)
relayInfo
:=
relaycommon
.
GenTaskRelayInfo
(
c
)
adaptor
:=
GetTaskAdaptor
(
platform
)
adaptor
:=
GetTaskAdaptor
(
platform
)
...
@@ -178,7 +181,7 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
...
@@ -178,7 +181,7 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
var
fetchRespBuilders
=
map
[
int
]
func
(
c
*
gin
.
Context
)
(
respBody
[]
byte
,
taskResp
*
dto
.
TaskError
){
var
fetchRespBuilders
=
map
[
int
]
func
(
c
*
gin
.
Context
)
(
respBody
[]
byte
,
taskResp
*
dto
.
TaskError
){
relayconstant
.
RelayModeSunoFetchByID
:
sunoFetchByIDRespBodyBuilder
,
relayconstant
.
RelayModeSunoFetchByID
:
sunoFetchByIDRespBodyBuilder
,
relayconstant
.
RelayModeSunoFetch
:
sunoFetchRespBodyBuilder
,
relayconstant
.
RelayModeSunoFetch
:
sunoFetchRespBodyBuilder
,
relayconstant
.
RelayMode
Kling
FetchByID
:
videoFetchByIDRespBodyBuilder
,
relayconstant
.
RelayMode
Video
FetchByID
:
videoFetchByIDRespBodyBuilder
,
}
}
func
RelayTaskFetch
(
c
*
gin
.
Context
,
relayMode
int
)
(
taskResp
*
dto
.
TaskError
)
{
func
RelayTaskFetch
(
c
*
gin
.
Context
,
relayMode
int
)
(
taskResp
*
dto
.
TaskError
)
{
...
...
web/src/components/table/task-logs/TaskLogsColumnDefs.js
View file @
b3c4d972
...
@@ -39,6 +39,7 @@ import {
...
@@ -39,6 +39,7 @@ import {
Sparkles
Sparkles
}
from
'lucide-react'
;
}
from
'lucide-react'
;
import
{
TASK_ACTION_GENERATE
,
TASK_ACTION_TEXT_GENERATE
}
from
'../../../constants/common.constant'
;
import
{
TASK_ACTION_GENERATE
,
TASK_ACTION_TEXT_GENERATE
}
from
'../../../constants/common.constant'
;
import
{
CHANNEL_OPTIONS
}
from
'../../../constants/channel.constants'
;
const
colors
=
[
const
colors
=
[
'amber'
,
'amber'
,
...
@@ -121,6 +122,14 @@ const renderType = (type, t) => {
...
@@ -121,6 +122,14 @@ const renderType = (type, t) => {
};
};
const
renderPlatform
=
(
platform
,
t
)
=>
{
const
renderPlatform
=
(
platform
,
t
)
=>
{
let
option
=
CHANNEL_OPTIONS
.
find
(
opt
=>
String
(
opt
.
value
)
===
String
(
platform
));
if
(
option
)
{
return
(
<
Tag
color
=
{
option
.
color
}
shape
=
'circle'
prefixIcon
=
{
<
Video
size
=
{
14
}
/>}
>
{
option
.
label
}
<
/Tag
>
);
}
switch
(
platform
)
{
switch
(
platform
)
{
case
'suno'
:
case
'suno'
:
return
(
return
(
...
@@ -128,18 +137,6 @@ const renderPlatform = (platform, t) => {
...
@@ -128,18 +137,6 @@ const renderPlatform = (platform, t) => {
Suno
Suno
<
/Tag
>
<
/Tag
>
);
);
case
'kling'
:
return
(
<
Tag
color
=
'orange'
shape
=
'circle'
prefixIcon
=
{
<
Video
size
=
{
14
}
/>}
>
Kling
<
/Tag
>
);
case
'jimeng'
:
return
(
<
Tag
color
=
'purple'
shape
=
'circle'
prefixIcon
=
{
<
Video
size
=
{
14
}
/>}
>
Jimeng
<
/Tag
>
);
default
:
default
:
return
(
return
(
<
Tag
color
=
'white'
shape
=
'circle'
prefixIcon
=
{
<
HelpCircle
size
=
{
14
}
/>}
>
<
Tag
color
=
'white'
shape
=
'circle'
prefixIcon
=
{
<
HelpCircle
size
=
{
14
}
/>}
>
...
...
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