From b584fbe97fa740758b244b9ee012cdba5477d061 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Sun, 7 Jun 2026 22:11:02 -0500 Subject: [PATCH] Fix asset fallthrough on api paths --- src/lib.rs | 10 +--------- src/router.rs | 1 + src/static_handlers.rs | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 322de8a..4343a07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,13 +16,7 @@ mod android; #[cfg(target_os = "ios")] mod ios; -use actix_web::{ - rt, - App, - HttpServer, - web, - dev::Service -}; +use actix_web::{rt, App, HttpServer, web, dev::Service}; use std::time::Duration; pub use options::get_args; use runtime::get_data_path; @@ -50,8 +44,6 @@ pub async fn run_server(in_thread: bool) -> std::io::Result<()> { }) .app_data(web::PayloadConfig::default().limit(1024 * 1024 * 25)) .service(static_handlers::maintenance) - .service(static_handlers::files_jp) - .service(static_handlers::files_gl) .configure(router::configure) .default_service(web::route().to(router::request)) ).bind(("0.0.0.0", port))?.run(); diff --git a/src/router.rs b/src/router.rs index 01944c7..039c202 100644 --- a/src/router.rs +++ b/src/router.rs @@ -209,6 +209,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse { } pub fn configure(cfg: &mut actix_web::web::ServiceConfig) { + cfg.configure(crate::static_handlers::routes); cfg.service( actix_web::web::scope("/api") .configure(asset_lists::routes) diff --git a/src/static_handlers.rs b/src/static_handlers.rs index 493d523..d0f5841 100644 --- a/src/static_handlers.rs +++ b/src/static_handlers.rs @@ -1,9 +1,4 @@ -use actix_web::{ - get, - HttpResponse, - HttpRequest, - http::header::ContentType -}; +use actix_web::{get, HttpResponse, HttpRequest, http::header::ContentType, web, guard}; use std::fs; use std::path::{Path, PathBuf}; @@ -63,12 +58,31 @@ fn handle_assets(req: HttpRequest) -> HttpResponse { } } -#[get("/{platform}/{hash}/{file}")] async fn files_jp(req: HttpRequest) -> HttpResponse { handle_assets(req) } -#[get("/{platform}/{lang}/{hash}/{file}")] async fn files_gl(req: HttpRequest) -> HttpResponse { handle_assets(req) } + +fn platform_guard(ctx: &guard::GuardContext) -> bool { + let platform = ctx.head().uri.path() + .split('/') + .nth(1) + .unwrap_or(""); + matches!(platform, "Android" | "StandaloneWindows64" | "Ios") +} + +pub fn routes(cfg: &mut web::ServiceConfig) { + cfg.service( + web::resource("/{platform}/{hash}/{file}") + .guard(guard::fn_guard(platform_guard)) + .route(web::get().to(files_jp)) + ) + .service( + web::resource("/{platform}/{lang}/{hash}/{file}") + .guard(guard::fn_guard(platform_guard)) + .route(web::get().to(files_gl)) + ); +}