From 92af0c3596a9da0579592baebb49e2caa62299cc Mon Sep 17 00:00:00 2001 From: Serhiy Barhamon Date: Sat, 28 Sep 2024 13:34:18 +0200 Subject: [PATCH 1/3] fix image to string when have dots in file name --- src/transformation/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index 0e0951a..5c7c1bd 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -99,11 +99,7 @@ impl Image { Some(format) => { let file_name = self.public_id.split('/').last().unwrap().to_string(); - let new_flie_name = format!( - "{}.{}", - file_name.split('.').collect::>().pop().unwrap(), - format - ); + let new_file_name = format!("{}.{}", file_name, format); url.set_path( path.replace(file_name.as_str(), new_flie_name.as_str()) .as_str(), @@ -427,6 +423,10 @@ mod tests { assert_eq!(image.cloud_name, "test".into()); assert_eq!(image.public_id, "1.2".into()); assert_eq!(image.get_format(), Some("jpg".into())); + assert_eq!( + image.to_string(), + "https://res.cloudinary.com/test/image/upload/1.2.jpg" + ) } #[test] From 02459bfad9a7e177629e82028dc503fe7d2fd2f3 Mon Sep 17 00:00:00 2001 From: Serhiy Barhamon Date: Sat, 28 Sep 2024 13:35:08 +0200 Subject: [PATCH 2/3] housekeeping --- Cargo.toml | 4 ++-- src/transformation/mod.rs | 14 +++++++------- src/transformation/named_color.rs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acdaa1d..8bef861 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cloudinary" description = "A Rust library for the Cloudinary API" license = "MIT OR Apache-2.0" keywords = ["cloudinary", "api", "image", "video", "upload"] -version = "0.5.0" +version = "0.5.1" edition = "2021" rust-version = "1.65.0" # due to let-else @@ -19,7 +19,7 @@ serde_json = "1.0.108" sha1 = "0.10.6" tokio = { version = "1.34.0", features = ["rt", "macros"] } tokio-util = "0.7.10" -url = "2.4.1" +url = "2.5.2" [dev-dependencies] dotenv = "0.15.0" diff --git a/src/transformation/mod.rs b/src/transformation/mod.rs index 5c7c1bd..42efd58 100644 --- a/src/transformation/mod.rs +++ b/src/transformation/mod.rs @@ -101,7 +101,7 @@ impl Image { let new_file_name = format!("{}.{}", file_name, format); url.set_path( - path.replace(file_name.as_str(), new_flie_name.as_str()) + path.replace(file_name.as_str(), new_file_name.as_str()) .as_str(), ); } @@ -156,7 +156,7 @@ impl TryFrom for Image { let mut cloud_name: Option<&str> = None; let mut public_id_parts: Vec<(&str, Option<&str>)> = Vec::new(); - let mut public_id_teritory = false; + let mut public_id_territory = false; for (pos, s) in url.path_segments().unwrap().enumerate() { match pos { 0 => { @@ -185,14 +185,14 @@ impl TryFrom for Image { } } _ => { - if !public_id_teritory && is_version(s) { - public_id_teritory = true; - } else if !public_id_teritory && is_transformation(s) { + if !public_id_territory && is_version(s) { + public_id_territory = true; + } else if !public_id_territory && is_transformation(s) { } else if let Some((head, tail)) = s.rsplit_once('.') { - public_id_teritory = true; + public_id_territory = true; public_id_parts.push((head, Some(tail))); } else { - public_id_teritory = true; + public_id_territory = true; public_id_parts.push((s, None)); } } diff --git a/src/transformation/named_color.rs b/src/transformation/named_color.rs index 21b3164..3b9ec11 100644 --- a/src/transformation/named_color.rs +++ b/src/transformation/named_color.rs @@ -1,6 +1,6 @@ use std::fmt::Display; /// CSS named colors V4. -/// https://www.w3.org/TR/css-color-4/#named-colors +/// #[derive(Debug, Clone)] pub enum NamedColor { AliceBlue, From 322d50c0111445cc8788f23f5ab2218a8bd39c02 Mon Sep 17 00:00:00 2001 From: Serhiy Barhamon Date: Sat, 28 Sep 2024 13:43:17 +0200 Subject: [PATCH 3/3] update deps --- Cargo.toml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8bef861..acd0c95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,21 +9,21 @@ rust-version = "1.65.0" # due to let-else [dependencies] -anyhow = "1.0.75" -chrono = "0.4.31" -itertools = "0.12.0" +anyhow = "1.0.89" +chrono = "0.4.38" +itertools = "0.13.0" mime = "0.3.17" -reqwest = { version = "0.11.22", features = ["json", "multipart", "stream"] } -serde = { version = "1.0.193", features = ["derive", "rc"] } -serde_json = "1.0.108" +reqwest = { version = "0.12.7", features = ["json", "multipart", "stream"] } +serde = { version = "1.0.210", features = ["derive", "rc"] } +serde_json = "1.0.128" sha1 = "0.10.6" -tokio = { version = "1.34.0", features = ["rt", "macros"] } -tokio-util = "0.7.10" +tokio = { version = "1.40.0", features = ["rt", "macros"] } +tokio-util = "0.7.12" url = "2.5.2" [dev-dependencies] dotenv = "0.15.0" -pretty_assertions = "1.4.0" +pretty_assertions = "1.4.1" # for minimal-versions [target.'cfg(any())'.dependencies]