cloudreve_api/api/v4/models/
file.rs

1//! File-related models for Cloudreve API v4
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// File or folder metadata
7#[derive(Debug, Serialize, Deserialize, Clone)]
8pub struct File {
9    #[serde(rename = "type")]
10    pub r#type: FileType,
11    pub id: String,
12    pub name: String,
13    #[serde(default)]
14    pub permission: Option<String>,
15    pub created_at: String,
16    pub updated_at: String,
17    pub size: i64,
18    #[serde(default)]
19    pub metadata: Option<Value>,
20    pub path: String,
21    #[serde(default)]
22    pub capability: Option<String>,
23    pub owned: bool,
24    #[serde(default)]
25    pub primary_entity: Option<String>,
26}
27
28/// File type enum
29#[derive(Debug, Serialize, Clone, PartialEq)]
30pub enum FileType {
31    File = 0,
32    Folder = 1,
33}
34
35impl<'de> Deserialize<'de> for FileType {
36    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
37    where
38        D: serde::Deserializer<'de>,
39    {
40        let value = i32::deserialize(deserializer)?;
41        match value {
42            0 => Ok(FileType::File),
43            1 => Ok(FileType::Folder),
44            _ => Err(serde::de::Error::custom(format!("Invalid FileType value: {}", value))),
45        }
46    }
47}
48
49/// File statistics
50#[derive(Debug, Serialize, Deserialize)]
51pub struct FileStat {
52    pub size: u64,
53    pub created_at: String,
54    pub updated_at: String,
55    pub mime_type: String,
56}
57
58/// Directory list response
59#[derive(Debug, Serialize, Deserialize, Clone)]
60pub struct ListResponse {
61    pub files: Vec<File>,
62    pub parent: File,
63    pub pagination: PaginationResults,
64    pub props: NavigatorProps,
65    pub context_hint: String,
66    pub mixed_type: bool,
67    #[serde(default)]
68    pub storage_policy: Option<super::storage::StoragePolicy>,
69    pub view: Option<ExplorerView>,
70}
71
72/// Pagination metadata
73#[derive(Debug, Serialize, Deserialize, Clone)]
74pub struct PaginationResults {
75    pub page: i32,
76    pub page_size: i32,
77    pub total_items: Option<i64>,
78    pub next_token: Option<String>,
79    pub is_cursor: bool,
80}
81
82/// Navigator capabilities
83#[derive(Debug, Serialize, Deserialize, Clone)]
84pub struct NavigatorProps {
85    pub capability: String,
86    pub max_page_size: i32,
87    pub order_by_options: Vec<String>,
88    pub order_direction_options: Vec<String>,
89}
90
91/// Explorer view settings
92#[derive(Debug, Serialize, Deserialize, Clone)]
93pub struct ExplorerView {
94    pub page_size: Option<i32>,
95    pub order: Option<String>,
96    pub order_direction: Option<OrderDirection>,
97    pub view: Option<ExplorerViewMode>,
98    pub thumbnail: Option<bool>,
99    pub gallery_width: Option<i32>,
100    pub columns: Option<Vec<ListViewColumn>>,
101}
102
103/// Sort direction enum
104#[derive(Debug, Serialize, Deserialize, Clone)]
105pub enum OrderDirection {
106    #[serde(rename = "asc")]
107    Asc,
108    #[serde(rename = "desc")]
109    Desc,
110}
111
112/// View mode enum
113#[derive(Debug, Serialize, Deserialize, Clone)]
114pub enum ExplorerViewMode {
115    #[serde(rename = "list")]
116    List,
117    #[serde(rename = "grid")]
118    Grid,
119    #[serde(rename = "gallery")]
120    Gallery,
121}
122
123/// List view column configuration
124#[derive(Debug, Serialize, Deserialize, Clone)]
125pub struct ListViewColumn {
126    pub r#type: i32,
127    pub width: Option<i32>,
128    pub props: Option<ColumnProps>,
129}
130
131/// Column properties
132#[derive(Debug, Serialize, Deserialize, Clone)]
133pub struct ColumnProps {
134    pub metadata_key: Option<String>,
135}
136
137/// Extended file information
138#[derive(Debug, Serialize, Deserialize, Clone)]
139pub struct ExtendedInfo {
140    #[serde(default)]
141    pub storage_policy: Option<super::storage::NewStoragePolicy>,
142    pub storage_policy_inherited: bool,
143    pub storage_used: i64,
144    #[serde(default)]
145    pub shares: Option<Vec<super::share::ShareLink>>,
146    #[serde(default)]
147    pub entities: Option<Vec<super::storage::NewEntity>>,
148    pub permissions: Option<PermissionSetting>,
149    #[serde(default)]
150    pub direct_links: Option<Vec<super::storage::DirectLink>>,
151}
152
153/// Folder summary
154#[derive(Debug, Serialize, Deserialize, Clone)]
155pub struct FolderSummary {
156    pub size: i64,
157    pub files: i64,
158    pub folders: i64,
159    pub completed: bool,
160    pub calculated_at: String,
161}
162
163/// Permission settings
164#[derive(Debug, Serialize, Deserialize, Clone)]
165pub struct PermissionSetting {
166    #[serde(rename = "user_explicit")]
167    pub user_explicit: Value,
168    #[serde(rename = "group_explicit")]
169    pub group_explicit: Value,
170    #[serde(rename = "same_group")]
171    pub same_group: String,
172    #[serde(rename = "other")]
173    pub other: String,
174    #[serde(rename = "anonymous")]
175    pub anonymous: String,
176    #[serde(rename = "everyone")]
177    pub everyone: String,
178}