From 08588c873ad73f4ba2d18983c62872086ef896f4 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 10 Oct 2020 19:31:56 -0500 Subject: [PATCH 1/4] pict-rs v2 --- docker/dev/docker-compose.yml | 2 +- docker/prod/docker-compose.yml | 2 +- src/routes/images.rs | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index b8e35f2ac..ff60d347a 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -40,7 +40,7 @@ services: restart: always pictrs: - image: asonix/pictrs:v0.1.13-r0 + image: asonix/pictrs:v0.2.0-alpha.8-r0 ports: - "8537:8080" user: 991:991 diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index e313c9fe0..e06505473 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -37,7 +37,7 @@ services: - lemmy pictrs: - image: asonix/pictrs:v0.1.13-r0 + image: asonix/pictrs:v0.2.0-alpha.8-r0 ports: - "127.0.0.1:8537:8080" user: 991:991 diff --git a/src/routes/images.rs b/src/routes/images.rs index 110dafcaa..2521d0b66 100644 --- a/src/routes/images.rs +++ b/src/routes/images.rs @@ -63,7 +63,7 @@ async fn full_res( client: web::Data, ) -> Result { let url = format!( - "{}/image/{}", + "{}/image/original/{}", Settings::get().pictrs_url, &filename.into_inner() ); @@ -78,10 +78,11 @@ async fn thumbnail( let (size, file) = parts.into_inner(); let url = format!( - "{}/image/thumbnail{}/{}", + "{}/image/process.{}?src={}&thumbnail={}", Settings::get().pictrs_url, + "jpg", // this can be changed to png or webp + &file, size, - &file ); image(url, req, client).await From 863a662ec6b14b62cb8b6f3ede286bc258d41de0 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 10 Oct 2020 20:54:15 -0500 Subject: [PATCH 2/4] Stable release --- docker/dev/docker-compose.yml | 2 +- docker/prod/docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index ff60d347a..01a0f8b06 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -40,7 +40,7 @@ services: restart: always pictrs: - image: asonix/pictrs:v0.2.0-alpha.8-r0 + image: asonix/pictrs:v0.2.1-r0 ports: - "8537:8080" user: 991:991 diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index e06505473..a5817d177 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -37,7 +37,7 @@ services: - lemmy pictrs: - image: asonix/pictrs:v0.2.0-alpha.8-r0 + image: asonix/pictrs:v0.2.1-r0 ports: - "127.0.0.1:8537:8080" user: 991:991 From 4010a944a403d4ce81e3e421410c2e8f953385af Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 11 Oct 2020 13:57:35 -0500 Subject: [PATCH 3/4] Bump pict-rs version --- docker/dev/docker-compose.yml | 2 +- docker/prod/docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 01a0f8b06..c22898dff 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -40,7 +40,7 @@ services: restart: always pictrs: - image: asonix/pictrs:v0.2.1-r0 + image: asonix/pictrs:v0.2.2-r0 ports: - "8537:8080" user: 991:991 diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index a5817d177..0b7f41d62 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -37,7 +37,7 @@ services: - lemmy pictrs: - image: asonix/pictrs:v0.2.1-r0 + image: asonix/pictrs:v0.2.2-r0 ports: - "127.0.0.1:8537:8080" user: 991:991 From c87a009b372c3defa5e16abb4fd2fc1c5bc854f3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 14 Oct 2020 11:48:10 -0500 Subject: [PATCH 4/4] Altering lemmy pict-rs-v2 forwarding. --- ansible/templates/docker-compose.yml | 2 +- docker/federation/docker-compose.yml | 2 +- src/routes/images.rs | 50 +++++++++++++++------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/ansible/templates/docker-compose.yml b/ansible/templates/docker-compose.yml index ca20f3ff8..ca7b0383f 100644 --- a/ansible/templates/docker-compose.yml +++ b/ansible/templates/docker-compose.yml @@ -37,7 +37,7 @@ services: restart: always pictrs: - image: asonix/pictrs:amd64-v0.1.0-r9 + image: asonix/pictrs:v0.2.2-r0 user: 991:991 ports: - "127.0.0.1:8537:8080" diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index ba085855b..b0abb9720 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -23,7 +23,7 @@ services: pictrs: restart: always - image: asonix/pictrs:v0.1.13-r0 + image: asonix/pictrs:v0.2.2-r0 user: 991:991 volumes: - ./volumes/pictrs_alpha:/mnt diff --git a/src/routes/images.rs b/src/routes/images.rs index 2521d0b66..4b5ed9811 100644 --- a/src/routes/images.rs +++ b/src/routes/images.rs @@ -18,10 +18,8 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .wrap(rate_limit.image()) .route(web::post().to(upload)), ) + // This has optional query params: /image/{filename}?format=jpg&thumbnail=256 .service(web::resource("/pictrs/image/{filename}").route(web::get().to(full_res))) - .service( - web::resource("/pictrs/image/thumbnail{size}/{filename}").route(web::get().to(thumbnail)), - ) .service(web::resource("/pictrs/image/delete/{token}/{filename}").route(web::get().to(delete))); } @@ -37,6 +35,12 @@ pub struct Images { files: Option>, } +#[derive(Deserialize)] +pub struct PictrsParams { + format: Option, + thumbnail: Option, +} + async fn upload( req: HttpRequest, body: web::Payload, @@ -59,31 +63,31 @@ async fn upload( async fn full_res( filename: web::Path, + web::Query(params): web::Query, req: HttpRequest, client: web::Data, ) -> Result { - let url = format!( - "{}/image/original/{}", - Settings::get().pictrs_url, - &filename.into_inner() - ); - image(url, req, client).await -} + let name = &filename.into_inner(); -async fn thumbnail( - parts: web::Path<(u64, String)>, - req: HttpRequest, - client: web::Data, -) -> Result { - let (size, file) = parts.into_inner(); + // If there are no query params, the URL is original + let url = if params.format.is_none() && params.thumbnail.is_none() { + format!("{}/image/original/{}", Settings::get().pictrs_url, name,) + } else { + // Use jpg as a default when none is given + let format = params.format.unwrap_or("jpg".to_string()); - let url = format!( - "{}/image/process.{}?src={}&thumbnail={}", - Settings::get().pictrs_url, - "jpg", // this can be changed to png or webp - &file, - size, - ); + let mut url = format!( + "{}/image/process.{}?src={}", + Settings::get().pictrs_url, + format, + name, + ); + + if let Some(size) = params.thumbnail { + url = format!("{}&thumbnail={}", url, size,); + } + url + }; image(url, req, client).await }