diff --git a/Cargo.lock b/Cargo.lock index ec57e8e89..ab77b1beb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1075,6 +1075,7 @@ dependencies = [ "neo4rs", "owo-colors", "pgvector", + "phf", "pyo3", "pyo3-async-runtimes", "pythonize", @@ -3029,6 +3030,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ + "phf_macros", "phf_shared", ] @@ -3052,6 +3054,19 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "phf_macros" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "phf_shared" version = "0.11.3" diff --git a/Cargo.toml b/Cargo.toml index 6d33f4fd2..6841f630b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ tower-http = { version = "0.6.2", features = ["cors", "trace"] } indexmap = { version = "2.8.0", features = ["serde"] } blake2 = "0.10.6" pgvector = { version = "0.4.0", features = ["sqlx"] } +phf = { version = "0.11.3", features = ["macros"] } indenter = "0.3.3" itertools = "0.14.0" derivative = "2.2.0" diff --git a/src/ops/sources/google_drive.rs b/src/ops/sources/google_drive.rs index 703f0ae49..2de994bc9 100644 --- a/src/ops/sources/google_drive.rs +++ b/src/ops/sources/google_drive.rs @@ -1,12 +1,13 @@ use chrono::Duration; use google_drive3::{ - api::{File, Scope}, - yup_oauth2::{read_service_account_key, ServiceAccountAuthenticator}, DriveHub, + api::{File, Scope}, + yup_oauth2::{ServiceAccountAuthenticator, read_service_account_key}, }; use http_body_util::BodyExt; use hyper_rustls::HttpsConnector; use hyper_util::client::legacy::connect::HttpConnector; +use phf::phf_map; use crate::base::field_attrs; use crate::ops::sdk::*; @@ -18,45 +19,33 @@ struct ExportMimeType { const FOLDER_MIME_TYPE: &str = "application/vnd.google-apps.folder"; const FILE_MIME_TYPE: &str = "application/vnd.google-apps.file"; -static EXPORT_MIME_TYPES: LazyLock> = LazyLock::new(|| { - HashMap::from([ - ( - "application/vnd.google-apps.document", - ExportMimeType { - text: "text/markdown", - binary: "application/pdf", - }, - ), - ( - "application/vnd.google-apps.spreadsheet", - ExportMimeType { - text: "text/csv", - binary: "application/pdf", - }, - ), - ( - "application/vnd.google-apps.presentation", - ExportMimeType { - text: "text/plain", - binary: "application/pdf", - }, - ), - ( - "application/vnd.google-apps.drawing", - ExportMimeType { - text: "image/svg+xml", - binary: "image/png", - }, - ), - ( - "application/vnd.google-apps.script", - ExportMimeType { - text: "application/vnd.google-apps.script+json", - binary: "application/vnd.google-apps.script+json", - }, - ), - ]) -}); +static EXPORT_MIME_TYPES: phf::Map<&'static str, ExportMimeType> = phf_map! { + "application/vnd.google-apps.document" => + ExportMimeType { + text: "text/markdown", + binary: "application/pdf", + }, + "application/vnd.google-apps.spreadsheet" => + ExportMimeType { + text: "text/csv", + binary: "application/pdf", + }, + "application/vnd.google-apps.presentation" => + ExportMimeType { + text: "text/plain", + binary: "application/pdf", + }, + "application/vnd.google-apps.drawing" => + ExportMimeType { + text: "image/svg+xml", + binary: "image/png", + }, + "application/vnd.google-apps.script" => + ExportMimeType { + text: "application/vnd.google-apps.script+json", + binary: "application/vnd.google-apps.script+json", + }, +}; fn is_supported_file_type(mime_type: &str) -> bool { !mime_type.starts_with("application/vnd.google-apps.") @@ -291,11 +280,7 @@ impl ResultExt for google_drive3::Result { } fn optional_modified_time(include_ordinal: bool) -> &'static str { - if include_ordinal { - ",modifiedTime" - } else { - "" - } + if include_ordinal { ",modifiedTime" } else { "" } } #[async_trait]