Skip to main content

nextcloud_users/capabilities/
files.rs

1use serde::{Deserialize, Serialize};
2
3use super::ChunkedUpload;
4use crate::wire::{lossy_bool, lossy_opt_u64};
5
6/// File-related capabilities advertised by the Files application.
7#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
8pub struct FilesCapabilities {
9    /// Whether the server supports chunked uploads for large files.
10    #[serde(
11        default,
12        alias = "bigfilechunking",
13        alias = "big_file_chunking",
14        deserialize_with = "lossy_bool"
15    )]
16    pub big_file_chunking: bool,
17    /// Whether soft deletion and trashbin restoration are available.
18    #[serde(default, deserialize_with = "lossy_bool")]
19    pub undelete: bool,
20    /// Whether file versioning history is supported.
21    #[serde(default, deserialize_with = "lossy_bool")]
22    pub versioning: bool,
23    /// Explicit chunked upload settings block, if present.
24    #[serde(default, alias = "chunked_upload", alias = "chunkedUpload")]
25    pub chunked_upload: Option<ChunkedUpload>,
26    /// Direct max chunk size advertisement in bytes, if present.
27    #[serde(
28        default,
29        alias = "max_chunk_size",
30        alias = "maxChunkSize",
31        deserialize_with = "lossy_opt_u64"
32    )]
33    pub max_chunk_size: Option<u64>,
34}
35
36impl FilesCapabilities {
37    /// Whether big file chunking is supported.
38    pub const fn big_file_chunking(&self) -> bool {
39        self.big_file_chunking
40    }
41
42    /// Whether trashbin / undelete functionality is enabled.
43    pub const fn undelete(&self) -> bool {
44        self.undelete
45    }
46
47    /// Whether file versioning is enabled.
48    pub const fn versioning(&self) -> bool {
49        self.versioning
50    }
51
52    /// Chunked upload configuration, if provided by the server.
53    pub fn chunked_upload(&self) -> Option<&ChunkedUpload> {
54        self.chunked_upload.as_ref()
55    }
56
57    /// Effective maximum upload chunk size in bytes, if advertised directly
58    /// or inside the [`ChunkedUpload`] block.
59    pub fn max_chunk_size(&self) -> Option<u64> {
60        self.max_chunk_size
61            .or_else(|| self.chunked_upload.as_ref().and_then(|c| c.max_size))
62    }
63}