lib_client_google_drive/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// File in Google Drive.
4#[derive(Debug, Clone, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct File {
7    pub id: String,
8    pub name: String,
9    pub mime_type: String,
10    #[serde(default)]
11    pub parents: Vec<String>,
12    pub created_time: Option<String>,
13    pub modified_time: Option<String>,
14    pub size: Option<String>,
15    pub web_view_link: Option<String>,
16    pub web_content_link: Option<String>,
17    pub trashed: Option<bool>,
18    pub shared: Option<bool>,
19}
20
21/// File list response.
22#[derive(Debug, Clone, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct FileList {
25    pub files: Vec<File>,
26    pub next_page_token: Option<String>,
27    pub incomplete_search: Option<bool>,
28}
29
30/// File metadata for create/update.
31#[derive(Debug, Clone, Default, Serialize)]
32#[serde(rename_all = "camelCase")]
33pub struct FileMetadata {
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub name: Option<String>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub mime_type: Option<String>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub parents: Option<Vec<String>>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub description: Option<String>,
42}
43
44impl FileMetadata {
45    pub fn new(name: impl Into<String>) -> Self {
46        Self {
47            name: Some(name.into()),
48            ..Default::default()
49        }
50    }
51
52    pub fn mime_type(mut self, mime: impl Into<String>) -> Self {
53        self.mime_type = Some(mime.into());
54        self
55    }
56
57    pub fn parent(mut self, parent_id: impl Into<String>) -> Self {
58        self.parents = Some(vec![parent_id.into()]);
59        self
60    }
61
62    pub fn folder(name: impl Into<String>) -> Self {
63        Self::new(name).mime_type("application/vnd.google-apps.folder")
64    }
65}
66
67/// Permission.
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub struct Permission {
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub id: Option<String>,
73    #[serde(rename = "type")]
74    pub permission_type: String,
75    pub role: String,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub email_address: Option<String>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub domain: Option<String>,
80}
81
82impl Permission {
83    pub fn user(email: impl Into<String>, role: PermissionRole) -> Self {
84        Self {
85            id: None,
86            permission_type: "user".to_string(),
87            role: role.as_str().to_string(),
88            email_address: Some(email.into()),
89            domain: None,
90        }
91    }
92
93    pub fn anyone(role: PermissionRole) -> Self {
94        Self {
95            id: None,
96            permission_type: "anyone".to_string(),
97            role: role.as_str().to_string(),
98            email_address: None,
99            domain: None,
100        }
101    }
102
103    pub fn domain(domain: impl Into<String>, role: PermissionRole) -> Self {
104        Self {
105            id: None,
106            permission_type: "domain".to_string(),
107            role: role.as_str().to_string(),
108            email_address: None,
109            domain: Some(domain.into()),
110        }
111    }
112}
113
114/// Permission role.
115#[derive(Debug, Clone, Copy)]
116pub enum PermissionRole {
117    Owner,
118    Organizer,
119    FileOrganizer,
120    Writer,
121    Commenter,
122    Reader,
123}
124
125impl PermissionRole {
126    pub fn as_str(&self) -> &'static str {
127        match self {
128            Self::Owner => "owner",
129            Self::Organizer => "organizer",
130            Self::FileOrganizer => "fileOrganizer",
131            Self::Writer => "writer",
132            Self::Commenter => "commenter",
133            Self::Reader => "reader",
134        }
135    }
136}
137
138/// Permission list.
139#[derive(Debug, Clone, Deserialize)]
140pub struct PermissionList {
141    pub permissions: Vec<Permission>,
142}
143
144/// About info.
145#[derive(Debug, Clone, Deserialize)]
146#[serde(rename_all = "camelCase")]
147pub struct About {
148    pub user: User,
149    pub storage_quota: StorageQuota,
150}
151
152/// User info.
153#[derive(Debug, Clone, Deserialize)]
154#[serde(rename_all = "camelCase")]
155pub struct User {
156    pub display_name: String,
157    pub email_address: String,
158    pub photo_link: Option<String>,
159}
160
161/// Storage quota.
162#[derive(Debug, Clone, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct StorageQuota {
165    pub limit: Option<String>,
166    pub usage: String,
167    pub usage_in_drive: Option<String>,
168    pub usage_in_drive_trash: Option<String>,
169}