task.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dto
  2. import (
  3. "encoding/json"
  4. )
  5. type TaskError struct {
  6. Code string `json:"code"`
  7. Message string `json:"message"`
  8. Data any `json:"data"`
  9. StatusCode int `json:"-"`
  10. LocalError bool `json:"-"`
  11. Error error `json:"-"`
  12. }
  13. type TaskData interface {
  14. SunoDataResponse | []SunoDataResponse | string | any
  15. }
  16. const TaskSuccessCode = "success"
  17. type TaskResponse[T TaskData] struct {
  18. Code string `json:"code"`
  19. Message string `json:"message"`
  20. Data T `json:"data"`
  21. }
  22. func (t *TaskResponse[T]) IsSuccess() bool {
  23. return t.Code == TaskSuccessCode
  24. }
  25. type TaskDto struct {
  26. ID int64 `json:"id"`
  27. CreatedAt int64 `json:"created_at"`
  28. UpdatedAt int64 `json:"updated_at"`
  29. TaskID string `json:"task_id"`
  30. Platform string `json:"platform"`
  31. UserId int `json:"user_id"`
  32. Group string `json:"group"`
  33. ChannelId int `json:"channel_id"`
  34. Quota int `json:"quota"`
  35. Action string `json:"action"`
  36. Status string `json:"status"`
  37. FailReason string `json:"fail_reason"`
  38. ResultURL string `json:"result_url,omitempty"` // 任务结果 URL(视频地址等)
  39. SubmitTime int64 `json:"submit_time"`
  40. StartTime int64 `json:"start_time"`
  41. FinishTime int64 `json:"finish_time"`
  42. Progress string `json:"progress"`
  43. Properties any `json:"properties"`
  44. Username string `json:"username,omitempty"`
  45. Data json.RawMessage `json:"data"`
  46. }
  47. type FetchReq struct {
  48. IDs []string `json:"ids"`
  49. }