2024-06-12 20:37:42 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strconv"
|
2025-07-14 21:59:42 +08:00
|
|
|
|
2025-10-11 15:30:09 +08:00
|
|
|
"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"
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
"github.com/QuantumNous/new-api/service"
|
2025-10-11 15:30:09 +08:00
|
|
|
|
2025-07-14 21:59:42 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2024-06-12 20:37:42 +08:00
|
|
|
)
|
|
|
|
|
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
// UpdateTaskBulk 薄入口,实际轮询逻辑在 service 层
|
2024-06-12 20:37:42 +08:00
|
|
|
func UpdateTaskBulk() {
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
service.TaskPollingLoop()
|
2024-06-12 20:37:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetAllTask(c *gin.Context) {
|
2025-07-14 21:59:42 +08:00
|
|
|
pageInfo := common.GetPageQuery(c)
|
🚀 feat(pagination): unify backend-driven pagination & improve channel tag aggregation
SUMMARY
• Migrated Token, Task, Midjourney, Channel, Redemption tables to true server-side pagination.
• Added total / page / page_size metadata in API responses; switched all affected React tables to consume new structure.
• Implemented counting helpers:
– model/token.go CountUserTokens
– model/task.go TaskCountAllTasks / TaskCountAllUserTask
– model/midjourney.go CountAllTasks / CountAllUserTask
– model/channel.go CountAllChannels / CountAllTags
• Refactored controllers (token, task, midjourney, channel) for 1-based paging & aggregated returns.
• Redesigned `ChannelsTable.js`:
– `loadChannels`, `syncPageData`, `enrichChannels` for tag-mode grouping without recursion.
– Fixed runtime white-screen (maximum call-stack) by removing child duplication.
– Pagination, search, tag-mode, idSort all hot-reload correctly.
• Removed unused `log` import in controller/midjourney.go.
BREAKING CHANGES
Front-end consumers must now expect data.items / total / page / page_size from list endpoints (`/api/channel`, `/api/task`, `/api/mj`, `/api/token`, etc.).
2025-06-12 17:25:25 +08:00
|
|
|
|
2024-06-12 20:37:42 +08:00
|
|
|
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,
|
🚀 feat(pagination): unify backend-driven pagination & improve channel tag aggregation
SUMMARY
• Migrated Token, Task, Midjourney, Channel, Redemption tables to true server-side pagination.
• Added total / page / page_size metadata in API responses; switched all affected React tables to consume new structure.
• Implemented counting helpers:
– model/token.go CountUserTokens
– model/task.go TaskCountAllTasks / TaskCountAllUserTask
– model/midjourney.go CountAllTasks / CountAllUserTask
– model/channel.go CountAllChannels / CountAllTags
• Refactored controllers (token, task, midjourney, channel) for 1-based paging & aggregated returns.
• Redesigned `ChannelsTable.js`:
– `loadChannels`, `syncPageData`, `enrichChannels` for tag-mode grouping without recursion.
– Fixed runtime white-screen (maximum call-stack) by removing child duplication.
– Pagination, search, tag-mode, idSort all hot-reload correctly.
• Removed unused `log` import in controller/midjourney.go.
BREAKING CHANGES
Front-end consumers must now expect data.items / total / page / page_size from list endpoints (`/api/channel`, `/api/task`, `/api/mj`, `/api/token`, etc.).
2025-06-12 17:25:25 +08:00
|
|
|
ChannelID: c.Query("channel_id"),
|
2024-06-12 20:37:42 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-14 21:59:42 +08:00
|
|
|
items := model.TaskGetAllTasks(pageInfo.GetStartIdx(), pageInfo.GetPageSize(), queryParams)
|
🚀 feat(pagination): unify backend-driven pagination & improve channel tag aggregation
SUMMARY
• Migrated Token, Task, Midjourney, Channel, Redemption tables to true server-side pagination.
• Added total / page / page_size metadata in API responses; switched all affected React tables to consume new structure.
• Implemented counting helpers:
– model/token.go CountUserTokens
– model/task.go TaskCountAllTasks / TaskCountAllUserTask
– model/midjourney.go CountAllTasks / CountAllUserTask
– model/channel.go CountAllChannels / CountAllTags
• Refactored controllers (token, task, midjourney, channel) for 1-based paging & aggregated returns.
• Redesigned `ChannelsTable.js`:
– `loadChannels`, `syncPageData`, `enrichChannels` for tag-mode grouping without recursion.
– Fixed runtime white-screen (maximum call-stack) by removing child duplication.
– Pagination, search, tag-mode, idSort all hot-reload correctly.
• Removed unused `log` import in controller/midjourney.go.
BREAKING CHANGES
Front-end consumers must now expect data.items / total / page / page_size from list endpoints (`/api/channel`, `/api/task`, `/api/mj`, `/api/token`, etc.).
2025-06-12 17:25:25 +08:00
|
|
|
total := model.TaskCountAllTasks(queryParams)
|
2025-07-14 21:59:42 +08:00
|
|
|
pageInfo.SetTotal(int(total))
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
pageInfo.SetItems(tasksToDto(items))
|
2025-07-14 21:59:42 +08:00
|
|
|
common.ApiSuccess(c, pageInfo)
|
2024-06-12 20:37:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserTask(c *gin.Context) {
|
2025-07-14 21:59:42 +08:00
|
|
|
pageInfo := common.GetPageQuery(c)
|
2024-06-12 20:37:42 +08:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-14 21:59:42 +08:00
|
|
|
items := model.TaskGetAllUserTask(userId, pageInfo.GetStartIdx(), pageInfo.GetPageSize(), queryParams)
|
🚀 feat(pagination): unify backend-driven pagination & improve channel tag aggregation
SUMMARY
• Migrated Token, Task, Midjourney, Channel, Redemption tables to true server-side pagination.
• Added total / page / page_size metadata in API responses; switched all affected React tables to consume new structure.
• Implemented counting helpers:
– model/token.go CountUserTokens
– model/task.go TaskCountAllTasks / TaskCountAllUserTask
– model/midjourney.go CountAllTasks / CountAllUserTask
– model/channel.go CountAllChannels / CountAllTags
• Refactored controllers (token, task, midjourney, channel) for 1-based paging & aggregated returns.
• Redesigned `ChannelsTable.js`:
– `loadChannels`, `syncPageData`, `enrichChannels` for tag-mode grouping without recursion.
– Fixed runtime white-screen (maximum call-stack) by removing child duplication.
– Pagination, search, tag-mode, idSort all hot-reload correctly.
• Removed unused `log` import in controller/midjourney.go.
BREAKING CHANGES
Front-end consumers must now expect data.items / total / page / page_size from list endpoints (`/api/channel`, `/api/task`, `/api/mj`, `/api/token`, etc.).
2025-06-12 17:25:25 +08:00
|
|
|
total := model.TaskCountAllUserTask(userId, queryParams)
|
2025-07-14 21:59:42 +08:00
|
|
|
pageInfo.SetTotal(int(total))
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
pageInfo.SetItems(tasksToDto(items))
|
2025-07-14 21:59:42 +08:00
|
|
|
common.ApiSuccess(c, pageInfo)
|
2024-06-12 20:37:42 +08:00
|
|
|
}
|
refactor(task): extract billing and polling logic from controller to service layer
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
2026-02-10 20:40:33 +08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|