feat: update avatars

This commit is contained in:
Paul Makles
2022-03-04 15:52:34 +00:00
parent f568838ff9
commit bbb368217c
12 changed files with 21 additions and 32 deletions

BIN
assets/user/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
assets/user/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
assets/user/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
assets/user/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
assets/user/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
assets/user/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
assets/user/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -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<u8>));
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("/<target>/default_avatar")]
pub async fn req(target: String) -> Option<CachedFile> {
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(),
},
))
}