Skip to main content

cloudreve_api/api/v4/models/
request.rs

1//! Request types for Cloudreve API v4
2
3use serde::Serialize;
4
5/// Upload file request
6#[derive(Debug, Serialize)]
7pub struct UploadRequest<'a> {
8    pub path: &'a str,
9    pub name: Option<&'a str>,
10    pub overwrite: Option<bool>,
11}
12
13/// List files request
14#[derive(Debug, Serialize, Default)]
15pub struct ListFilesRequest<'a> {
16    pub path: &'a str,
17    pub page: Option<u32>,
18    pub page_size: Option<u32>,
19    pub order_by: Option<&'a str>,
20    pub order_direction: Option<&'a str>,
21    pub next_page_token: Option<&'a str>,
22}
23
24/// Move file request (also used for copy with copy=true)
25#[derive(Debug, Serialize)]
26pub struct MoveFileRequest<'a> {
27    pub uris: Vec<&'a str>,
28    pub dst: &'a str,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub copy: Option<bool>,
31}
32
33/// Copy file request
34#[derive(Debug, Serialize)]
35pub struct CopyFileRequest<'a> {
36    pub uris: Vec<&'a str>,
37    pub dst: &'a str,
38}
39
40/// Rename file request
41#[derive(Debug, Serialize)]
42pub struct RenameFileRequest<'a> {
43    pub uri: &'a str,
44    pub new_name: &'a str,
45}
46
47/// Set file permission request
48#[derive(Debug, Serialize)]
49pub struct SetFilePermissionRequest<'a> {
50    /// File path (will be converted to URI format internally)
51    ///
52    /// Can be:
53    /// - Absolute path: "/folder/file.txt"
54    /// - Relative path: "folder/file.txt"
55    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
56    pub uri: &'a str,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub user_explicit: Option<serde_json::Value>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub group_explicit: Option<serde_json::Value>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub same_group: Option<&'a str>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub other: Option<&'a str>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub anonymous: Option<&'a str>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub everyone: Option<&'a str>,
69}
70
71/// Create upload session request
72#[derive(Debug, Serialize)]
73pub struct CreateUploadSessionRequest<'a> {
74    /// Target file path (will be converted to URI format internally)
75    ///
76    /// Can be:
77    /// - Absolute path: "/folder/file.txt"
78    /// - Relative path: "folder/file.txt"
79    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
80    pub uri: &'a str,
81    /// Size of the file in bytes
82    pub size: u64,
83    /// ID of the storage policy to use
84    pub policy_id: &'a str,
85    /// Optional Unix milliseconds timestamp of when the file is last modified
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub last_modified: Option<u64>,
88    /// Optional mime type of the file
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub mime_type: Option<&'a str>,
91    /// Optional key-value of file metadata
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub metadata: Option<std::collections::HashMap<String, String>>,
94    /// Optional blob type. "version" overwrites existing files.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub entity_type: Option<&'a str>,
97}
98
99/// Delete upload session request
100#[derive(Debug, Serialize)]
101pub struct DeleteUploadSessionRequest<'a> {
102    /// ID of the upload session
103    pub id: &'a str,
104    /// Target file path (will be converted to URI format internally)
105    ///
106    /// Can be:
107    /// - Absolute path: "/folder/file.txt"
108    /// - Relative path: "folder/file.txt"
109    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
110    pub uri: &'a str,
111}
112
113/// Move/copy file request
114#[derive(Debug, Serialize)]
115pub struct MoveCopyFileRequest<'a> {
116    pub from: Vec<&'a str>,
117    pub to: &'a str,
118    #[serde(skip_serializing_if = "Option::is_none")]
119    pub copy: Option<bool>,
120}
121
122/// Update file content request
123#[derive(Debug, Serialize)]
124pub struct UpdateFileContentRequest<'a> {
125    /// File path (will be converted to URI format internally)
126    ///
127    /// Can be:
128    /// - Absolute path: "/folder/file.txt"
129    /// - Relative path: "folder/file.txt"
130    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
131    pub uri: &'a str,
132    pub content: &'a str,
133}
134
135/// Create viewer session request
136#[derive(Debug, Serialize)]
137pub struct CreateViewerSessionRequest<'a> {
138    /// File path (will be converted to URI format internally)
139    ///
140    /// Can be:
141    /// - Absolute path: "/folder/file.txt"
142    /// - Relative path: "folder/file.txt"
143    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
144    pub uri: &'a str,
145}
146
147/// Create file request
148#[derive(Debug, Serialize)]
149pub struct CreateFileRequest<'a> {
150    pub path: &'a str,
151    pub name: &'a str,
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub content: Option<&'a str>,
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub overwrite: Option<bool>,
156}
157
158/// Rename multiple request
159#[derive(Debug, Serialize)]
160pub struct RenameMultipleRequest<'a> {
161    pub uris: Vec<&'a str>,
162    pub names: Vec<&'a str>,
163}
164
165/// Create download URL request
166#[derive(Debug, Serialize)]
167pub struct CreateDownloadUrlRequest<'a> {
168    /// List of file paths (will be converted to URI format internally)
169    ///
170    /// Each path can be:
171    /// - Absolute path: "/folder/file.txt"
172    /// - Relative path: "folder/file.txt"
173    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
174    pub uris: Vec<&'a str>,
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub download: Option<bool>,
177    #[serde(skip_serializing_if = "Option::is_none")]
178    pub redirect: Option<bool>,
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub entity: Option<&'a str>,
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub use_primary_site_url: Option<bool>,
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub skip_error: Option<bool>,
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub archive: Option<bool>,
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub no_cache: Option<bool>,
189}
190
191/// Restore file request
192#[derive(Debug, Serialize)]
193pub struct RestoreFileRequest<'a> {
194    /// List of file paths to restore (will be converted to URI format internally)
195    ///
196    /// Each path can be:
197    /// - Absolute path: "/folder/file.txt"
198    /// - Relative path: "folder/file.txt"
199    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
200    pub uris: Vec<&'a str>,
201}
202
203/// Update metadata request
204#[derive(Debug, Serialize)]
205pub struct UpdateMetadataRequest {
206    #[serde(skip_serializing_if = "Option::is_none")]
207    pub metadata: Option<serde_json::Value>,
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub clear_metadata: Option<bool>,
210}
211
212/// Mount storage policy request
213#[derive(Debug, Serialize)]
214pub struct MountStoragePolicyRequest {
215    pub policy_id: u64,
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub inherit_to_children: Option<bool>,
218}
219
220/// Update view request
221#[derive(Debug, Serialize)]
222pub struct UpdateViewRequest {
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub page_size: Option<i32>,
225    #[serde(skip_serializing_if = "Option::is_none")]
226    pub order: Option<String>,
227    #[serde(skip_serializing_if = "Option::is_none")]
228    pub order_direction: Option<String>,
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub view: Option<String>,
231    #[serde(skip_serializing_if = "Option::is_none")]
232    pub thumbnail: Option<bool>,
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub gallery_width: Option<i32>,
235}
236
237/// Get file info request
238#[derive(Debug, Serialize)]
239pub struct GetFileInfoRequest<'a> {
240    /// File path (will be converted to URI format internally)
241    ///
242    /// Can be:
243    /// - Absolute path: "/folder/file.txt"
244    /// - Relative path: "folder/file.txt"
245    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
246    pub uri: &'a str,
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub include_extended_info: Option<bool>,
249}
250
251/// Get archive list request
252#[derive(Debug, Serialize)]
253pub struct GetArchiveListRequest<'a> {
254    /// File path (will be converted to URI format internally)
255    ///
256    /// Can be:
257    /// - Absolute path: "/folder/file.txt"
258    /// - Relative path: "folder/file.txt"
259    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
260    pub uri: &'a str,
261}
262
263/// Relocate request
264#[derive(Debug, Serialize)]
265pub struct RelocateRequest<'a> {
266    #[serde(rename = "src")]
267    pub src: Vec<&'a str>,
268    #[serde(rename = "dst_policy_id")]
269    pub dst_policy_id: &'a str,
270}
271
272/// Import request
273#[derive(Debug, Serialize)]
274pub struct ImportRequest<'a> {
275    #[serde(rename = "src")]
276    pub src: &'a str,
277    #[serde(rename = "dst")]
278    pub dst: &'a str,
279    #[serde(rename = "user_id")]
280    pub user_id: &'a str,
281    #[serde(rename = "policy_id")]
282    pub policy_id: i32,
283    #[serde(rename = "extract_media_meta")]
284    pub extract_media_meta: Option<bool>,
285    #[serde(rename = "recursive")]
286    pub recursive: Option<bool>,
287}
288
289/// Select download files request
290#[derive(Debug, Serialize)]
291pub struct SelectDownloadFilesRequest<'a> {
292    pub selected_files: Vec<&'a str>,
293}
294
295/// Delete file request
296#[derive(Debug, Serialize)]
297pub struct DeleteFileRequest<'a> {
298    /// List of file paths to delete (will be converted to URI format internally)
299    ///
300    /// Each path can be:
301    /// - Absolute path: "/folder/file.txt"
302    /// - Relative path: "folder/file.txt"
303    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
304    pub uris: Vec<&'a str>,
305    #[serde(skip_serializing_if = "Option::is_none")]
306    pub unlink: Option<bool>,
307    #[serde(skip_serializing_if = "Option::is_none")]
308    pub skip_soft_delete: Option<bool>,
309}
310
311/// Create download request (alias for remote download)
312#[derive(Debug, Serialize)]
313pub struct CreateDownloadRequest<'a> {
314    #[serde(rename = "dst")]
315    pub dst: &'a str,
316    #[serde(rename = "src")]
317    pub src: Vec<&'a str>,
318    #[serde(rename = "preferred_node_id")]
319    pub preferred_node_id: Option<String>,
320}