relay_task.go 18 KB

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