From e39f0ff1a85fe91eb5c5334232fa5cf7f44f04ce Mon Sep 17 00:00:00 2001 From: xiejiann Date: Fri, 10 May 2024 15:48:12 +0800 Subject: [PATCH] add drive_id in config --- core/src/services/gdrive/builder.rs | 9 +++++++++ core/src/services/gdrive/core.rs | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/core/src/services/gdrive/builder.rs b/core/src/services/gdrive/builder.rs index 5ee80ab4c644..23a243b1fdae 100644 --- a/core/src/services/gdrive/builder.rs +++ b/core/src/services/gdrive/builder.rs @@ -52,6 +52,8 @@ pub struct GdriveConfig { pub client_id: Option, /// Client secret for gdrive. pub client_secret: Option, + /// ID of shared drive to search. + pub drive_id: Option, } impl Debug for GdriveConfig { @@ -127,6 +129,12 @@ impl GdriveBuilder { self } + /// Set the drive id for GoogleDrive + pub fn drive_id(&mut self, drive_id: &str) -> &mut Self { + self.config.drive_id = Some(drive_id.to_string()); + self + } + /// Specify the http client that used by this service. /// /// # Notes @@ -219,6 +227,7 @@ impl Builder for GdriveBuilder { Ok(GdriveBackend { core: Arc::new(GdriveCore { root, + drive_id: self.config.drive_id.clone(), signer: signer.clone(), client: client.clone(), path_cache: PathCacher::new(GdrivePathQuery::new(client, signer)).with_lock(), diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs index 0b72e1c9db4f..f6a4c99e97c7 100644 --- a/core/src/services/gdrive/core.rs +++ b/core/src/services/gdrive/core.rs @@ -39,6 +39,8 @@ use crate::*; pub struct GdriveCore { pub root: String, + pub drive_id: Option, + pub client: HttpClient, pub signer: Arc>, @@ -113,6 +115,10 @@ impl GdriveCore { url += &format!("&pageToken={next_page_token}"); }; + if let Some(drive_id) = self.drive_id.as_ref() { + url += &format!("&drive_id={}&supportsAllDrives=true", drive_id); + } + let mut req = Request::get(&url) .body(Buffer::new()) .map_err(new_request_build_error)?;