BuildTaskPluginView converts a persisted task into the deliberately narrow public shape permitted at JavaScript plugin boundaries.
(task *model.Task)
| 9 | // BuildTaskPluginView converts a persisted task into the deliberately narrow |
| 10 | // public shape permitted at JavaScript plugin boundaries. |
| 11 | func BuildTaskPluginView(task *model.Task) (dto.TaskView, error) { |
| 12 | createdAt := task.CreatedAt |
| 13 | if createdAt == 0 { |
| 14 | createdAt = task.SubmitTime |
| 15 | } |
| 16 | view := dto.TaskView{ |
| 17 | TaskID: task.TaskID, |
| 18 | Platform: string(task.Platform), |
| 19 | Status: string(task.Status), |
| 20 | Progress: task.Progress, |
| 21 | FailReason: task.FailReason, |
| 22 | CreatedAt: createdAt, |
| 23 | UpdatedAt: task.UpdatedAt, |
| 24 | FinishedAt: task.FinishTime, |
| 25 | } |
| 26 | if len(task.Data) > 0 { |
| 27 | if err := common.Unmarshal(task.Data, &view.Data); err != nil { |
| 28 | return dto.TaskView{}, err |
| 29 | } |
| 30 | view.Data = replacePrivateTaskID(view.Data, task.PrivateData.UpstreamTaskID, task.TaskID) |
| 31 | } |
| 32 | return view, nil |
| 33 | } |
| 34 | |
| 35 | // replacePrivateTaskID rewrites exact private IDs only in known task-ID fields. |
| 36 | // Map keys and opaque strings, including URLs containing the ID, are preserved. |