drive_v3/objects/
file.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4use super::{ContentHints, User, Permission, FileCapabilities, ImageMediaMetadata,
5    VideoMediaMetadata, ShortcutDetails, ContentRestriction, LabelInfo};
6
7/// Contains details about the link URLs that clients are using to refer to this item.
8#[derive(Default, Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct LinkShareMetadata {
11    /// Whether the file is eligible for security update.
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub security_update_eligible: Option<bool>,
14
15    /// Whether the security update is enabled for this file.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub security_update_enabled: Option<bool>,
18}
19
20impl fmt::Display for LinkShareMetadata {
21    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
22        let json = serde_json::to_string_pretty(&self)
23            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
24
25        write!(f, "{}", json)
26    }
27}
28
29#[doc(hidden)]
30impl From<&Self> for LinkShareMetadata {
31    fn from( reference: &Self ) -> Self {
32        reference.clone()
33    }
34}
35
36impl LinkShareMetadata {
37    /// Creates a new, empty instance of this struct.
38    pub fn new() -> Self {
39        Self { ..Default::default() }
40    }
41}
42
43/// List of the user's files.
44///
45/// # Note
46///
47/// All of the fields of [`FileList`] are an [`Option<T>`] since the values that
48/// Google's API will return are dependent on the
49/// [`fields`](crate::resources::files::ListRequest::fields) requested, by
50/// default all fields will be requested but if you change this value only the
51/// specified fields will be [`Some<T>`], the rest will be [`None`].
52#[derive(Default, Debug, Clone, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54pub struct FileList {
55    /// The page token for the next page of files.
56    ///
57    /// This will be absent if the end of the files list has been reached. If the token is rejected for any reason, it should be
58    /// discarded, and pagination should be restarted from the first page of results. The page token is typically valid for
59    /// several hours. However, if new items are added or removed, your expected results might differ.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub next_page_token: Option<String>,
62
63    /// Identifies what kind of resource this is. Value: the fixed string "drive#fileList".
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub kind: Option<String>,
66
67    /// Whether the search process was incomplete.
68    ///
69    /// If `true`, then some search results might be missing, since all documents were not searched. This can occur when
70    /// searching multiple drives with the `allDrives` corpora, but all corpora couldn't be searched. When this happens, it's
71    /// suggested that clients narrow their query by choosing a different corpus such as `user` or `drive`.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub incomplete_search: Option<bool>,
74
75    /// The list of files.
76    ///
77    /// If [`next_page_token`](FileList::next_page_token) is populated, then this list may be incomplete and an additional page
78    /// of results should be fetched.
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub files: Option<Vec<File>>,
81}
82
83impl fmt::Display for FileList {
84    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
85        let json = serde_json::to_string_pretty(&self)
86            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
87
88        write!(f, "{}", json)
89    }
90}
91
92#[doc(hidden)]
93impl From<&Self> for FileList {
94    fn from( reference: &Self ) -> Self {
95        reference.clone()
96    }
97}
98
99impl FileList {
100    /// Creates a new, empty instance of this struct.
101    pub fn new() -> Self {
102        Self { ..Default::default() }
103    }
104}
105
106/// The metadata for a file.
107///
108/// Some resource methods (such as files.update) require a `fileId`. Use the `files.list` method to retrieve the ID for a file.
109///
110/// See Google's [documentation](https://developers.google.com/drive/api/reference/rest/v3/files) for a full list and more
111/// detailed information.
112///
113/// # Warning
114///
115/// Fields like `teamDriveId` are not included in this struct, since they are marked as deprecated
116/// in Google's [documentation](https://developers.google.com/drive/api/reference/rest/v3/about).
117///
118/// # Note
119///
120/// All of the fields of [`File`] are an [`Option<T>`] since the values that
121/// Google's API will return are dependent on the
122/// [`fields`](crate::resources::files::GetRequest::fields) requested, by
123/// default all fields will be requested but if you change this value only the
124/// specified fields will be [`Some<T>`], the rest will be [`None`].
125#[derive(Default, Debug, Clone, Serialize, Deserialize)]
126#[serde(rename_all = "camelCase")]
127pub struct File {
128    /// Identifies what kind of resource this is.
129    ///
130    /// Value: the fixed string "drive#file".
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub kind: Option<String>,
133
134    /// ID of the shared drive the file resides in.
135    ///
136    /// Only populated for items in shared drives.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub drive_id: Option<String>,
139
140    /// The final component of fullFileExtension.
141    ///
142    /// This is only available for files with binary content in Google Drive.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub file_extension: Option<String>,
145
146    /// Whether the options to copy, print, or download this file, should be disabled for readers and commenters.
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub copy_requires_writer_permission: Option<bool>,
149
150    /// The MD5 checksum for the content of the file.
151    ///
152    /// This is only applicable to files with binary content in Google Drive.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub md5_checksum: Option<String>,
155
156    /// Additional information about the content of the file.
157    ///
158    /// These fields are never populated in responses.
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub content_hints: Option<ContentHints>,
161
162    /// Whether users with only writer permission can modify the file's permissions.
163    ///
164    /// Not populated for items in shared drives.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub writers_can_share: Option<bool>,
167
168    /// Whether the file has been viewed by this user.
169    #[serde(skip_serializing_if = "Option::is_none")]
170    pub viewed_by_me: Option<bool>,
171
172    /// The MIME type of the file.
173    ///
174    /// Google Drive attempts to automatically detect an appropriate value from uploaded content, if no value is provided. The
175    /// value cannot be changed unless a new revision is uploaded.
176    ///
177    /// If a file is created with a Google Doc MIME type, the uploaded content is imported, if possible. The supported import
178    /// formats are published in the About resource.
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub mime_type: Option<String>,
181
182    /// Links for exporting Docs Editors files to specific formats.
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub export_links: Option<serde_json::Map<String, serde_json::Value>>,
185
186    /// The IDs of the parent folders which contain the file.
187    ///
188    /// If not specified as part of a create request, a `file` is placed directly in the user's My Drive folder. If not specified
189    /// as part of a copy request, a `file` inherits any discoverable parents of the source file. `files.update` requests must
190    /// use the `addParents` and `removeParents` parameters to modify the parents list.
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub parents: Option<Vec<String>>,
193
194    /// A short-lived link to the file's thumbnail, if available.
195    ///
196    /// Typically lasts on the order of hours. Only populated when the requesting app can access the file's content. If the file
197    /// isn't shared publicly, the URL returned in Files.thumbnailLink must be fetched using a credentialed request.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub thumbnail_link: Option<String>,
200
201    /// A static, unauthenticated link to the file's icon.
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub icon_link: Option<String>,
204
205    /// Whether the file has been shared.
206    ///
207    /// Not populated for items in shared drives.
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub shared: Option<bool>,
210
211    /// The last user to modify the file.
212    #[serde(skip_serializing_if = "Option::is_none")]
213    pub last_modifying_user: Option<User>,
214
215    /// The owner of this file.
216    ///
217    /// Only certain legacy files may have more than one owner. This field isn't populated for items in shared drives.
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub owners: Option<Vec<User>>,
220
221    /// The ID of the file's head revision.
222    ///
223    /// This is currently only available for files with binary content in Google Drive.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub head_revision_id: Option<String>,
226
227    /// The user who shared the file with the requesting user, if applicable.
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub sharing_user: Option<User>,
230
231    /// A link for opening the file in a relevant Google editor or viewer in a browser.
232    #[serde(skip_serializing_if = "Option::is_none")]
233    pub web_view_link: Option<String>,
234
235    /// A link for downloading the content of the file in a browser.
236    ///
237    /// This is only available for files with binary content in Google Drive.
238    #[serde(skip_serializing_if = "Option::is_none")]
239    pub web_content_link: Option<String>,
240
241    /// Size in bytes of blobs and first party editor files.
242    ///
243    /// Won't be populated for files that have no size, like `shortcuts` and `folders`.
244    #[serde(skip_serializing_if = "Option::is_none")]
245    pub size: Option<String>,
246
247    /// The full list of permissions for the file.
248    ///
249    /// This is only available if the requesting user can share the file. Not populated for items in shared drives.
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub permissions: Option<Vec<Permission>>,
252
253    /// Whether this file has a thumbnail.
254    ///
255    /// This does not indicate whether the requesting app has access to the thumbnail. To check access, look for the presence of
256    /// the [`thumbnail_link`](File::thumbnail_link) field.
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub has_thumbnail: Option<bool>,
259
260    /// The list of spaces which contain the file.
261    ///
262    /// The currently supported values are `drive`, `appDataFolder` and `photos`.
263    #[serde(skip_serializing_if = "Option::is_none")]
264    pub spaces: Option<Vec<String>>,
265
266    /// The color for a folder or a shortcut to a folder as an RGB hex string.
267    ///
268    /// The supported colors are published in the [`folder_color_palette`](super::About::folder_color_palette) field of the
269    /// [`About`](super::About) resource.
270    #[serde(skip_serializing_if = "Option::is_none")]
271    pub folder_color_rgb: Option<String>,
272
273    /// The ID of the file.
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub id: Option<String>,
276
277    /// The name of the file.
278    ///
279    /// This is not necessarily unique within a folder. Note that for immutable items such as the top level folders of shared
280    /// drives, My Drive root folder, and Application Data folder the name is constant.
281    #[serde(skip_serializing_if = "Option::is_none")]
282    pub name: Option<String>,
283
284    /// A short description of the file.
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub description: Option<String>,
287
288    /// Whether the user has starred the file.
289    #[serde(skip_serializing_if = "Option::is_none")]
290    pub starred: Option<bool>,
291
292    /// Whether the file has been trashed, either explicitly or from a trashed parent folder.
293    ///
294    /// Only the owner may trash a file, and other users cannot see files in the owner's trash.
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub trashed: Option<bool>,
297
298    /// Whether the file has been explicitly trashed, as opposed to recursively trashed from a parent folder.
299    #[serde(skip_serializing_if = "Option::is_none")]
300    pub explicitly_trashed: Option<bool>,
301
302    /// The time at which the file was created (RFC 3339 date-time).
303    #[serde(skip_serializing_if = "Option::is_none")]
304    pub created_time: Option<String>,
305
306    /// The last time the file was modified by anyone (RFC 3339 date-time).
307    ///
308    /// Note that setting `modified_time` also updates `modified_by_me_time` for the user.
309    #[serde(skip_serializing_if = "Option::is_none")]
310    pub modified_time: Option<String>,
311
312    /// The last time the file was modified by the user (RFC 3339 date-time).
313    #[serde(skip_serializing_if = "Option::is_none")]
314    pub modified_by_me_time: Option<String>,
315
316    /// The last time the file was viewed by the user (RFC 3339 date-time).
317    #[serde(skip_serializing_if = "Option::is_none")]
318    pub viewed_by_me_time: Option<String>,
319
320    /// The time at which the file was shared with the user, if applicable (RFC 3339 date-time).
321    #[serde(skip_serializing_if = "Option::is_none")]
322    pub shared_with_me_time: Option<String>,
323
324    /// The number of storage quota bytes used by the file. This includes the head revision as well as previous revisions with
325    /// `keepForever` enabled.
326    #[serde(skip_serializing_if = "Option::is_none")]
327    pub quota_bytes_used: Option<String>,
328
329    /// A monotonically increasing version number for the file. This reflects every change made to the file on the server, even
330    /// those not visible to the user.
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub version: Option<String>,
333
334    /// The original filename of the uploaded content if available, or else the original value of the
335    /// [`name`](File::name) field.
336    ///
337    /// This is only available for files with binary content in Google Drive.
338    #[serde(skip_serializing_if = "Option::is_none")]
339    pub original_filename: Option<String>,
340
341    /// Whether the user owns the file. Not populated for items in shared drives.
342    #[serde(skip_serializing_if = "Option::is_none")]
343    pub owned_by_me: Option<bool>,
344
345    /// The full file extension extracted from the [`name`](File::name) field.
346    ///
347    /// May contain multiple concatenated extensions, such as "`tar.gz`". This is only available for files with binary content in
348    /// Google Drive.
349    ///
350    /// This is automatically updated when the [`name`](File::name) field changes, however it is not cleared if the new
351    /// [`name`](File::name) does not contain a valid extension.
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub full_file_extension: Option<String>,
354
355    /// A collection of arbitrary key-value pairs which are visible to all apps.
356    ///
357    /// Entries with null values are cleared in update and copy requests.
358    #[serde(skip_serializing_if = "Option::is_none")]
359    pub properties: Option<serde_json::Map<String, serde_json::Value>>,
360
361    /// A collection of arbitrary key-value pairs which are private to the requesting app.
362    ///
363    /// Entries with null values are cleared in update and copy requests.
364    ///
365    /// These properties can only be retrieved using an authenticated request. An authenticated request uses an access token
366    /// obtained with an OAuth 2 client ID. You cannot use an API key to retrieve private properties.
367    #[serde(skip_serializing_if = "Option::is_none")]
368    pub app_properties: Option<serde_json::Map<String, serde_json::Value>>,
369
370    /// Whether the file was created or opened by the requesting app.
371    #[serde(skip_serializing_if = "Option::is_none")]
372    pub is_app_authorized: Option<bool>,
373
374    /// Capabilities the current user has on this file.
375    ///
376    /// Each capability corresponds to a fine-grained action that a user may take.
377    #[serde(skip_serializing_if = "Option::is_none")]
378    pub capabilities: Option<FileCapabilities>,
379
380    /// Whether there are permissions directly on this file.
381    ///
382    /// This field is only populated for items in shared drives.
383    #[serde(skip_serializing_if = "Option::is_none")]
384    pub has_augmented_permissions: Option<bool>,
385
386    /// If the file has been explicitly trashed, the user who trashed it.
387    ///
388    /// Only populated for items in shared drives.
389    #[serde(skip_serializing_if = "Option::is_none")]
390    pub trashing_user: Option<User>,
391
392    /// The thumbnail version for use in thumbnail cache invalidation.
393    #[serde(skip_serializing_if = "Option::is_none")]
394    pub thumbnail_version: Option<String>,
395
396    /// The time that the item was trashed (RFC 3339 date-time).
397    ///
398    /// Only populated for items in shared drives.
399    #[serde(skip_serializing_if = "Option::is_none")]
400    pub trashed_time: Option<String>,
401
402    /// Whether the file has been modified by this user.
403    #[serde(skip_serializing_if = "Option::is_none")]
404    pub modified_by_me: Option<bool>,
405
406    /// files.list of permission IDs for users with access to this file.
407    #[serde(skip_serializing_if = "Option::is_none")]
408    pub permission_ids: Option<Vec<String>>,
409
410    /// Additional metadata about image media, if available.
411    #[serde(skip_serializing_if = "Option::is_none")]
412    pub image_media_metadata: Option<ImageMediaMetadata>,
413
414    /// Additional metadata about video media.
415    ///
416    /// This may not be available immediately upon upload.
417    #[serde(skip_serializing_if = "Option::is_none")]
418    pub video_media_metadata: Option<VideoMediaMetadata>,
419
420    /// Shortcut file details.
421    ///
422    /// Only populated for shortcut files, which have the [`mime_type`](File::mime_type) field set to
423    /// `application/vnd.google-apps.shortcut`.
424    #[serde(skip_serializing_if = "Option::is_none")]
425    pub shortcut_details: Option<ShortcutDetails>,
426
427    /// Restrictions for accessing the content of the file.
428    ///
429    /// Only populated if such a restriction exists.
430    #[serde(skip_serializing_if = "Option::is_none")]
431    pub content_restrictions: Option<Vec<ContentRestriction>>,
432
433    /// A key needed to access the item via a shared link.
434    #[serde(skip_serializing_if = "Option::is_none")]
435    pub resource_key: Option<String>,
436
437    /// Contains details about the link URLs that clients are using to refer to this item.
438    #[serde(skip_serializing_if = "Option::is_none")]
439    pub link_share_metadata: Option<LinkShareMetadata>,
440
441    /// An overview of the labels on the file.
442    #[serde(skip_serializing_if = "Option::is_none")]
443    pub label_info: Option<LabelInfo>,
444
445    /// The SHA1 checksum associated with this file, if available.
446    ///
447    /// This field is only populated for files with content stored in Google Drive; it is not populated for Docs Editors or
448    /// shortcut files.
449    #[serde(skip_serializing_if = "Option::is_none")]
450    pub sha1_checksum: Option<String>,
451
452    /// The SHA256 checksum associated with this file, if available.
453    ///
454    /// This field is only populated for files with content stored in Google Drive; it is not populated for Docs Editors or
455    /// shortcut files.
456    #[serde(skip_serializing_if = "Option::is_none")]
457    pub sha256_checksum: Option<String>,
458}
459
460impl fmt::Display for File {
461    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
462        let json = serde_json::to_string_pretty(&self)
463            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
464
465        write!(f, "{}", json)
466    }
467}
468
469#[doc(hidden)]
470impl From<&Self> for File {
471    fn from( reference: &Self ) -> Self {
472        reference.clone()
473    }
474}
475
476impl File {
477    /// Creates a new, empty instance of this struct.
478    pub fn new() -> Self {
479        Self { ..Default::default() }
480    }
481}