Add cache control header for default avatars.
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export version=0.5.1-alpha.20
|
export version=0.5.1-alpha.21
|
||||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||||
|
|||||||
@@ -1,28 +1,41 @@
|
|||||||
use rocket::response::NamedFile;
|
use rocket::{Request, Response};
|
||||||
|
use rocket::response::{self, NamedFile, Responder};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::database::Ref;
|
use crate::database::Ref;
|
||||||
|
|
||||||
|
pub struct CachedFile(NamedFile);
|
||||||
|
|
||||||
|
pub static CACHE_CONTROL: &'static 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)
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/<target>/default_avatar")]
|
#[get("/<target>/default_avatar")]
|
||||||
pub async fn req(target: Ref) -> Option<NamedFile> {
|
pub async fn req(target: Ref) -> Option<CachedFile> {
|
||||||
match target.id.chars().nth(25).unwrap() {
|
match target.id.chars().nth(25).unwrap() {
|
||||||
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => {
|
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' => {
|
||||||
NamedFile::open(Path::new("assets/user_red.png")).await.ok()
|
NamedFile::open(Path::new("assets/user_red.png")).await.ok().map(|n| CachedFile(n))
|
||||||
}
|
}
|
||||||
'8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => {
|
'8' | '9' | 'A' | 'C' | 'B' | 'D' | 'E' | 'F' => {
|
||||||
NamedFile::open(Path::new("assets/user_green.png"))
|
NamedFile::open(Path::new("assets/user_green.png"))
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok().map(|n| CachedFile(n))
|
||||||
}
|
}
|
||||||
'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => {
|
'G' | 'H' | 'J' | 'K' | 'M' | 'N' | 'P' | 'Q' => {
|
||||||
NamedFile::open(Path::new("assets/user_blue.png"))
|
NamedFile::open(Path::new("assets/user_blue.png"))
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok().map(|n| CachedFile(n))
|
||||||
}
|
}
|
||||||
'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => {
|
'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z' => {
|
||||||
NamedFile::open(Path::new("assets/user_yellow.png"))
|
NamedFile::open(Path::new("assets/user_yellow.png"))
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok().map(|n| CachedFile(n))
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub const VERSION: &str = "0.5.1-alpha.20";
|
pub const VERSION: &str = "0.5.1-alpha.21";
|
||||||
|
|||||||
Reference in New Issue
Block a user