diff --git a/assets/user/1.png b/assets/user/1.png new file mode 100644 index 00000000..88d2e28b Binary files /dev/null and b/assets/user/1.png differ diff --git a/assets/user/2.png b/assets/user/2.png new file mode 100644 index 00000000..dd0d2967 Binary files /dev/null and b/assets/user/2.png differ diff --git a/assets/user/3.png b/assets/user/3.png new file mode 100644 index 00000000..c40c1291 Binary files /dev/null and b/assets/user/3.png differ diff --git a/assets/user/4.png b/assets/user/4.png new file mode 100644 index 00000000..6db7af60 Binary files /dev/null and b/assets/user/4.png differ diff --git a/assets/user/5.png b/assets/user/5.png new file mode 100644 index 00000000..9f32511c Binary files /dev/null and b/assets/user/5.png differ diff --git a/assets/user/6.png b/assets/user/6.png new file mode 100644 index 00000000..533f920d Binary files /dev/null and b/assets/user/6.png differ diff --git a/assets/user/7.png b/assets/user/7.png new file mode 100644 index 00000000..7d9ffd0e Binary files /dev/null and b/assets/user/7.png differ diff --git a/assets/user_blue.png b/assets/user_blue.png deleted file mode 100644 index 2806b7d2..00000000 Binary files a/assets/user_blue.png and /dev/null differ diff --git a/assets/user_green.png b/assets/user_green.png deleted file mode 100644 index 0e531e07..00000000 Binary files a/assets/user_green.png and /dev/null differ diff --git a/assets/user_red.png b/assets/user_red.png deleted file mode 100644 index 46e62cce..00000000 Binary files a/assets/user_red.png and /dev/null differ diff --git a/assets/user_yellow.png b/assets/user_yellow.png deleted file mode 100644 index 7b8daaab..00000000 Binary files a/assets/user_yellow.png and /dev/null differ diff --git a/src/routes/users/get_default_avatar.rs b/src/routes/users/get_default_avatar.rs index 766e42f2..d3b07eb3 100644 --- a/src/routes/users/get_default_avatar.rs +++ b/src/routes/users/get_default_avatar.rs @@ -1,47 +1,36 @@ -use rocket::fs::NamedFile; +use rocket::http::ContentType; use rocket::response::{self, Responder}; use rocket::{Request, Response}; -use std::path::Path; -pub struct CachedFile(NamedFile); +pub struct CachedFile((ContentType, Vec)); pub static CACHE_CONTROL: &str = "public, max-age=31536000, immutable"; impl<'r> Responder<'r, 'static> for CachedFile { fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { Response::build_from(self.0.respond_to(req)?) - .raw_header("Cache-control", CACHE_CONTROL) + .raw_header("Cache-Control", CACHE_CONTROL) .ok() } } +// Charset: 0123456789ABCDEFGHJKMNPQRSTVWXYZ + #[get("//default_avatar")] -pub async fn req(target: String) -> Option { - match target.chars().nth(25).unwrap() { - '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => { - NamedFile::open(Path::new("assets/user_red.png")) - .await - .ok() - .map(CachedFile) - } - '8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => { - NamedFile::open(Path::new("assets/user_green.png")) - .await - .ok() - .map(CachedFile) - } - 'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => { - NamedFile::open(Path::new("assets/user_blue.png")) - .await - .ok() - .map(CachedFile) - } - 'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => { - NamedFile::open(Path::new("assets/user_yellow.png")) - .await - .ok() - .map(CachedFile) - } - _ => unreachable!(), - } +pub async fn req(target: String) -> CachedFile { + CachedFile(( + ContentType::PNG, + match target.chars().last().unwrap() { + '0' | '1' | '2' | '3' | 'S' | 'Z' => { + include_bytes!("../../../assets/user/2.png").to_vec() + } + '4' | '5' | '6' | '7' | 'T' => include_bytes!("../../../assets/user/3.png").to_vec(), + '8' | '9' | 'A' | 'B' => include_bytes!("../../../assets/user/4.png").to_vec(), + 'C' | 'D' | 'E' | 'F' | 'V' => include_bytes!("../../../assets/user/5.png").to_vec(), + 'G' | 'H' | 'J' | 'K' | 'W' => include_bytes!("../../../assets/user/6.png").to_vec(), + 'M' | 'N' | 'P' | 'Q' | 'X' => include_bytes!("../../../assets/user/7.png").to_vec(), + /*'0' | '1' | '2' | '3' | 'R' | 'Y'*/ + _ => include_bytes!("../../../assets/user/1.png").to_vec(), + }, + )) }