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
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/constant"
|
|
"github.com/QuantumNous/new-api/dto"
|
|
"github.com/QuantumNous/new-api/model"
|
|
"github.com/QuantumNous/new-api/relay"
|
|
"github.com/QuantumNous/new-api/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// UpdateTaskBulk 薄入口,实际轮询逻辑在 service 层
|
|
func UpdateTaskBulk() {
|
|
service.TaskPollingLoop()
|
|
}
|
|
|
|
func GetAllTask(c *gin.Context) {
|
|
pageInfo := common.GetPageQuery(c)
|
|
|
|
startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
|
|
endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
|
|
// 解析其他查询参数
|
|
queryParams := model.SyncTaskQueryParams{
|
|
Platform: constant.TaskPlatform(c.Query("platform")),
|
|
TaskID: c.Query("task_id"),
|
|
Status: c.Query("status"),
|
|
Action: c.Query("action"),
|
|
StartTimestamp: startTimestamp,
|
|
EndTimestamp: endTimestamp,
|
|
ChannelID: c.Query("channel_id"),
|
|
}
|
|
|
|
items := model.TaskGetAllTasks(pageInfo.GetStartIdx(), pageInfo.GetPageSize(), queryParams)
|
|
total := model.TaskCountAllTasks(queryParams)
|
|
pageInfo.SetTotal(int(total))
|
|
pageInfo.SetItems(tasksToDto(items))
|
|
common.ApiSuccess(c, pageInfo)
|
|
}
|
|
|
|
func GetUserTask(c *gin.Context) {
|
|
pageInfo := common.GetPageQuery(c)
|
|
|
|
userId := c.GetInt("id")
|
|
|
|
startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
|
|
endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
|
|
|
|
queryParams := model.SyncTaskQueryParams{
|
|
Platform: constant.TaskPlatform(c.Query("platform")),
|
|
TaskID: c.Query("task_id"),
|
|
Status: c.Query("status"),
|
|
Action: c.Query("action"),
|
|
StartTimestamp: startTimestamp,
|
|
EndTimestamp: endTimestamp,
|
|
}
|
|
|
|
items := model.TaskGetAllUserTask(userId, pageInfo.GetStartIdx(), pageInfo.GetPageSize(), queryParams)
|
|
total := model.TaskCountAllUserTask(userId, queryParams)
|
|
pageInfo.SetTotal(int(total))
|
|
pageInfo.SetItems(tasksToDto(items))
|
|
common.ApiSuccess(c, pageInfo)
|
|
}
|
|
|
|
func tasksToDto(tasks []*model.Task) []*dto.TaskDto {
|
|
result := make([]*dto.TaskDto, len(tasks))
|
|
for i, task := range tasks {
|
|
result[i] = relay.TaskModel2Dto(task)
|
|
}
|
|
return result
|
|
}
|