cloudreve_api/api/v4/models/
task.rs

1//! Task and workflow models for Cloudreve API v4
2
3use serde::{Deserialize, Serialize};
4
5/// Basic task information
6#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct Task {
8    pub id: String,
9    pub name: Option<String>,
10    pub status: String,
11    pub created_at: String,
12    pub updated_at: String,
13}
14
15/// Detailed task information
16#[derive(Debug, Serialize, Deserialize, Clone)]
17pub struct TaskResponse {
18    pub created_at: String,
19    pub updated_at: String,
20    pub id: String,
21    pub status: TaskStatus,
22    pub r#type: TaskType,
23    pub summary: Option<TaskSummary>,
24    pub duration: Option<i64>,
25    pub resume_time: Option<i64>,
26    pub error: Option<String>,
27    pub error_history: Option<Vec<String>>,
28    pub retry_count: Option<i32>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub node: Option<NewNode>,
31}
32
33/// Task status enum
34#[derive(Debug, Serialize, Deserialize, Clone)]
35pub enum TaskStatus {
36    #[serde(rename = "queued")]
37    Queued,
38    #[serde(rename = "processing")]
39    Processing,
40    #[serde(rename = "suspending")]
41    Suspending,
42    #[serde(rename = "error")]
43    Error,
44    #[serde(rename = "canceled")]
45    Canceled,
46    #[serde(rename = "completed")]
47    Completed,
48}
49
50/// Task type enum
51#[derive(Debug, Serialize, Deserialize, Clone)]
52pub enum TaskType {
53    #[serde(rename = "media_meta")]
54    MediaMeta,
55    #[serde(rename = "entity_recycle_routine")]
56    EntityRecycleRoutine,
57    #[serde(rename = "explicit_entity_recycle")]
58    ExplicitEntityRecycle,
59    #[serde(rename = "upload_sentinel_check")]
60    UploadSentinelCheck,
61    #[serde(rename = "create_archive")]
62    CreateArchive,
63    #[serde(rename = "extract_archive")]
64    ExtractArchive,
65    #[serde(rename = "relocate")]
66    Relocate,
67    #[serde(rename = "remote_download")]
68    RemoteDownload,
69    #[serde(rename = "import")]
70    Import,
71}
72
73/// Task summary
74#[derive(Debug, Serialize, Deserialize, Clone)]
75pub struct TaskSummary {
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub phase: Option<String>,
78    pub props: serde_json::Value,
79}
80
81/// Node information
82#[derive(Debug, Serialize, Deserialize, Clone)]
83pub struct NewNode {
84    pub id: String,
85    pub name: String,
86    pub r#type: NodeType,
87    pub capabilities: String,
88}
89
90/// Node type enum
91#[derive(Debug, Serialize, Deserialize, Clone)]
92pub enum NodeType {
93    #[serde(rename = "master")]
94    Master,
95    #[serde(rename = "slave")]
96    Slave,
97}
98
99/// Task list response
100#[derive(Debug, Serialize, Deserialize, Clone)]
101pub struct TaskListResponse {
102    pub pagination: TaskPagination,
103    pub tasks: Vec<TaskResponse>,
104}
105
106/// Task pagination metadata
107#[derive(Debug, Serialize, Deserialize, Clone)]
108pub struct TaskPagination {
109    pub page_size: i32,
110    pub next_token: Option<String>,
111    pub is_cursor: bool,
112}
113
114/// Task progress information
115#[derive(Debug, Serialize, Deserialize, Clone)]
116pub struct TaskProgress {
117    pub progress: f64,
118    pub message: String,
119    pub total: Option<u64>,
120    pub current: Option<u64>,
121}
122
123/// Detailed task with progress
124#[derive(Debug, Deserialize, Clone)]
125pub struct DetailedTask {
126    pub id: String,
127    pub name: String,
128    pub status: String,
129    pub type_: String,
130    pub created_at: String,
131    pub updated_at: String,
132    pub progress: Option<TaskProgress>,
133}
134
135/// Upload progress
136#[derive(Debug, Serialize, Deserialize, Clone)]
137pub struct Progress {
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub total: Option<i64>,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub current: Option<i64>,
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub identifier: Option<String>,
144}
145
146/// File activity
147#[derive(Debug, Serialize, Deserialize, Clone)]
148pub struct Activity {
149    pub id: String,
150    pub content: LogEntry,
151    pub created_at: String,
152    pub user: Option<super::auth::NewUser>,
153    pub version_id: Option<String>,
154}
155
156/// Log entry
157#[derive(Debug, Serialize, Deserialize, Clone)]
158pub struct LogEntry {
159    pub r#type: String,
160    pub props: serde_json::Value,
161}
162
163/// File activities response
164#[derive(Debug, Serialize, Deserialize, Clone)]
165pub struct FileActivitiesResponse {
166    pub activities: Vec<Activity>,
167    pub pagination: ActivitiesPagination,
168}
169
170/// Activities pagination metadata
171#[derive(Debug, Serialize, Deserialize, Clone)]
172pub struct ActivitiesPagination {
173    pub page: i32,
174    pub page_size: i32,
175    pub next_token: Option<String>,
176    pub is_cursor: bool,
177}
178
179/// List tasks request
180#[derive(Debug, Serialize, Default)]
181pub struct ListTasksRequest<'a> {
182    pub page: Option<u32>,
183    pub per_page: Option<u32>,
184    pub status: Option<&'a str>,
185    pub type_: Option<&'a str>,
186}
187
188/// Create archive request
189#[derive(Debug, Serialize)]
190pub struct CreateArchiveRequest<'a> {
191    #[serde(rename = "src")]
192    pub src: Vec<&'a str>,
193    #[serde(rename = "dst")]
194    pub dst: &'a str,
195}
196
197/// Extract archive request
198#[derive(Debug, Serialize)]
199pub struct ExtractArchiveRequest<'a> {
200    #[serde(rename = "src")]
201    pub src: Vec<&'a str>,
202    #[serde(rename = "dst")]
203    pub dst: &'a str,
204}