Fix asset fallthrough on api paths

This commit is contained in:
Ethan O'Brien
2026-06-07 22:11:02 -05:00
parent d34b5fc6a4
commit b584fbe97f
3 changed files with 24 additions and 17 deletions

View File

@@ -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();

View File

@@ -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)

View File

@@ -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))
);
}