perf: use const-str's include_asset!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Scope for the image get backend.
|
||||
//! - `/`: Gives the default image.
|
||||
//! - `/{username}`: Gives username's pfp or redirects to the default image's path (for better
|
||||
//! - `/default`: Gives the default image.
|
||||
//! - `/user/{username}`: Gives username's pfp or redirects to the default image's path (for better
|
||||
//! cache control) if there's no image.
|
||||
//!
|
||||
//! Must be scoped at [`ws::IMAGES`]
|
||||
@@ -15,7 +15,7 @@ use actix_web::{
|
||||
|
||||
use crate::{
|
||||
consts::{self, web_scopes as ws},
|
||||
server::{self, AppData},
|
||||
server::AppData,
|
||||
};
|
||||
|
||||
#[must_use]
|
||||
@@ -25,21 +25,18 @@ pub fn make_scope(path: &str) -> actix_web::Scope {
|
||||
.service(get_image)
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn get_default_image(
|
||||
data: AppData,
|
||||
_username: web::Path<String>,
|
||||
) -> HttpResponse {
|
||||
#[get("/default")]
|
||||
async fn get_default_image() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.insert_header((
|
||||
header::CACHE_CONTROL,
|
||||
consts::DEFAULT_USER_PFP_CACHES_HEADER,
|
||||
))
|
||||
.content_type(consts::DEFAULT_USER_PFP_MIME)
|
||||
.body(web::Bytes::from_static(consts::DEFAULT_USER_PFP))
|
||||
.content_type(consts::DEFAULT_USER_PFP.mime)
|
||||
.body(web::Bytes::from_static(consts::DEFAULT_USER_PFP.bytes))
|
||||
}
|
||||
|
||||
#[get("/{username}")]
|
||||
#[get("/user/{username}")]
|
||||
async fn get_image(
|
||||
data: AppData,
|
||||
username: web::Path<String>,
|
||||
@@ -47,7 +44,11 @@ async fn get_image(
|
||||
let cached_pfp = data.cache.get_pfp(username.to_string()).await;
|
||||
|
||||
cached_pfp.as_ref().map_or_else(
|
||||
|| web::Either::Left(web::Redirect::to(ws::IMAGES).temporary()),
|
||||
|| {
|
||||
web::Either::Left(
|
||||
web::Redirect::to(const_str::concat!(ws::IMAGES, "/default")).temporary(),
|
||||
)
|
||||
},
|
||||
|img| {
|
||||
web::Either::Right(
|
||||
HttpResponse::Ok()
|
||||
|
||||
Reference in New Issue
Block a user