mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-29 23:28:36 +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
49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package router
|
|
|
|
import (
|
|
"github.com/QuantumNous/new-api/controller"
|
|
"github.com/QuantumNous/new-api/middleware"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetVideoRouter(router *gin.Engine) {
|
|
// Video proxy: accepts either session auth (dashboard) or token auth (API clients)
|
|
videoProxyRouter := router.Group("/v1")
|
|
videoProxyRouter.Use(middleware.TokenOrUserAuth())
|
|
{
|
|
videoProxyRouter.GET("/videos/:task_id/content", controller.VideoProxy)
|
|
}
|
|
|
|
videoV1Router := router.Group("/v1")
|
|
videoV1Router.Use(middleware.TokenAuth(), middleware.Distribute())
|
|
{
|
|
videoV1Router.POST("/video/generations", controller.RelayTask)
|
|
videoV1Router.GET("/video/generations/:task_id", controller.RelayTask)
|
|
videoV1Router.POST("/videos/:video_id/remix", controller.RelayTask)
|
|
}
|
|
// openai compatible API video routes
|
|
// docs: https://platform.openai.com/docs/api-reference/videos/create
|
|
{
|
|
videoV1Router.POST("/videos", controller.RelayTask)
|
|
videoV1Router.GET("/videos/:task_id", controller.RelayTask)
|
|
}
|
|
|
|
klingV1Router := router.Group("/kling/v1")
|
|
klingV1Router.Use(middleware.KlingRequestConvert(), middleware.TokenAuth(), middleware.Distribute())
|
|
{
|
|
klingV1Router.POST("/videos/text2video", controller.RelayTask)
|
|
klingV1Router.POST("/videos/image2video", controller.RelayTask)
|
|
klingV1Router.GET("/videos/text2video/:task_id", controller.RelayTask)
|
|
klingV1Router.GET("/videos/image2video/:task_id", controller.RelayTask)
|
|
}
|
|
|
|
// Jimeng official API routes - direct mapping to official API format
|
|
jimengOfficialGroup := router.Group("jimeng")
|
|
jimengOfficialGroup.Use(middleware.JimengRequestConvert(), middleware.TokenAuth(), middleware.Distribute())
|
|
{
|
|
// Maps to: /?Action=CVSync2AsyncSubmitTask&Version=2022-08-31 and /?Action=CVSync2AsyncGetResult&Version=2022-08-31
|
|
jimengOfficialGroup.POST("/", controller.RelayTask)
|
|
}
|
|
}
|