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
111dc18d
authored
Jun 27, 2025
by
skynono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: video action to constant
parent
defc18de
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
9 deletions
+21
-9
constant/task.go
+3
-0
middleware/kling_adapter.go
+4
-2
relay/channel/task/jimeng/adaptor.go
+2
-1
relay/channel/task/kling/adaptor.go
+4
-3
web/src/components/table/TaskLogsTable.js
+4
-3
web/src/constants/common.constant.js
+4
-0
No files found.
constant/task.go
View file @
111dc18d
...
@@ -12,6 +12,9 @@ const (
...
@@ -12,6 +12,9 @@ const (
const
(
const
(
SunoActionMusic
=
"MUSIC"
SunoActionMusic
=
"MUSIC"
SunoActionLyrics
=
"LYRICS"
SunoActionLyrics
=
"LYRICS"
TaskActionGenerate
=
"generate"
TaskActionTextGenerate
=
"textGenerate"
)
)
var
SunoModel2Action
=
map
[
string
]
string
{
var
SunoModel2Action
=
map
[
string
]
string
{
...
...
middleware/kling_adapter.go
View file @
111dc18d
...
@@ -3,9 +3,11 @@ package middleware
...
@@ -3,9 +3,11 @@ package middleware
import
(
import
(
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"github.com/gin-gonic/gin"
"io"
"io"
"one-api/common"
"one-api/common"
"one-api/constant"
"github.com/gin-gonic/gin"
)
)
func
KlingRequestConvert
()
func
(
c
*
gin
.
Context
)
{
func
KlingRequestConvert
()
func
(
c
*
gin
.
Context
)
{
...
@@ -35,7 +37,7 @@ func KlingRequestConvert() func(c *gin.Context) {
...
@@ -35,7 +37,7 @@ func KlingRequestConvert() func(c *gin.Context) {
c
.
Request
.
Body
=
io
.
NopCloser
(
bytes
.
NewBuffer
(
jsonData
))
c
.
Request
.
Body
=
io
.
NopCloser
(
bytes
.
NewBuffer
(
jsonData
))
c
.
Request
.
URL
.
Path
=
"/v1/video/generations"
c
.
Request
.
URL
.
Path
=
"/v1/video/generations"
if
image
:=
originalReq
[
"image"
];
image
==
""
{
if
image
:=
originalReq
[
"image"
];
image
==
""
{
c
.
Set
(
"action"
,
"textGenerate"
)
c
.
Set
(
"action"
,
constant
.
TaskActionTextGenerate
)
}
}
// We have to reset the request body for the next handlers
// We have to reset the request body for the next handlers
...
...
relay/channel/task/jimeng/adaptor.go
View file @
111dc18d
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
"one-api/common"
"one-api/common"
"one-api/constant"
"one-api/dto"
"one-api/dto"
"one-api/relay/channel"
"one-api/relay/channel"
relaycommon
"one-api/relay/common"
relaycommon
"one-api/relay/common"
...
@@ -88,7 +89,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.TaskRelayInfo) {
...
@@ -88,7 +89,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.TaskRelayInfo) {
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
TaskRelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
TaskRelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
// Accept only POST /v1/video/generations as "generate" action.
// Accept only POST /v1/video/generations as "generate" action.
action
:=
"generate"
action
:=
constant
.
TaskActionGenerate
info
.
Action
=
action
info
.
Action
=
action
req
:=
relaycommon
.
TaskSubmitReq
{}
req
:=
relaycommon
.
TaskSubmitReq
{}
...
...
relay/channel/task/kling/adaptor.go
View file @
111dc18d
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
"one-api/common"
"one-api/common"
"one-api/constant"
"one-api/dto"
"one-api/dto"
"one-api/relay/channel"
"one-api/relay/channel"
relaycommon
"one-api/relay/common"
relaycommon
"one-api/relay/common"
...
@@ -92,7 +93,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.TaskRelayInfo) {
...
@@ -92,7 +93,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.TaskRelayInfo) {
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
TaskRelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
TaskRelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
// Accept only POST /v1/video/generations as "generate" action.
// Accept only POST /v1/video/generations as "generate" action.
action
:=
"generate"
action
:=
constant
.
TaskActionGenerate
info
.
Action
=
action
info
.
Action
=
action
var
req
SubmitReq
var
req
SubmitReq
...
@@ -112,7 +113,7 @@ func (a *TaskAdaptor) ValidateRequestAndSetAction(c *gin.Context, info *relaycom
...
@@ -112,7 +113,7 @@ func (a *TaskAdaptor) ValidateRequestAndSetAction(c *gin.Context, info *relaycom
// BuildRequestURL constructs the upstream URL.
// BuildRequestURL constructs the upstream URL.
func
(
a
*
TaskAdaptor
)
BuildRequestURL
(
info
*
relaycommon
.
TaskRelayInfo
)
(
string
,
error
)
{
func
(
a
*
TaskAdaptor
)
BuildRequestURL
(
info
*
relaycommon
.
TaskRelayInfo
)
(
string
,
error
)
{
path
:=
lo
.
Ternary
(
info
.
Action
==
"generate"
,
"/v1/videos/image2video"
,
"/v1/videos/text2video"
)
path
:=
lo
.
Ternary
(
info
.
Action
==
constant
.
TaskActionGenerate
,
"/v1/videos/image2video"
,
"/v1/videos/text2video"
)
return
fmt
.
Sprintf
(
"%s%s"
,
a
.
baseURL
,
path
),
nil
return
fmt
.
Sprintf
(
"%s%s"
,
a
.
baseURL
,
path
),
nil
}
}
...
@@ -198,7 +199,7 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
...
@@ -198,7 +199,7 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid action"
)
return
nil
,
fmt
.
Errorf
(
"invalid action"
)
}
}
path
:=
lo
.
Ternary
(
action
==
"generate"
,
"/v1/videos/image2video"
,
"/v1/videos/text2video"
)
path
:=
lo
.
Ternary
(
action
==
constant
.
TaskActionGenerate
,
"/v1/videos/image2video"
,
"/v1/videos/text2video"
)
url
:=
fmt
.
Sprintf
(
"%s%s/%s"
,
baseUrl
,
path
,
taskID
)
url
:=
fmt
.
Sprintf
(
"%s%s/%s"
,
baseUrl
,
path
,
taskID
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
url
,
nil
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
url
,
nil
)
...
...
web/src/components/table/TaskLogsTable.js
View file @
111dc18d
...
@@ -51,6 +51,7 @@ import {
...
@@ -51,6 +51,7 @@ import {
IconDescend
IconDescend
}
from
'@douyinfe/semi-icons'
;
}
from
'@douyinfe/semi-icons'
;
import
{
useTableCompactMode
}
from
'../../hooks/useTableCompactMode'
;
import
{
useTableCompactMode
}
from
'../../hooks/useTableCompactMode'
;
import
{
TASK_ACTION_GENERATE
,
TASK_ACTION_TEXT_GENERATE
}
from
'../../constants/common.constant'
;
const
{
Text
}
=
Typography
;
const
{
Text
}
=
Typography
;
...
@@ -209,13 +210,13 @@ const LogsTable = () => {
...
@@ -209,13 +210,13 @@ const LogsTable = () => {
{
t
(
'生成歌词'
)}
{
t
(
'生成歌词'
)}
<
/Tag
>
<
/Tag
>
);
);
case
'generate'
:
case
TASK_ACTION_GENERATE
:
return
(
return
(
<
Tag
color
=
'blue'
size
=
'large'
shape
=
'circle'
prefixIcon
=
{
<
Sparkles
size
=
{
14
}
/>}
>
<
Tag
color
=
'blue'
size
=
'large'
shape
=
'circle'
prefixIcon
=
{
<
Sparkles
size
=
{
14
}
/>}
>
{
t
(
'图生视频'
)}
{
t
(
'图生视频'
)}
<
/Tag
>
<
/Tag
>
);
);
case
'textGenerate'
:
case
TASK_ACTION_TEXT_GENERATE
:
return
(
return
(
<
Tag
color
=
'blue'
size
=
'large'
shape
=
'circle'
prefixIcon
=
{
<
Sparkles
size
=
{
14
}
/>}
>
<
Tag
color
=
'blue'
size
=
'large'
shape
=
'circle'
prefixIcon
=
{
<
Sparkles
size
=
{
14
}
/>}
>
{
t
(
'文生视频'
)}
{
t
(
'文生视频'
)}
...
@@ -446,7 +447,7 @@ const LogsTable = () => {
...
@@ -446,7 +447,7 @@ const LogsTable = () => {
fixed
:
'right'
,
fixed
:
'right'
,
render
:
(
text
,
record
,
index
)
=>
{
render
:
(
text
,
record
,
index
)
=>
{
// 仅当为视频生成任务且成功,且 fail_reason 是 URL 时显示可点击链接
// 仅当为视频生成任务且成功,且 fail_reason 是 URL 时显示可点击链接
const
isVideoTask
=
record
.
action
===
'generate'
||
record
.
action
===
'textGenerate'
;
const
isVideoTask
=
record
.
action
===
TASK_ACTION_GENERATE
||
record
.
action
===
TASK_ACTION_TEXT_GENERATE
;
const
isSuccess
=
record
.
status
===
'SUCCESS'
;
const
isSuccess
=
record
.
status
===
'SUCCESS'
;
const
isUrl
=
typeof
text
===
'string'
&&
/^https
?
:
\/\/
/
.
test
(
text
);
const
isUrl
=
typeof
text
===
'string'
&&
/^https
?
:
\/\/
/
.
test
(
text
);
if
(
isSuccess
&&
isVideoTask
&&
isUrl
)
{
if
(
isSuccess
&&
isVideoTask
&&
isUrl
)
{
...
...
web/src/constants/common.constant.js
View file @
111dc18d
...
@@ -18,3 +18,6 @@ export const API_ENDPOINTS = [
...
@@ -18,3 +18,6 @@ export const API_ENDPOINTS = [
'/v1/audio/transcriptions'
,
'/v1/audio/transcriptions'
,
'/v1/audio/translations'
'/v1/audio/translations'
];
];
export
const
TASK_ACTION_GENERATE
=
'generate'
;
export
const
TASK_ACTION_TEXT_GENERATE
=
'textGenerate'
;
\ No newline at end of file
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