relay_task.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. package relay
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "io"
  7. "net/http"
  8. "strconv"
  9. "strings"
  10. "github.com/QuantumNous/new-api/common"
  11. "github.com/QuantumNous/new-api/constant"
  12. "github.com/QuantumNous/new-api/dto"
  13. "github.com/QuantumNous/new-api/model"
  14. "github.com/QuantumNous/new-api/relay/channel"
  15. "github.com/QuantumNous/new-api/relay/channel/task/taskcommon"
  16. relaycommon "github.com/QuantumNous/new-api/relay/common"
  17. relayconstant "github.com/QuantumNous/new-api/relay/constant"
  18. "github.com/QuantumNous/new-api/relay/helper"
  19. "github.com/QuantumNous/new-api/service"
  20. "github.com/gin-gonic/gin"
  21. )
  22. type TaskSubmitResult struct {
  23. UpstreamTaskID string
  24. TaskData []byte
  25. Platform constant.TaskPlatform
  26. Quota int
  27. //PerCallPrice types.PriceData
  28. }
  29. // ResolveOriginTask 处理基于已有任务的提交(remix / continuation):
  30. // 查找原始任务、从中提取模型名称、将渠道锁定到原始任务的渠道
  31. // (通过 info.LockedChannel,重试时复用同一渠道并轮换 key),
  32. // 以及提取 OtherRatios(时长、分辨率)。
  33. // 该函数在控制器的重试循环之前调用一次,其结果通过 info 字段和上下文持久化。
  34. func ResolveOriginTask(c *gin.Context, info *relaycommon.RelayInfo) *dto.TaskError {
  35. // 检测 remix action
  36. path := c.Request.URL.Path
  37. if strings.Contains(path, "/v1/videos/") && strings.HasSuffix(path, "/remix") {
  38. info.Action = constant.TaskActionRemix
  39. }
  40. // 提取 remix 任务的 video_id
  41. if info.Action == constant.TaskActionRemix {
  42. videoID := c.Param("video_id")
  43. if strings.TrimSpace(videoID) == "" {
  44. return service.TaskErrorWrapperLocal(fmt.Errorf("video_id is required"), "invalid_request", http.StatusBadRequest)
  45. }
  46. info.OriginTaskID = videoID
  47. }
  48. if info.OriginTaskID == "" {
  49. return nil
  50. }
  51. // 查找原始任务
  52. originTask, exist, err := model.GetByTaskId(info.UserId, info.OriginTaskID)
  53. if err != nil {
  54. return service.TaskErrorWrapper(err, "get_origin_task_failed", http.StatusInternalServerError)
  55. }
  56. if !exist {
  57. return service.TaskErrorWrapperLocal(errors.New("task_origin_not_exist"), "task_not_exist", http.StatusBadRequest)
  58. }
  59. // 从原始任务推导模型名称
  60. if info.OriginModelName == "" {
  61. if originTask.Properties.OriginModelName != "" {
  62. info.OriginModelName = originTask.Properties.OriginModelName
  63. } else if originTask.Properties.UpstreamModelName != "" {
  64. info.OriginModelName = originTask.Properties.UpstreamModelName
  65. } else {
  66. var taskData map[string]interface{}
  67. _ = common.Unmarshal(originTask.Data, &taskData)
  68. if m, ok := taskData["model"].(string); ok && m != "" {
  69. info.OriginModelName = m
  70. }
  71. }
  72. }
  73. // 锁定到原始任务的渠道(重试时复用同一渠道,轮换 key)
  74. ch, err := model.GetChannelById(originTask.ChannelId, true)
  75. if err != nil {
  76. return service.TaskErrorWrapperLocal(err, "channel_not_found", http.StatusBadRequest)
  77. }
  78. if ch.Status != common.ChannelStatusEnabled {
  79. return service.TaskErrorWrapperLocal(errors.New("the channel of the origin task is disabled"), "task_channel_disable", http.StatusBadRequest)
  80. }
  81. info.LockedChannel = ch
  82. if originTask.ChannelId != info.ChannelId {
  83. key, _, newAPIError := ch.GetNextEnabledKey()
  84. if newAPIError != nil {
  85. return service.TaskErrorWrapper(newAPIError, "channel_no_available_key", newAPIError.StatusCode)
  86. }
  87. common.SetContextKey(c, constant.ContextKeyChannelKey, key)
  88. common.SetContextKey(c, constant.ContextKeyChannelType, ch.Type)
  89. common.SetContextKey(c, constant.ContextKeyChannelBaseUrl, ch.GetBaseURL())
  90. common.SetContextKey(c, constant.ContextKeyChannelId, originTask.ChannelId)
  91. info.ChannelBaseUrl = ch.GetBaseURL()
  92. info.ChannelId = originTask.ChannelId
  93. info.ChannelType = ch.Type
  94. info.ApiKey = key
  95. }
  96. // 提取 remix 参数(时长、分辨率 → OtherRatios)
  97. if info.Action == constant.TaskActionRemix {
  98. if originTask.PrivateData.BillingContext != nil {
  99. // 新的 remix 逻辑:直接从原始任务的 BillingContext 中提取 OtherRatios(如果存在)
  100. for s, f := range originTask.PrivateData.BillingContext.OtherRatios {
  101. info.PriceData.AddOtherRatio(s, f)
  102. }
  103. } else {
  104. // 旧的 remix 逻辑:直接从 task data 解析 seconds 和 size(如果存在)
  105. var taskData map[string]interface{}
  106. _ = common.Unmarshal(originTask.Data, &taskData)
  107. secondsStr, _ := taskData["seconds"].(string)
  108. seconds, _ := strconv.Atoi(secondsStr)
  109. if seconds <= 0 {
  110. seconds = 4
  111. }
  112. sizeStr, _ := taskData["size"].(string)
  113. if info.PriceData.OtherRatios == nil {
  114. info.PriceData.OtherRatios = map[string]float64{}
  115. }
  116. info.PriceData.OtherRatios["seconds"] = float64(seconds)
  117. info.PriceData.OtherRatios["size"] = 1
  118. if sizeStr == "1792x1024" || sizeStr == "1024x1792" {
  119. info.PriceData.OtherRatios["size"] = 1.666667
  120. }
  121. }
  122. }
  123. return nil
  124. }
  125. // RelayTaskSubmit 完成 task 提交的全部流程(每次尝试调用一次):
  126. // 刷新渠道元数据 → 确定 platform/adaptor → 验证请求 →
  127. // 估算计费(EstimateBilling) → 计算价格 → 预扣费(仅首次)→
  128. // 构建/发送/解析上游请求 → 提交后计费调整(AdjustBillingOnSubmit)。
  129. // 控制器负责 defer Refund 和成功后 Settle。
  130. func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (*TaskSubmitResult, *dto.TaskError) {
  131. info.InitChannelMeta(c)
  132. // 1. 确定 platform → 创建适配器 → 验证请求
  133. platform := constant.TaskPlatform(c.GetString("platform"))
  134. if platform == "" {
  135. platform = GetTaskPlatform(c)
  136. }
  137. adaptor := GetTaskAdaptor(platform)
  138. if adaptor == nil {
  139. return nil, service.TaskErrorWrapperLocal(fmt.Errorf("invalid api platform: %s", platform), "invalid_api_platform", http.StatusBadRequest)
  140. }
  141. adaptor.Init(info)
  142. if taskErr := adaptor.ValidateRequestAndSetAction(c, info); taskErr != nil {
  143. return nil, taskErr
  144. }
  145. // 2. 确定模型名称
  146. modelName := info.OriginModelName
  147. if modelName == "" {
  148. modelName = service.CoverTaskActionToModelName(platform, info.Action)
  149. }
  150. // 2.5 应用渠道的模型映射(与同步任务对齐)
  151. info.OriginModelName = modelName
  152. info.UpstreamModelName = modelName
  153. if err := helper.ModelMappedHelper(c, info, nil); err != nil {
  154. return nil, service.TaskErrorWrapperLocal(err, "model_mapping_failed", http.StatusBadRequest)
  155. }
  156. // 3. 预生成公开 task ID(仅首次)
  157. if info.PublicTaskID == "" {
  158. info.PublicTaskID = model.GenerateTaskID()
  159. }
  160. // 4. 价格计算:基础模型价格
  161. info.OriginModelName = modelName
  162. priceData, err := helper.ModelPriceHelperPerCall(c, info)
  163. if err != nil {
  164. return nil, service.TaskErrorWrapper(err, "model_price_error", http.StatusBadRequest)
  165. }
  166. info.PriceData = priceData
  167. // 5. 计费估算:让适配器根据用户请求提供 OtherRatios(时长、分辨率等)
  168. // 必须在 ModelPriceHelperPerCall 之后调用(它会重建 PriceData)。
  169. // ResolveOriginTask 可能已在 remix 路径中预设了 OtherRatios,此处合并。
  170. if estimatedRatios := adaptor.EstimateBilling(c, info); len(estimatedRatios) > 0 {
  171. for k, v := range estimatedRatios {
  172. info.PriceData.AddOtherRatio(k, v)
  173. }
  174. }
  175. // 6. 将 OtherRatios 应用到基础额度
  176. if !common.StringsContains(constant.TaskPricePatches, modelName) {
  177. for _, ra := range info.PriceData.OtherRatios {
  178. if ra != 1.0 {
  179. info.PriceData.Quota = int(float64(info.PriceData.Quota) * ra)
  180. }
  181. }
  182. }
  183. // 7. 预扣费(仅首次 — 重试时 info.Billing 已存在,跳过)
  184. if info.Billing == nil && !info.PriceData.FreeModel {
  185. info.ForcePreConsume = true
  186. if apiErr := service.PreConsumeBilling(c, info.PriceData.Quota, info); apiErr != nil {
  187. return nil, service.TaskErrorFromAPIError(apiErr)
  188. }
  189. }
  190. // 8. 构建请求体
  191. requestBody, err := adaptor.BuildRequestBody(c, info)
  192. if err != nil {
  193. return nil, service.TaskErrorWrapper(err, "build_request_failed", http.StatusInternalServerError)
  194. }
  195. // 9. 发送请求
  196. resp, err := adaptor.DoRequest(c, info, requestBody)
  197. if err != nil {
  198. return nil, service.TaskErrorWrapper(err, "do_request_failed", http.StatusInternalServerError)
  199. }
  200. if resp != nil && resp.StatusCode != http.StatusOK {
  201. responseBody, _ := io.ReadAll(resp.Body)
  202. return nil, service.TaskErrorWrapper(fmt.Errorf("%s", string(responseBody)), "fail_to_fetch_task", resp.StatusCode)
  203. }
  204. // 10. 返回 OtherRatios 给下游(header 必须在 DoResponse 写 body 之前设置)
  205. otherRatios := info.PriceData.OtherRatios
  206. if otherRatios == nil {
  207. otherRatios = map[string]float64{}
  208. }
  209. ratiosJSON, _ := common.Marshal(otherRatios)
  210. c.Header("X-New-Api-Other-Ratios", string(ratiosJSON))
  211. // 11. 解析响应
  212. upstreamTaskID, taskData, taskErr := adaptor.DoResponse(c, resp, info)
  213. if taskErr != nil {
  214. return nil, taskErr
  215. }
  216. // 11. 提交后计费调整:让适配器根据上游实际返回调整 OtherRatios
  217. finalQuota := info.PriceData.Quota
  218. if adjustedRatios := adaptor.AdjustBillingOnSubmit(info, taskData); len(adjustedRatios) > 0 {
  219. // 基于调整后的 ratios 重新计算 quota
  220. finalQuota = recalcQuotaFromRatios(info, adjustedRatios)
  221. info.PriceData.OtherRatios = adjustedRatios
  222. info.PriceData.Quota = finalQuota
  223. }
  224. return &TaskSubmitResult{
  225. UpstreamTaskID: upstreamTaskID,
  226. TaskData: taskData,
  227. Platform: platform,
  228. Quota: finalQuota,
  229. }, nil
  230. }
  231. // recalcQuotaFromRatios 根据 adjustedRatios 重新计算 quota。
  232. // 公式: baseQuota × ∏(ratio) — 其中 baseQuota 是不含 OtherRatios 的基础额度。
  233. func recalcQuotaFromRatios(info *relaycommon.RelayInfo, ratios map[string]float64) int {
  234. // 从 PriceData 获取不含 OtherRatios 的基础价格
  235. baseQuota := info.PriceData.Quota
  236. // 先除掉原有的 OtherRatios 恢复基础额度
  237. for _, ra := range info.PriceData.OtherRatios {
  238. if ra != 1.0 && ra > 0 {
  239. baseQuota = int(float64(baseQuota) / ra)
  240. }
  241. }
  242. // 应用新的 ratios
  243. result := float64(baseQuota)
  244. for _, ra := range ratios {
  245. if ra != 1.0 {
  246. result *= ra
  247. }
  248. }
  249. return int(result)
  250. }
  251. var fetchRespBuilders = map[int]func(c *gin.Context) (respBody []byte, taskResp *dto.TaskError){
  252. relayconstant.RelayModeSunoFetchByID: sunoFetchByIDRespBodyBuilder,
  253. relayconstant.RelayModeSunoFetch: sunoFetchRespBodyBuilder,
  254. relayconstant.RelayModeVideoFetchByID: videoFetchByIDRespBodyBuilder,
  255. }
  256. func RelayTaskFetch(c *gin.Context, relayMode int) (taskResp *dto.TaskError) {
  257. respBuilder, ok := fetchRespBuilders[relayMode]
  258. if !ok {
  259. taskResp = service.TaskErrorWrapperLocal(errors.New("invalid_relay_mode"), "invalid_relay_mode", http.StatusBadRequest)
  260. }
  261. respBody, taskErr := respBuilder(c)
  262. if taskErr != nil {
  263. return taskErr
  264. }
  265. if len(respBody) == 0 {
  266. respBody = []byte("{\"code\":\"success\",\"data\":null}")
  267. }
  268. c.Writer.Header().Set("Content-Type", "application/json")
  269. _, err := io.Copy(c.Writer, bytes.NewBuffer(respBody))
  270. if err != nil {
  271. taskResp = service.TaskErrorWrapper(err, "copy_response_body_failed", http.StatusInternalServerError)
  272. return
  273. }
  274. return
  275. }
  276. func sunoFetchRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *dto.TaskError) {
  277. userId := c.GetInt("id")
  278. var condition = struct {
  279. IDs []any `json:"ids"`
  280. Action string `json:"action"`
  281. }{}
  282. err := c.BindJSON(&condition)
  283. if err != nil {
  284. taskResp = service.TaskErrorWrapper(err, "invalid_request", http.StatusBadRequest)
  285. return
  286. }
  287. var tasks []any
  288. if len(condition.IDs) > 0 {
  289. taskModels, err := model.GetByTaskIds(userId, condition.IDs)
  290. if err != nil {
  291. taskResp = service.TaskErrorWrapper(err, "get_tasks_failed", http.StatusInternalServerError)
  292. return
  293. }
  294. for _, task := range taskModels {
  295. tasks = append(tasks, TaskModel2Dto(task))
  296. }
  297. } else {
  298. tasks = make([]any, 0)
  299. }
  300. respBody, err = common.Marshal(dto.TaskResponse[[]any]{
  301. Code: "success",
  302. Data: tasks,
  303. })
  304. return
  305. }
  306. func sunoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *dto.TaskError) {
  307. taskId := c.Param("id")
  308. userId := c.GetInt("id")
  309. originTask, exist, err := model.GetByTaskId(userId, taskId)
  310. if err != nil {
  311. taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
  312. return
  313. }
  314. if !exist {
  315. taskResp = service.TaskErrorWrapperLocal(errors.New("task_not_exist"), "task_not_exist", http.StatusBadRequest)
  316. return
  317. }
  318. respBody, err = common.Marshal(dto.TaskResponse[any]{
  319. Code: "success",
  320. Data: TaskModel2Dto(originTask),
  321. })
  322. return
  323. }
  324. func videoFetchByIDRespBodyBuilder(c *gin.Context) (respBody []byte, taskResp *dto.TaskError) {
  325. taskId := c.Param("task_id")
  326. if taskId == "" {
  327. taskId = c.GetString("task_id")
  328. }
  329. userId := c.GetInt("id")
  330. originTask, exist, err := model.GetByTaskId(userId, taskId)
  331. if err != nil {
  332. taskResp = service.TaskErrorWrapper(err, "get_task_failed", http.StatusInternalServerError)
  333. return
  334. }
  335. if !exist {
  336. taskResp = service.TaskErrorWrapperLocal(errors.New("task_not_exist"), "task_not_exist", http.StatusBadRequest)
  337. return
  338. }
  339. isOpenAIVideoAPI := strings.HasPrefix(c.Request.RequestURI, "/v1/videos/")
  340. // Gemini/Vertex 支持实时查询:用户 fetch 时直接从上游拉取最新状态
  341. if realtimeResp := tryRealtimeFetch(originTask, isOpenAIVideoAPI); len(realtimeResp) > 0 {
  342. respBody = realtimeResp
  343. return
  344. }
  345. // OpenAI Video API 格式: 走各 adaptor 的 ConvertToOpenAIVideo
  346. if isOpenAIVideoAPI {
  347. adaptor := GetTaskAdaptor(originTask.Platform)
  348. if adaptor == nil {
  349. taskResp = service.TaskErrorWrapperLocal(fmt.Errorf("invalid channel id: %d", originTask.ChannelId), "invalid_channel_id", http.StatusBadRequest)
  350. return
  351. }
  352. if converter, ok := adaptor.(channel.OpenAIVideoConverter); ok {
  353. openAIVideoData, err := converter.ConvertToOpenAIVideo(originTask)
  354. if err != nil {
  355. taskResp = service.TaskErrorWrapper(err, "convert_to_openai_video_failed", http.StatusInternalServerError)
  356. return
  357. }
  358. respBody = openAIVideoData
  359. return
  360. }
  361. taskResp = service.TaskErrorWrapperLocal(fmt.Errorf("not_implemented:%s", originTask.Platform), "not_implemented", http.StatusNotImplemented)
  362. return
  363. }
  364. // 通用 TaskDto 格式
  365. respBody, err = common.Marshal(dto.TaskResponse[any]{
  366. Code: "success",
  367. Data: TaskModel2Dto(originTask),
  368. })
  369. if err != nil {
  370. taskResp = service.TaskErrorWrapper(err, "marshal_response_failed", http.StatusInternalServerError)
  371. }
  372. return
  373. }
  374. // tryRealtimeFetch 尝试从上游实时拉取 Gemini/Vertex 任务状态。
  375. // 仅当渠道类型为 Gemini 或 Vertex 时触发;其他渠道或出错时返回 nil。
  376. // 当非 OpenAI Video API 时,还会构建自定义格式的响应体。
  377. func tryRealtimeFetch(task *model.Task, isOpenAIVideoAPI bool) []byte {
  378. channelModel, err := model.GetChannelById(task.ChannelId, true)
  379. if err != nil {
  380. return nil
  381. }
  382. if channelModel.Type != constant.ChannelTypeVertexAi && channelModel.Type != constant.ChannelTypeGemini {
  383. return nil
  384. }
  385. baseURL := constant.ChannelBaseURLs[channelModel.Type]
  386. if channelModel.GetBaseURL() != "" {
  387. baseURL = channelModel.GetBaseURL()
  388. }
  389. proxy := channelModel.GetSetting().Proxy
  390. adaptor := GetTaskAdaptor(constant.TaskPlatform(strconv.Itoa(channelModel.Type)))
  391. if adaptor == nil {
  392. return nil
  393. }
  394. resp, err := adaptor.FetchTask(baseURL, channelModel.Key, map[string]any{
  395. "task_id": task.GetUpstreamTaskID(),
  396. "action": task.Action,
  397. }, proxy)
  398. if err != nil || resp == nil {
  399. return nil
  400. }
  401. defer resp.Body.Close()
  402. body, err := io.ReadAll(resp.Body)
  403. if err != nil {
  404. return nil
  405. }
  406. ti, err := adaptor.ParseTaskResult(body)
  407. if err != nil || ti == nil {
  408. return nil
  409. }
  410. snap := task.Snapshot()
  411. // 将上游最新状态更新到 task
  412. if ti.Status != "" {
  413. task.Status = model.TaskStatus(ti.Status)
  414. }
  415. if ti.Progress != "" {
  416. task.Progress = ti.Progress
  417. }
  418. if strings.HasPrefix(ti.Url, "data:") {
  419. // data: URI — kept in Data, not ResultURL
  420. } else if ti.Url != "" {
  421. task.PrivateData.ResultURL = ti.Url
  422. } else if task.Status == model.TaskStatusSuccess {
  423. // No URL from adaptor — construct proxy URL using public task ID
  424. task.PrivateData.ResultURL = taskcommon.BuildProxyURL(task.TaskID)
  425. }
  426. if !snap.Equal(task.Snapshot()) {
  427. _, _ = task.UpdateWithStatus(snap.Status)
  428. }
  429. // OpenAI Video API 由调用者的 ConvertToOpenAIVideo 分支处理
  430. if isOpenAIVideoAPI {
  431. return nil
  432. }
  433. // 非 OpenAI Video API: 构建自定义格式响应
  434. format := detectVideoFormat(body)
  435. out := map[string]any{
  436. "error": nil,
  437. "format": format,
  438. "metadata": nil,
  439. "status": mapTaskStatusToSimple(task.Status),
  440. "task_id": task.TaskID,
  441. "url": task.GetResultURL(),
  442. }
  443. respBody, _ := common.Marshal(dto.TaskResponse[any]{
  444. Code: "success",
  445. Data: out,
  446. })
  447. return respBody
  448. }
  449. // detectVideoFormat 从 Gemini/Vertex 原始响应中探测视频格式
  450. func detectVideoFormat(rawBody []byte) string {
  451. var raw map[string]any
  452. if err := common.Unmarshal(rawBody, &raw); err != nil {
  453. return "mp4"
  454. }
  455. respObj, ok := raw["response"].(map[string]any)
  456. if !ok {
  457. return "mp4"
  458. }
  459. vids, ok := respObj["videos"].([]any)
  460. if !ok || len(vids) == 0 {
  461. return "mp4"
  462. }
  463. v0, ok := vids[0].(map[string]any)
  464. if !ok {
  465. return "mp4"
  466. }
  467. mt, ok := v0["mimeType"].(string)
  468. if !ok || mt == "" || strings.Contains(mt, "mp4") {
  469. return "mp4"
  470. }
  471. return mt
  472. }
  473. // mapTaskStatusToSimple 将内部 TaskStatus 映射为简化状态字符串
  474. func mapTaskStatusToSimple(status model.TaskStatus) string {
  475. switch status {
  476. case model.TaskStatusSuccess:
  477. return "succeeded"
  478. case model.TaskStatusFailure:
  479. return "failed"
  480. case model.TaskStatusQueued, model.TaskStatusSubmitted:
  481. return "queued"
  482. default:
  483. return "processing"
  484. }
  485. }
  486. func TaskModel2Dto(task *model.Task) *dto.TaskDto {
  487. return &dto.TaskDto{
  488. ID: task.ID,
  489. CreatedAt: task.CreatedAt,
  490. UpdatedAt: task.UpdatedAt,
  491. TaskID: task.TaskID,
  492. Platform: string(task.Platform),
  493. UserId: task.UserId,
  494. Group: task.Group,
  495. ChannelId: task.ChannelId,
  496. Quota: task.Quota,
  497. Action: task.Action,
  498. Status: string(task.Status),
  499. FailReason: task.FailReason,
  500. ResultURL: task.GetResultURL(),
  501. SubmitTime: task.SubmitTime,
  502. StartTime: task.StartTime,
  503. FinishTime: task.FinishTime,
  504. Progress: task.Progress,
  505. Properties: task.Properties,
  506. Username: task.Username,
  507. Data: task.Data,
  508. }
  509. }