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
88b73224
authored
Jan 28, 2026
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: kling cost quota support use FinalUnitDeduction as totalToken
parent
44f8b3e2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
relay/channel/task/kling/adaptor.go
+26
-4
No files found.
relay/channel/task/kling/adaptor.go
View file @
88b73224
...
...
@@ -5,7 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"math"
"net/http"
"strconv"
"strings"
"time"
...
...
@@ -80,15 +82,28 @@ type responsePayload struct {
TaskId
string
`json:"task_id"`
TaskStatus
string
`json:"task_status"`
TaskStatusMsg
string
`json:"task_status_msg"`
TaskInfo
struct
{
ExternalTaskId
string
`json:"external_task_id"`
}
`json:"task_info"`
WatermarkInfo
struct
{
Enabled
bool
`json:"enabled"`
}
`json:"watermark_info"`
TaskResult
struct
{
Videos
[]
struct
{
Id
string
`json:"id"`
Url
string
`json:"url"`
WatermarkUrl
string
`json:"watermark_url"`
Duration
string
`json:"duration"`
}
`json:"videos"`
Images
[]
struct
{
Index
int
`json:"index"`
Url
string
`json:"url"`
WatermarkUrl
string
`json:"watermark_url"`
}
`json:"images"`
}
`json:"task_result"`
CreatedAt
int64
`json:"created_at"`
UpdatedAt
int64
`json:"updated_at"`
FinalUnitDeduction
string
`json:"final_unit_deduction"`
}
`json:"data"`
}
...
...
@@ -356,15 +371,22 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
taskInfo
.
Status
=
model
.
TaskStatusInProgress
case
"succeed"
:
taskInfo
.
Status
=
model
.
TaskStatusSuccess
if
videos
:=
resPayload
.
Data
.
TaskResult
.
Videos
;
len
(
videos
)
>
0
{
video
:=
videos
[
0
]
taskInfo
.
Url
=
video
.
Url
}
if
tokens
,
err
:=
strconv
.
ParseFloat
(
resPayload
.
Data
.
FinalUnitDeduction
,
64
);
err
==
nil
{
rounded
:=
int
(
math
.
Ceil
(
tokens
))
if
rounded
>
0
{
taskInfo
.
CompletionTokens
=
rounded
taskInfo
.
TotalTokens
=
rounded
}
}
case
"failed"
:
taskInfo
.
Status
=
model
.
TaskStatusFailure
default
:
return
nil
,
fmt
.
Errorf
(
"unknown task status: %s"
,
status
)
}
if
videos
:=
resPayload
.
Data
.
TaskResult
.
Videos
;
len
(
videos
)
>
0
{
video
:=
videos
[
0
]
taskInfo
.
Url
=
video
.
Url
}
return
taskInfo
,
nil
}
...
...
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