From 583ceb25063ce0d2fdd5f30708beb75e566d40a2 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 16 Aug 2022 15:20:41 +0000 Subject: [PATCH] Fix pictrs routing (#2407) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * SUGGESTED FIX TO PICTRS ROUTING 404 ERROR #2359 Removed slashes at "/image" routes. * cargo fmt Co-authored-by: Majid ✨ <72635080+umamawme@users.noreply.github.com> --- crates/api_common/src/request.rs | 2 +- crates/routes/src/images.rs | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 84789b17..a4c15fb7 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -125,7 +125,7 @@ pub(crate) async fn fetch_pictrs( is_image_content_type(client, image_url).await?; let fetch_url = format!( - "{}/image/download?url={}", + "{}image/download?url={}", pictrs_config.url, utf8_percent_encode(image_url.as_str(), NON_ALPHANUMERIC) // TODO this might not be needed ); diff --git a/crates/routes/src/images.rs b/crates/routes/src/images.rs index a3d8115c..3eb9bfd4 100644 --- a/crates/routes/src/images.rs +++ b/crates/routes/src/images.rs @@ -96,7 +96,7 @@ async fn upload( }; let pictrs_config = context.settings().pictrs_config()?; - let image_url = format!("{}/image", pictrs_config.url); + let image_url = format!("{}image", pictrs_config.url); let mut client_req = adapt_request(&req, &client, image_url); @@ -128,15 +128,12 @@ async fn full_res( // If there are no query params, the URL is original let pictrs_config = context.settings().pictrs_config()?; let url = if params.format.is_none() && params.thumbnail.is_none() { - format!("{}/image/original/{}", pictrs_config.url, name,) + format!("{}image/original/{}", pictrs_config.url, name,) } else { // Use jpg as a default when none is given let format = params.format.unwrap_or_else(|| "jpg".to_string()); - let mut url = format!( - "{}/image/process.{}?src={}", - pictrs_config.url, format, name, - ); + let mut url = format!("{}image/process.{}?src={}", pictrs_config.url, format, name,); if let Some(size) = params.thumbnail { url = format!("{}&thumbnail={}", url, size,); @@ -186,7 +183,7 @@ async fn delete( let (token, file) = components.into_inner(); let pictrs_config = context.settings().pictrs_config()?; - let url = format!("{}/image/delete/{}/{}", pictrs_config.url, &token, &file); + let url = format!("{}image/delete/{}/{}", pictrs_config.url, &token, &file); let mut client_req = adapt_request(&req, &client, url); -- 2.44.1