Skip to content

Commit

Permalink
Fix pictrs routing (#2407)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Nutomic and xximj authored Aug 16, 2022
1 parent f878151 commit 583ceb2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
11 changes: 4 additions & 7 deletions crates/routes/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 583ceb2

Please sign in to comment.