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
73609f50
authored
Aug 10, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add jimeng video official api
parent
ca85d224
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
1 deletions
+80
-1
middleware/distributor.go
+3
-1
middleware/jimeng_adapter.go
+66
-0
relay/relay_task.go
+3
-0
router/video-router.go
+8
-0
No files found.
middleware/distributor.go
View file @
73609f50
...
...
@@ -174,7 +174,9 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
relayMode
=
relayconstant
.
RelayModeVideoFetchByID
shouldSelectChannel
=
false
}
c
.
Set
(
"relay_mode"
,
relayMode
)
if
_
,
ok
:=
c
.
Get
(
"relay_mode"
);
!
ok
{
c
.
Set
(
"relay_mode"
,
relayMode
)
}
}
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
relayMode
:=
relayconstant
.
RelayModeGemini
...
...
middleware/jimeng_adapter.go
0 → 100644
View file @
73609f50
package
middleware
import
(
"bytes"
"encoding/json"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/common"
"one-api/constant"
relayconstant
"one-api/relay/constant"
)
func
JimengRequestConvert
()
func
(
c
*
gin
.
Context
)
{
return
func
(
c
*
gin
.
Context
)
{
action
:=
c
.
Query
(
"Action"
)
if
action
==
""
{
abortWithOpenAiMessage
(
c
,
http
.
StatusBadRequest
,
"Action query parameter is required"
)
return
}
// Handle Jimeng official API request
var
originalReq
map
[
string
]
interface
{}
if
err
:=
common
.
UnmarshalBodyReusable
(
c
,
&
originalReq
);
err
!=
nil
{
abortWithOpenAiMessage
(
c
,
http
.
StatusBadRequest
,
"Invalid request body"
)
return
}
model
,
_
:=
originalReq
[
"req_key"
]
.
(
string
)
prompt
,
_
:=
originalReq
[
"prompt"
]
.
(
string
)
unifiedReq
:=
map
[
string
]
interface
{}{
"model"
:
model
,
"prompt"
:
prompt
,
"metadata"
:
originalReq
,
}
jsonData
,
err
:=
json
.
Marshal
(
unifiedReq
)
if
err
!=
nil
{
abortWithOpenAiMessage
(
c
,
http
.
StatusInternalServerError
,
"Failed to marshal request body"
)
return
}
// Update request body
c
.
Request
.
Body
=
io
.
NopCloser
(
bytes
.
NewBuffer
(
jsonData
))
c
.
Set
(
common
.
KeyRequestBody
,
jsonData
)
if
image
,
ok
:=
originalReq
[
"image"
];
!
ok
||
image
==
""
{
c
.
Set
(
"action"
,
constant
.
TaskActionTextGenerate
)
}
c
.
Request
.
URL
.
Path
=
"/v1/video/generations"
if
action
==
"CVSync2AsyncGetResult"
{
taskId
,
ok
:=
originalReq
[
"task_id"
]
.
(
string
)
if
!
ok
||
taskId
==
""
{
abortWithOpenAiMessage
(
c
,
http
.
StatusBadRequest
,
"task_id is required for CVSync2AsyncGetResult"
)
return
}
c
.
Request
.
URL
.
Path
=
"/v1/video/generations/"
+
taskId
c
.
Request
.
Method
=
http
.
MethodGet
c
.
Set
(
"task_id"
,
taskId
)
c
.
Set
(
"relay_mode"
,
relayconstant
.
RelayModeVideoFetchByID
)
}
c
.
Next
()
}
}
relay/relay_task.go
View file @
73609f50
...
...
@@ -258,6 +258,9 @@ func sunoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *dt
func
videoFetchByIDRespBodyBuilder
(
c
*
gin
.
Context
)
(
respBody
[]
byte
,
taskResp
*
dto
.
TaskError
)
{
taskId
:=
c
.
Param
(
"task_id"
)
if
taskId
==
""
{
taskId
=
c
.
GetString
(
"task_id"
)
}
userId
:=
c
.
GetInt
(
"id"
)
originTask
,
exist
,
err
:=
model
.
GetByTaskId
(
userId
,
taskId
)
...
...
router/video-router.go
View file @
73609f50
...
...
@@ -23,4 +23,12 @@ func SetVideoRouter(router *gin.Engine) {
klingV1Router
.
GET
(
"/videos/text2video/:task_id"
,
controller
.
RelayTask
)
klingV1Router
.
GET
(
"/videos/image2video/:task_id"
,
controller
.
RelayTask
)
}
// Jimeng official API routes - direct mapping to official API format
jimengOfficialGroup
:=
router
.
Group
(
"jimeng"
)
jimengOfficialGroup
.
Use
(
middleware
.
JimengRequestConvert
(),
middleware
.
TokenAuth
(),
middleware
.
Distribute
())
{
// Maps to: /?Action=CVSync2AsyncSubmitTask&Version=2022-08-31 and /?Action=CVSync2AsyncGetResult&Version=2022-08-31
jimengOfficialGroup
.
POST
(
"/"
,
controller
.
RelayTask
)
}
}
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