mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-29 23:10:35 +00:00
Restructure the task relay system for better separation of concerns: - Extract task billing into service/task_billing.go with unified settlement flow - Move task polling loop from controller to service/task_polling.go (supports Suno + video platforms) - Split RelayTask into fetch/submit paths with dedicated retry logic (taskSubmitWithRetry) - Add TaskDto, TaskResponse generics, and FetchReq to dto/task.go - Add taskcommon/helpers.go for shared task adaptor utilities - Remove controller/task_video.go (logic consolidated into service layer) - Update all task adaptors (ali, doubao, gemini, hailuo, jimeng, kling, sora, suno, vertex, vidu) - Simplify frontend task logs to use new TaskDto response format
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package dto
|
||
|
||
import (
|
||
"encoding/json"
|
||
)
|
||
|
||
type TaskError struct {
|
||
Code string `json:"code"`
|
||
Message string `json:"message"`
|
||
Data any `json:"data"`
|
||
StatusCode int `json:"-"`
|
||
LocalError bool `json:"-"`
|
||
Error error `json:"-"`
|
||
}
|
||
|
||
type TaskData interface {
|
||
SunoDataResponse | []SunoDataResponse | string | any
|
||
}
|
||
|
||
const TaskSuccessCode = "success"
|
||
|
||
type TaskResponse[T TaskData] struct {
|
||
Code string `json:"code"`
|
||
Message string `json:"message"`
|
||
Data T `json:"data"`
|
||
}
|
||
|
||
func (t *TaskResponse[T]) IsSuccess() bool {
|
||
return t.Code == TaskSuccessCode
|
||
}
|
||
|
||
type TaskDto struct {
|
||
ID int64 `json:"id"`
|
||
CreatedAt int64 `json:"created_at"`
|
||
UpdatedAt int64 `json:"updated_at"`
|
||
TaskID string `json:"task_id"`
|
||
Platform string `json:"platform"`
|
||
UserId int `json:"user_id"`
|
||
Group string `json:"group"`
|
||
ChannelId int `json:"channel_id"`
|
||
Quota int `json:"quota"`
|
||
Action string `json:"action"`
|
||
Status string `json:"status"`
|
||
FailReason string `json:"fail_reason"`
|
||
ResultURL string `json:"result_url,omitempty"` // 任务结果 URL(视频地址等)
|
||
SubmitTime int64 `json:"submit_time"`
|
||
StartTime int64 `json:"start_time"`
|
||
FinishTime int64 `json:"finish_time"`
|
||
Progress string `json:"progress"`
|
||
Properties any `json:"properties"`
|
||
Username string `json:"username,omitempty"`
|
||
Data json.RawMessage `json:"data"`
|
||
}
|
||
|
||
type FetchReq struct {
|
||
IDs []string `json:"ids"`
|
||
}
|