use axum::{ extract::{Path, Query}, http::StatusCode, response::Response, }; use serde::Deserialize; use crate::types::http::ResponseCode; pub async fn js(Path(path): Path) -> Response { let path = format!("/js/{path}"); super::serve(&path).await } pub async fn css(Path(path): Path) -> Response { let path = format!("/css/{path}"); super::serve(&path).await } pub async fn fonts(Path(path): Path) -> Response { let path = format!("/fonts/{path}"); super::serve(&path).await } pub async fn image(Path(path): Path) -> Response { let path = format!("/image/{path}"); super::serve(&path).await } pub async fn favicon() -> Response { super::serve("/favicon.ico").await } pub async fn robots() -> Response { super::serve("/robots.txt").await } #[derive(Deserialize)] pub struct AvatarRequest { user_id: u64, } pub async fn avatar(params: Option>) -> Response { let Some(params) = params else { return ResponseCode::BadRequest.text("Missing query paramaters"); }; let custom = format!("/image/custom/avatar/{}.png", params.user_id); let default = format!("/image/default/{}.png", params.user_id % 25); let file = super::serve(&custom).await; if file.status() != StatusCode::OK { return super::serve(&default).await; } file } #[derive(Deserialize)] pub struct BannerRequest { user_id: u64, } pub async fn banner(params: Option>) -> Response { let Some(params) = params else { return ResponseCode::BadRequest.text("Missing query paramaters"); }; let custom = format!("/image/custom/banner/{}.png", params.user_id); let file = super::serve(&custom).await; if file.status() != StatusCode::OK { return ResponseCode::NotFound.text("User does not have a custom banner"); } file }