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