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
e705cff4
authored
Oct 31, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enhance Ali video request handling and validation
parent
a98e207e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
8 deletions
+46
-8
relay/channel/task/ali/adaptor.go
+45
-8
relay/common/relay_utils.go
+1
-0
No files found.
relay/channel/task/ali/adaptor.go
View file @
e705cff4
...
@@ -108,6 +108,7 @@ type TaskAdaptor struct {
...
@@ -108,6 +108,7 @@ type TaskAdaptor struct {
ChannelType
int
ChannelType
int
apiKey
string
apiKey
string
baseURL
string
baseURL
string
aliReq
*
AliVideoRequest
}
}
func
(
a
*
TaskAdaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
func
(
a
*
TaskAdaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
...
@@ -118,6 +119,11 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
...
@@ -118,6 +119,11 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
// 阿里通义万相支持 JSON 格式,不使用 multipart
// 阿里通义万相支持 JSON 格式,不使用 multipart
var
taskReq
relaycommon
.
TaskSubmitReq
if
err
:=
common
.
UnmarshalBodyReusable
(
c
,
&
taskReq
);
err
!=
nil
{
return
service
.
TaskErrorWrapper
(
err
,
"unmarshal_task_request_failed"
,
http
.
StatusBadRequest
)
}
a
.
aliReq
=
a
.
convertToAliRequest
(
info
,
taskReq
)
return
relaycommon
.
ValidateMultipartDirect
(
c
,
info
)
return
relaycommon
.
ValidateMultipartDirect
(
c
,
info
)
}
}
...
@@ -134,13 +140,7 @@ func (a *TaskAdaptor) BuildRequestHeader(c *gin.Context, req *http.Request, info
...
@@ -134,13 +140,7 @@ func (a *TaskAdaptor) BuildRequestHeader(c *gin.Context, req *http.Request, info
}
}
func
(
a
*
TaskAdaptor
)
BuildRequestBody
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
io
.
Reader
,
error
)
{
func
(
a
*
TaskAdaptor
)
BuildRequestBody
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
io
.
Reader
,
error
)
{
var
taskReq
relaycommon
.
TaskSubmitReq
bodyBytes
,
err
:=
common
.
Marshal
(
a
.
aliReq
)
if
err
:=
common
.
UnmarshalBodyReusable
(
c
,
&
taskReq
);
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"unmarshal_task_request_failed"
)
}
aliReq
:=
a
.
convertToAliRequest
(
taskReq
)
bodyBytes
,
err
:=
common
.
Marshal
(
aliReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"marshal_ali_request_failed"
)
return
nil
,
errors
.
Wrap
(
err
,
"marshal_ali_request_failed"
)
}
}
...
@@ -148,7 +148,31 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
...
@@ -148,7 +148,31 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
return
bytes
.
NewReader
(
bodyBytes
),
nil
return
bytes
.
NewReader
(
bodyBytes
),
nil
}
}
func
(
a
*
TaskAdaptor
)
convertToAliRequest
(
req
relaycommon
.
TaskSubmitReq
)
*
AliVideoRequest
{
func
(
a
*
TaskAdaptor
)
convertToAliRequest
(
info
*
relaycommon
.
RelayInfo
,
req
relaycommon
.
TaskSubmitReq
)
*
AliVideoRequest
{
otherRatios
:=
map
[
string
]
map
[
string
]
float64
{
"wan2.5-i2v-preview"
:
{
"480P"
:
1
,
"720P"
:
2
,
"1080P"
:
1
/
0.3
,
},
"wan2.2-i2v-plus"
:
{
"480P"
:
1
,
"1080P"
:
0.7
/
0.14
,
},
"wan2.2-kf2v-flash"
:
{
"480P"
:
1
,
"720P"
:
2
,
"1080P"
:
4.8
,
},
"wan2.2-i2v-flash"
:
{
"480P"
:
1
,
"720P"
:
2
,
},
"wan2.2-s2v"
:
{
"480P"
:
1
,
"720P"
:
0.9
/
0.5
,
},
}
aliReq
:=
&
AliVideoRequest
{
aliReq
:=
&
AliVideoRequest
{
Model
:
req
.
Model
,
Model
:
req
.
Model
,
Input
:
AliVideoInput
{
Input
:
AliVideoInput
{
...
@@ -196,6 +220,19 @@ func (a *TaskAdaptor) convertToAliRequest(req relaycommon.TaskSubmitReq) *AliVid
...
@@ -196,6 +220,19 @@ func (a *TaskAdaptor) convertToAliRequest(req relaycommon.TaskSubmitReq) *AliVid
}
}
}
}
info
.
PriceData
.
OtherRatios
=
map
[
string
]
float64
{
"seconds"
:
float64
(
aliReq
.
Parameters
.
Duration
),
//"size": 1,
}
if
otherRatio
,
ok
:=
otherRatios
[
req
.
Model
];
ok
{
if
ratio
,
ok
:=
otherRatio
[
aliReq
.
Parameters
.
Resolution
];
ok
{
info
.
PriceData
.
OtherRatios
[
fmt
.
Sprintf
(
"resolution-%s"
,
aliReq
.
Parameters
.
Resolution
)]
=
ratio
}
}
// println(fmt.Sprintf("other ratios: %v", info.PriceData.OtherRatios))
return
aliReq
return
aliReq
}
}
...
...
relay/common/relay_utils.go
View file @
e705cff4
...
@@ -121,6 +121,7 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
...
@@ -121,6 +121,7 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError {
prompt
=
req
.
Prompt
prompt
=
req
.
Prompt
model
=
req
.
Model
model
=
req
.
Model
size
=
req
.
Size
seconds
,
_
=
strconv
.
Atoi
(
req
.
Seconds
)
seconds
,
_
=
strconv
.
Atoi
(
req
.
Seconds
)
if
seconds
==
0
{
if
seconds
==
0
{
seconds
=
req
.
Duration
seconds
=
req
.
Duration
...
...
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