Skip to content

Commit 802df10

Browse files
committed
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.
1 parent acf5728 commit 802df10

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/ui/proxy.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use crate::cache::image::manager::Error;
77

88
pub static ERROR_IMAGE_LOADER: Once = Once::new();
99

10-
pub static mut ERROR_IMAGE_URL_IS_UNREACHABLE: Bytes = Bytes::new();
11-
pub static mut ERROR_IMAGE_URL_IS_NOT_AN_IMAGE: Bytes = Bytes::new();
12-
pub static mut ERROR_IMAGE_TOO_BIG: Bytes = Bytes::new();
13-
pub static mut ERROR_IMAGE_USER_QUOTA_MET: Bytes = Bytes::new();
14-
pub static mut ERROR_IMAGE_UNAUTHENTICATED: Bytes = Bytes::new();
10+
static mut ERROR_IMAGE_URL_IS_UNREACHABLE: Bytes = Bytes::new();
11+
static mut ERROR_IMAGE_URL_IS_NOT_AN_IMAGE: Bytes = Bytes::new();
12+
static mut ERROR_IMAGE_TOO_BIG: Bytes = Bytes::new();
13+
static mut ERROR_IMAGE_USER_QUOTA_MET: Bytes = Bytes::new();
14+
static mut ERROR_IMAGE_UNAUTHENTICATED: Bytes = Bytes::new();
1515

1616
const ERROR_IMG_FONT_SIZE: u8 = 16;
1717
const ERROR_IMG_COLOR: &str = "Red";
@@ -33,6 +33,7 @@ pub fn load_error_images() {
3333
}
3434

3535
pub fn map_error_to_image(error: &Error) -> Bytes {
36+
load_error_images();
3637
unsafe {
3738
match error {
3839
Error::UrlIsUnreachable => ERROR_IMAGE_URL_IS_UNREACHABLE.clone(),

src/web/api/v1/contexts/proxy/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! - Avoid storing images on the server.
1010
//!
1111
//! The proxy service is a simple cache that stores the images in memory.
12-
//!
12+
//!
1313
//! **NOTICE:** For now, it only supports PNG images.
1414
//!
1515
//! **NOTICE:** The proxy service is not intended to be used as a general
@@ -20,13 +20,13 @@
2020
//! with the text "Sign in to see image" instead.
2121
//!
2222
//! # Example
23-
//!
23+
//!
2424
//! The PNG image:
25-
//!
25+
//!
2626
//! <https://raw.githubusercontent.com/torrust/torrust-index-backend/develop/docs/media/torrust_logo.png>
27-
//!
27+
//!
2828
//! The percent encoded image URL:
29-
//!
29+
//!
3030
//! ```text
3131
//! https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index-backend%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png
3232
//! ```

0 commit comments

Comments
 (0)