Move code into a lib

This commit is contained in:
Ethan O'Brien
2025-11-30 10:08:38 -06:00
parent d1ee220edb
commit 99da87095b
5 changed files with 242 additions and 233 deletions

40
src/static_handlers.rs Normal file
View File

@@ -0,0 +1,40 @@
use actix_web::{
get,
HttpResponse,
HttpRequest,
http::header::ContentType
};
use crate::include_file;
#[get("/index.css")]
async fn css(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.insert_header(ContentType(mime::TEXT_CSS))
.body(include_file!("webui/dist/index.css"))
}
#[get("/index.js")]
async fn js(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.insert_header(ContentType(mime::APPLICATION_JAVASCRIPT_UTF_8))
.body(include_file!("webui/dist/index.js"))
}
#[get("/maintenance/maintenance.json")]
async fn maintenance(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.insert_header(ContentType(mime::APPLICATION_JSON))
.body(r#"{"opened_at":"2024-02-05 02:00:00","closed_at":"2024-02-05 04:00:00","message":":(","server":1,"gamelib":0}"#)
}
fn handle_assets(req: HttpRequest) -> HttpResponse {
HttpResponse::SeeOther()
.insert_header(("location", format!("https://sif2.sif.moe{}", req.path())))
.body("")
}
#[get("/Android/{hash}/{file}")]
async fn files_jp(req: HttpRequest) -> HttpResponse {
handle_assets(req)
}
#[get("/Android/{lang}/{hash}/{file}")]
async fn files_gl(req: HttpRequest) -> HttpResponse {
handle_assets(req)
}