Skip to main content

cloudreve_api/api/v4/models/
request.rs

1//! Request types for Cloudreve API v4
2
3use serde::Serialize;
4use std::collections::HashMap;
5
6/// Upload file request
7#[derive(Debug, Serialize)]
8pub struct UploadRequest<'a> {
9    pub path: &'a str,
10    pub name: Option<&'a str>,
11    pub overwrite: Option<bool>,
12}
13
14/// List files request
15#[derive(Debug, Serialize, Default)]
16pub struct ListFilesRequest<'a> {
17    pub path: &'a str,
18    pub page: Option<u32>,
19    pub page_size: Option<u32>,
20    pub order_by: Option<&'a str>,
21    pub order_direction: Option<&'a str>,
22    pub next_page_token: Option<&'a str>,
23}
24
25/// Search files request
26///
27/// Search runs through the same endpoint as listing; what turns it into a
28/// search is the URI's own query string, built by
29/// [`crate::api::v4::uri::search_uri`].
30#[derive(Debug, Serialize, Default)]
31pub struct SearchFilesRequest<'a> {
32    /// Folder to search under; empty or "/" covers the whole drive
33    pub path: &'a str,
34    /// Name fragment to look for
35    pub keyword: &'a str,
36    /// Match regardless of letter case
37    pub case_folding: bool,
38    pub page: Option<u32>,
39    pub page_size: Option<u32>,
40    pub next_page_token: Option<&'a str>,
41}
42
43/// Move file request (also used for copy with copy=true)
44#[derive(Debug, Serialize)]
45pub struct MoveFileRequest<'a> {
46    pub uris: Vec<&'a str>,
47    pub dst: &'a str,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub copy: Option<bool>,
50}
51
52/// Copy file request
53#[derive(Debug, Serialize)]
54pub struct CopyFileRequest<'a> {
55    pub uris: Vec<&'a str>,
56    pub dst: &'a str,
57}
58
59/// Rename file request
60#[derive(Debug, Serialize)]
61pub struct RenameFileRequest<'a> {
62    pub uri: &'a str,
63    pub new_name: &'a str,
64}
65
66/// Set file permission request
67#[derive(Debug, Serialize)]
68pub struct SetFilePermissionRequest<'a> {
69    /// File path (will be converted to URI format internally)
70    ///
71    /// Can be:
72    /// - Absolute path: "/folder/file.txt"
73    /// - Relative path: "folder/file.txt"
74    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
75    pub uri: &'a str,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub user_explicit: Option<serde_json::Value>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub group_explicit: Option<serde_json::Value>,
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub same_group: Option<&'a str>,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub other: Option<&'a str>,
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub anonymous: Option<&'a str>,
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub everyone: Option<&'a str>,
88}
89
90/// Create upload session request
91#[derive(Debug, Serialize)]
92pub struct CreateUploadSessionRequest<'a> {
93    /// Target file path (will be converted to URI format internally)
94    ///
95    /// Can be:
96    /// - Absolute path: "/folder/file.txt"
97    /// - Relative path: "folder/file.txt"
98    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
99    pub uri: &'a str,
100    /// Size of the file in bytes
101    pub size: u64,
102    /// ID of the storage policy to use
103    pub policy_id: &'a str,
104    /// Optional Unix milliseconds timestamp of when the file is last modified
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub last_modified: Option<u64>,
107    /// Optional mime type of the file
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub mime_type: Option<&'a str>,
110    /// Optional key-value of file metadata
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub metadata: Option<std::collections::HashMap<String, String>>,
113    /// Optional blob type. "version" overwrites existing files.
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub entity_type: Option<&'a str>,
116}
117
118/// Delete upload session request
119#[derive(Debug, Serialize)]
120pub struct DeleteUploadSessionRequest<'a> {
121    /// ID of the upload session
122    pub id: &'a str,
123    /// Target file path (will be converted to URI format internally)
124    ///
125    /// Can be:
126    /// - Absolute path: "/folder/file.txt"
127    /// - Relative path: "folder/file.txt"
128    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
129    pub uri: &'a str,
130}
131
132/// Move/copy file request
133#[derive(Debug, Serialize)]
134pub struct MoveCopyFileRequest<'a> {
135    pub from: Vec<&'a str>,
136    pub to: &'a str,
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub copy: Option<bool>,
139}
140
141/// Update file content request
142#[derive(Debug, Serialize)]
143pub struct UpdateFileContentRequest<'a> {
144    /// File path (will be converted to URI format internally)
145    ///
146    /// Can be:
147    /// - Absolute path: "/folder/file.txt"
148    /// - Relative path: "folder/file.txt"
149    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
150    pub uri: &'a str,
151    pub content: &'a str,
152}
153
154/// Create viewer session request
155#[derive(Debug, Serialize)]
156pub struct CreateViewerSessionRequest<'a> {
157    /// File path (will be converted to URI format internally)
158    ///
159    /// Can be:
160    /// - Absolute path: "/folder/file.txt"
161    /// - Relative path: "folder/file.txt"
162    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
163    pub uri: &'a str,
164}
165
166/// What a [`CreateFileRequest`] creates
167#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
168#[serde(rename_all = "lowercase")]
169pub enum CreateFileType {
170    File,
171    Folder,
172}
173
174/// Create file or folder request
175#[derive(Debug, Clone, Serialize)]
176pub struct CreateFileRequest<'a> {
177    /// Path or URI of the item to create (converted to URI format internally)
178    pub uri: &'a str,
179    /// Whether to create a file or a folder
180    pub r#type: CreateFileType,
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub metadata: Option<HashMap<String, String>>,
183    /// Fail on a name clash instead of returning the existing item
184    #[serde(skip_serializing_if = "Option::is_none")]
185    pub err_on_conflict: Option<bool>,
186}
187
188/// Rename multiple request
189#[derive(Debug, Serialize)]
190pub struct RenameMultipleRequest<'a> {
191    pub uris: Vec<&'a str>,
192    pub names: Vec<&'a str>,
193}
194
195/// Create download URL request
196#[derive(Debug, Serialize)]
197pub struct CreateDownloadUrlRequest<'a> {
198    /// List of file paths (will be converted to URI format internally)
199    ///
200    /// Each path can be:
201    /// - Absolute path: "/folder/file.txt"
202    /// - Relative path: "folder/file.txt"
203    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
204    pub uris: Vec<&'a str>,
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub download: Option<bool>,
207    #[serde(skip_serializing_if = "Option::is_none")]
208    pub redirect: Option<bool>,
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub entity: Option<&'a str>,
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub use_primary_site_url: Option<bool>,
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub skip_error: Option<bool>,
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub archive: Option<bool>,
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub no_cache: Option<bool>,
219}
220
221/// Restore file request
222#[derive(Debug, Serialize)]
223pub struct RestoreFileRequest<'a> {
224    /// List of file paths to restore (will be converted to URI format internally)
225    ///
226    /// Each path can be:
227    /// - Absolute path: "/folder/file.txt"
228    /// - Relative path: "folder/file.txt"
229    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
230    pub uris: Vec<&'a str>,
231}
232
233/// Update metadata request
234#[derive(Debug, Serialize)]
235pub struct UpdateMetadataRequest {
236    #[serde(skip_serializing_if = "Option::is_none")]
237    pub metadata: Option<serde_json::Value>,
238    #[serde(skip_serializing_if = "Option::is_none")]
239    pub clear_metadata: Option<bool>,
240}
241
242/// Mount storage policy request
243#[derive(Debug, Serialize)]
244pub struct MountStoragePolicyRequest {
245    pub policy_id: u64,
246    #[serde(skip_serializing_if = "Option::is_none")]
247    pub inherit_to_children: Option<bool>,
248}
249
250/// Update view request
251#[derive(Debug, Serialize)]
252pub struct UpdateViewRequest {
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub page_size: Option<i32>,
255    #[serde(skip_serializing_if = "Option::is_none")]
256    pub order: Option<String>,
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub order_direction: Option<String>,
259    #[serde(skip_serializing_if = "Option::is_none")]
260    pub view: Option<String>,
261    #[serde(skip_serializing_if = "Option::is_none")]
262    pub thumbnail: Option<bool>,
263    #[serde(skip_serializing_if = "Option::is_none")]
264    pub gallery_width: Option<i32>,
265}
266
267/// Get file info request
268#[derive(Debug, Serialize)]
269pub struct GetFileInfoRequest<'a> {
270    /// File path (will be converted to URI format internally)
271    ///
272    /// Can be:
273    /// - Absolute path: "/folder/file.txt"
274    /// - Relative path: "folder/file.txt"
275    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
276    pub uri: &'a str,
277    #[serde(skip_serializing_if = "Option::is_none")]
278    pub include_extended_info: Option<bool>,
279}
280
281/// Get archive list request
282#[derive(Debug, Serialize)]
283pub struct GetArchiveListRequest<'a> {
284    /// File path (will be converted to URI format internally)
285    ///
286    /// Can be:
287    /// - Absolute path: "/folder/file.txt"
288    /// - Relative path: "folder/file.txt"
289    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
290    pub uri: &'a str,
291}
292
293/// Relocate request
294#[derive(Debug, Serialize)]
295pub struct RelocateRequest<'a> {
296    #[serde(rename = "src")]
297    pub src: Vec<&'a str>,
298    #[serde(rename = "dst_policy_id")]
299    pub dst_policy_id: &'a str,
300}
301
302/// Import request
303#[derive(Debug, Serialize)]
304pub struct ImportRequest<'a> {
305    #[serde(rename = "src")]
306    pub src: &'a str,
307    #[serde(rename = "dst")]
308    pub dst: &'a str,
309    #[serde(rename = "user_id")]
310    pub user_id: &'a str,
311    #[serde(rename = "policy_id")]
312    pub policy_id: i32,
313    #[serde(rename = "extract_media_meta")]
314    pub extract_media_meta: Option<bool>,
315    #[serde(rename = "recursive")]
316    pub recursive: Option<bool>,
317}
318
319/// Select download files request
320#[derive(Debug, Serialize)]
321pub struct SelectDownloadFilesRequest<'a> {
322    pub selected_files: Vec<&'a str>,
323}
324
325/// Delete file request
326#[derive(Debug, Serialize)]
327pub struct DeleteFileRequest<'a> {
328    /// List of file paths to delete (will be converted to URI format internally)
329    ///
330    /// Each path can be:
331    /// - Absolute path: "/folder/file.txt"
332    /// - Relative path: "folder/file.txt"
333    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
334    pub uris: Vec<&'a str>,
335    #[serde(skip_serializing_if = "Option::is_none")]
336    pub unlink: Option<bool>,
337    #[serde(skip_serializing_if = "Option::is_none")]
338    pub skip_soft_delete: Option<bool>,
339}
340
341/// Force-unlock request
342///
343/// Unlocks by the tokens handed out in a 40073 lock-conflict response, which
344/// is how a client releases locks it did not create. Unlocking by path instead
345/// goes through `force_unlock`.
346#[derive(Debug, Serialize)]
347pub struct UnlockFilesRequest<'a> {
348    pub tokens: Vec<&'a str>,
349}
350
351/// Create download request (alias for remote download)
352#[derive(Debug, Serialize)]
353pub struct CreateDownloadRequest<'a> {
354    #[serde(rename = "dst")]
355    pub dst: &'a str,
356    #[serde(rename = "src")]
357    pub src: Vec<&'a str>,
358    #[serde(rename = "preferred_node_id")]
359    pub preferred_node_id: Option<String>,
360}
361
362/// Create direct link request
363#[derive(Debug, Serialize)]
364pub struct CreateDirectLinkRequest<'a> {
365    /// List of file paths (will be converted to URI format internally)
366    ///
367    /// Each path can be:
368    /// - Absolute path: "/folder/file.txt"
369    /// - Relative path: "folder/file.txt"
370    /// - Already formatted URI: "cloudreve://my/folder/file.txt"
371    pub uris: Vec<&'a str>,
372}