Skip to content

Commit

Permalink
Merge torrust#228: fix: load error images in image proxy before servi…
Browse files Browse the repository at this point in the history
…ng them

802df10 fix: [torrust#227] load error images in image proxy before serving them (Jose Celano)

Pull request description:

  Error images in image proxy were not been loaded before serving them, resulting in not sending the iamge data to the frontend.

Top commit has no ACKs.

Tree-SHA512: 780ae15f40d7a5705c62d40f4a49c401a0eb30605af9fef0b749a07424c1215e58bba2aa49669c4c1b70aed1fcebafc4351f21e3e6cb9053b60f0715a032abad
  • Loading branch information
josecelano committed Jun 27, 2023
2 parents acf5728 + 802df10 commit 31d63e3
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.git.ttaallkk.top%2Ftorrust%2Ftorrust-index-backend%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png
//! ```
Expand Down

0 comments on commit 31d63e3

Please sign in to comment.