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
5 changes: 5 additions & 0 deletions .changeset/mime-guess-upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---

Replace hand-rolled MIME type lookup with mime_guess2 crate for upload content-type inference
35 changes: 31 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ crossterm = "0.29.0"
chrono = "0.4.44"
chrono-tz = "0.10"
iana-time-zone = "0.1"
mime_guess2 = "2.3"
async-trait = "0.1.89"
serde_yaml = "0.9.34"
percent-encoding = "2.3.2"
Expand Down
29 changes: 1 addition & 28 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ fn resolve_upload_mime(
}

if let Some(path) = upload_path {
if let Some(detected) = mime_from_extension(path) {
if let Some(detected) = mime_guess2::from_path(path).first() {
return detected.to_string();
}
}
Expand All @@ -824,33 +824,6 @@ fn resolve_upload_mime(
"application/octet-stream".to_string()
}

/// Infers a MIME type from a file path's extension.
fn mime_from_extension(path: &str) -> Option<&'static str> {
let ext = std::path::Path::new(path)
.extension()
.and_then(|e| e.to_str())?;
match ext.to_lowercase().as_str() {
"md" | "markdown" => Some("text/markdown"),
"html" | "htm" => Some("text/html"),
"txt" => Some("text/plain"),
"json" => Some("application/json"),
"csv" => Some("text/csv"),
"xml" => Some("application/xml"),
"pdf" => Some("application/pdf"),
"png" => Some("image/png"),
"jpg" | "jpeg" => Some("image/jpeg"),
"gif" => Some("image/gif"),
"svg" => Some("image/svg+xml"),
"doc" => Some("application/msword"),
"docx" => Some("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
"xls" => Some("application/vnd.ms-excel"),
"xlsx" => Some("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
"ppt" => Some("application/vnd.ms-powerpoint"),
"pptx" => Some("application/vnd.openxmlformats-officedocument.presentationml.presentation"),
_ => None,
}
}

/// Builds a streaming multipart/related body for media upload requests.
///
/// Instead of reading the entire file into memory, this streams the file in
Expand Down
Loading