Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/services/gdrive/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ impl GdriveBuilder {
self
}

/// Include shared files when fetching and listing files
pub fn include_shared(mut self, include_files: bool) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, please keep the naming as Builder, Core, and Config unchanged. This consistency is essential to ensure our configuration parser can correctly interpret user configurations.

self.config.shared_files = Some(include_files);
self
}
/// Specify the http client that used by this service.
///
/// # Notes
Expand Down Expand Up @@ -219,6 +224,7 @@ impl Builder for GdriveBuilder {
core: Arc::new(GdriveCore {
info: accessor_info.clone(),
root,
include_shared_files: self.config.shared_files.unwrap_or_default(),
signer: signer.clone(),
path_cache: PathCacher::new(GdrivePathQuery::new(accessor_info, signer))
.with_lock(),
Expand Down
2 changes: 2 additions & 0 deletions core/src/services/gdrive/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct GdriveConfig {
pub client_id: Option<String>,
/// Client secret for gdrive.
pub client_secret: Option<String>,
/// Enable viewing shared files in list
pub shared_files: Option<bool>,
}

impl Debug for GdriveConfig {
Expand Down
14 changes: 12 additions & 2 deletions core/src/services/gdrive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct GdriveCore {

pub root: String,

pub include_shared_files: bool,

pub signer: Arc<Mutex<GdriveSigner>>,

/// Cache the mapping from path to file id
Expand All @@ -66,7 +68,7 @@ impl GdriveCore {
// The file metadata in the Google Drive API is very complex.
// For now, we only need the file id, name, mime type and modified time.
let mut req = Request::get(format!(
"https://www.googleapis.com/drive/v3/files/{file_id}?fields=id,name,mimeType,size,modifiedTime"
"https://www.googleapis.com/drive/v3/files/{file_id}?supportsAllDrives={}&fields=id,name,mimeType,size,modifiedTime",self.include_shared_files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can migrate this to QueryPairsWriter for better reading.

))
.extension(Operation::Stat)
.body(Buffer::new())
Expand All @@ -83,7 +85,10 @@ impl GdriveCore {
format!("path not found: {path}"),
))?;

let url: String = format!("https://www.googleapis.com/drive/v3/files/{path_id}?alt=media");
let url: String = format!(
"https://www.googleapis.com/drive/v3/files/{path_id}?supportsAllDrives={}&alt=media",
self.include_shared_files
);

let mut req = Request::get(&url)
.extension(Operation::Read)
Expand All @@ -104,6 +109,11 @@ impl GdriveCore {
let q = format!("'{file_id}' in parents and trashed = false");
let url = "https://www.googleapis.com/drive/v3/files";
let mut url = QueryPairsWriter::new(url);
url = url.push("supportsAllDrives", &self.include_shared_files.to_string());
url = url.push(
"includeItemsFromAllDrives",
&self.include_shared_files.to_string(),
);
url = url.push("pageSize", &page_size.to_string());
url = url.push("q", &percent_encode_path(&q));
if !next_page_token.is_empty() {
Expand Down
Loading