Skip to content

Commit

Permalink
fix: [#227] load error images in image proxy before serving them
Browse files Browse the repository at this point in the history
Error images in image proxy were not been loaded before serving them,
resulting in not sending the iamge data to the frontend.
  • Loading branch information
josecelano committed Jun 27, 2023
1 parent acf5728 commit 802df10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/ui/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions src/web/api/v1/contexts/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,13 +20,13 @@
//! with the text "Sign in to see image" instead.
//!
//! # Example
//!
//!
//! The PNG image:
//!
//!
//! <https://raw.githubusercontent.com/torrust/torrust-index-backend/develop/docs/media/torrust_logo.png>
//!
//!
//! The percent encoded image URL:
//!
//!
//! ```text
//! https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index-backend%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png
//! ```
Expand Down

0 comments on commit 802df10

Please sign in to comment.