From f7611937cc5417a7af9691bc68d1cd3d1f95fde9 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Mon, 4 May 2026 12:35:22 -0500 Subject: [PATCH] Redo endpoints to get all data at once --- src/router.rs | 4 +-- src/router/asset_lists.rs | 29 +++++++++++++++++++ .../{file_lists => asset_lists}/Bundle.json | 0 .../{file_lists => asset_lists}/Movie.json | 0 .../{file_lists => asset_lists}/Sound.json | 0 src/router/databases/csv.rs | 17 +++++++++++ src/router/file_lists.rs | 22 -------------- src/router/master_data.rs | 23 ++++++--------- 8 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 src/router/asset_lists.rs rename src/router/{file_lists => asset_lists}/Bundle.json (100%) rename src/router/{file_lists => asset_lists}/Movie.json (100%) rename src/router/{file_lists => asset_lists}/Sound.json (100%) delete mode 100644 src/router/file_lists.rs diff --git a/src/router.rs b/src/router.rs index 5cd9d0c..697f84e 100644 --- a/src/router.rs +++ b/src/router.rs @@ -27,7 +27,7 @@ pub mod items; pub mod databases; pub mod location; pub mod event_ranking; -pub mod file_lists; +pub mod asset_lists; mod master_data; use actix_web::{ @@ -231,7 +231,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse { pub fn configure(cfg: &mut actix_web::web::ServiceConfig) { cfg.service( actix_web::web::scope("/api") - .configure(file_lists::routes) + .configure(asset_lists::routes) .configure(master_data::routes) ); } diff --git a/src/router/asset_lists.rs b/src/router/asset_lists.rs new file mode 100644 index 0000000..44d7725 --- /dev/null +++ b/src/router/asset_lists.rs @@ -0,0 +1,29 @@ +use actix_web::{HttpRequest, web, Responder, HttpResponse}; +use actix_web::http::header::ContentType; +use jzon::object; +use crate::include_file; + +pub fn routes(cfg: &mut web::ServiceConfig) { + cfg.service( + web::scope("/assetLists") + .route("/supported", web::get().to(supported)) + .route("{platform}/{LANG}", web::get().to(get)) + ); +} + +async fn get(_req: HttpRequest) -> impl Responder { + let mut response = object!{}; + response["Bundle"] = include_file!("src/router/asset_lists/Bundle.json").into(); + response["Movie"] = include_file!("src/router/asset_lists/Movie.json").into(); + response["Sound"] = include_file!("src/router/asset_lists/Sound.json").into(); + + let body = jzon::stringify(response); + HttpResponse::Ok() + .insert_header(("content-type", ContentType::json())) + .insert_header(("content-length", body.len())) + .body(body) +} + +async fn supported() -> impl Responder { + "SUPPORTED" +} diff --git a/src/router/file_lists/Bundle.json b/src/router/asset_lists/Bundle.json similarity index 100% rename from src/router/file_lists/Bundle.json rename to src/router/asset_lists/Bundle.json diff --git a/src/router/file_lists/Movie.json b/src/router/asset_lists/Movie.json similarity index 100% rename from src/router/file_lists/Movie.json rename to src/router/asset_lists/Movie.json diff --git a/src/router/file_lists/Sound.json b/src/router/asset_lists/Sound.json similarity index 100% rename from src/router/file_lists/Sound.json rename to src/router/asset_lists/Sound.json diff --git a/src/router/databases/csv.rs b/src/router/databases/csv.rs index 848e12e..ec9c9e9 100644 --- a/src/router/databases/csv.rs +++ b/src/router/databases/csv.rs @@ -33,6 +33,23 @@ fn dir_for(region: Region) -> &'static Dir<'static> { } } +pub fn get_all(region: Region) -> JsonValue { + let mut rv = object!{}; + + for file in dir_for(region).files() { + let table_name = file.path() + .file_stem() + .and_then(|s| s.to_str()) + .unwrap_or_default(); + + if !table_name.is_empty() { + rv[table_name] = file.contents_utf8().unwrap_or_default().into(); + } + } + + rv +} + pub fn csv_bytes(region: Region, name: &str) -> Option<&'static [u8]> { dir_for(region) .get_file(format!("{name}.csv")) diff --git a/src/router/file_lists.rs b/src/router/file_lists.rs deleted file mode 100644 index 4ce2b6a..0000000 --- a/src/router/file_lists.rs +++ /dev/null @@ -1,22 +0,0 @@ -use actix_web::{HttpResponse, HttpRequest, web, Responder}; - -pub fn routes(cfg: &mut web::ServiceConfig) { - cfg.service( - web::scope("/fileLists/{platform}/{LANG}") - .route("/Bundle", web::get().to(bundle)) - .route("/Movie", web::get().to(movie)) - .route("/Sound", web::get().to(sound)) - ); -} - -async fn bundle(_req: HttpRequest) -> impl Responder { - HttpResponse::Ok().body(include_str!("file_lists/Bundle.json")) -} - -async fn movie(_req: HttpRequest) -> impl Responder { - HttpResponse::Ok().body(include_str!("file_lists/Movie.json")) -} - -async fn sound(_req: HttpRequest) -> impl Responder { - HttpResponse::Ok().body(include_str!("file_lists/Sound.json")) -} diff --git a/src/router/master_data.rs b/src/router/master_data.rs index ab00d45..ad3ff3e 100644 --- a/src/router/master_data.rs +++ b/src/router/master_data.rs @@ -1,20 +1,16 @@ use actix_web::{web, HttpRequest, HttpResponse, Responder}; - -use crate::router::databases::csv::{self, Region}; +use actix_web::http::header::ContentType; +use crate::router::databases::csv::{get_all, Region}; pub fn routes(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/masterdata") .route("/supported", web::get().to(supported)) - .service( - web::scope("/{platform}/{LANG}") - .route("/{MST}", web::get().to(mst)) - ) + .route("/{platform}/{LANG}", web::get().to(mst)) ); } async fn mst(req: HttpRequest) -> impl Responder { - let mst_name = req.match_info().get("MST").unwrap(); let lang = req.match_info().get("LANG").unwrap_or("JP"); let region = match lang.to_ascii_uppercase().as_str() { @@ -22,13 +18,12 @@ async fn mst(req: HttpRequest) -> impl Responder { _ => Region::En, // idk }; - match csv::csv_bytes(region, mst_name) { - Some(body) => HttpResponse::Ok() - .insert_header(("content-type", "text/csv; charset=utf-8")) - .insert_header(("content-length", body.len())) - .body(body), - None => HttpResponse::NotFound().finish(), - } + let body = get_all(region); + let body = jzon::stringify(body); + HttpResponse::Ok() + .insert_header(("content-type", ContentType::json())) + .insert_header(("content-length", body.len())) + .body(body) } async fn supported() -> impl Responder {