From 802df100976aa047876843e20b83e148dc8490be Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 27 Jun 2023 18:31:50 +0100 Subject: [PATCH] fix: [#227] load error images in image proxy before serving them Error images in image proxy were not been loaded before serving them, resulting in not sending the iamge data to the frontend. --- src/ui/proxy.rs | 11 ++++++----- src/web/api/v1/contexts/proxy/mod.rs | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ui/proxy.rs b/src/ui/proxy.rs index a744c5b7..78dd2fc2 100644 --- a/src/ui/proxy.rs +++ b/src/ui/proxy.rs @@ -7,11 +7,11 @@ use crate::cache::image::manager::Error; pub static ERROR_IMAGE_LOADER: Once = Once::new(); -pub static mut ERROR_IMAGE_URL_IS_UNREACHABLE: Bytes = Bytes::new(); -pub static mut ERROR_IMAGE_URL_IS_NOT_AN_IMAGE: Bytes = Bytes::new(); -pub static mut ERROR_IMAGE_TOO_BIG: Bytes = Bytes::new(); -pub static mut ERROR_IMAGE_USER_QUOTA_MET: Bytes = Bytes::new(); -pub static mut ERROR_IMAGE_UNAUTHENTICATED: Bytes = Bytes::new(); +static mut ERROR_IMAGE_URL_IS_UNREACHABLE: Bytes = Bytes::new(); +static mut ERROR_IMAGE_URL_IS_NOT_AN_IMAGE: Bytes = Bytes::new(); +static mut ERROR_IMAGE_TOO_BIG: Bytes = Bytes::new(); +static mut ERROR_IMAGE_USER_QUOTA_MET: Bytes = Bytes::new(); +static mut ERROR_IMAGE_UNAUTHENTICATED: Bytes = Bytes::new(); const ERROR_IMG_FONT_SIZE: u8 = 16; const ERROR_IMG_COLOR: &str = "Red"; @@ -33,6 +33,7 @@ pub fn load_error_images() { } pub fn map_error_to_image(error: &Error) -> Bytes { + load_error_images(); unsafe { match error { Error::UrlIsUnreachable => ERROR_IMAGE_URL_IS_UNREACHABLE.clone(), diff --git a/src/web/api/v1/contexts/proxy/mod.rs b/src/web/api/v1/contexts/proxy/mod.rs index ea5b5dbd..a6adae1a 100644 --- a/src/web/api/v1/contexts/proxy/mod.rs +++ b/src/web/api/v1/contexts/proxy/mod.rs @@ -9,7 +9,7 @@ //! - Avoid storing images on the server. //! //! The proxy service is a simple cache that stores the images in memory. -//! +//! //! **NOTICE:** For now, it only supports PNG images. //! //! **NOTICE:** The proxy service is not intended to be used as a general @@ -20,13 +20,13 @@ //! with the text "Sign in to see image" instead. //! //! # Example -//! +//! //! The PNG image: -//! +//! //! -//! +//! //! The percent encoded image URL: -//! +//! //! ```text //! https%3A%2F%2Fraw.git.ttaallkk.top%2Ftorrust%2Ftorrust-index-backend%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png //! ```