mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-08-26 15:02:18 +08:00
Remove old asset lists / masterdata endpoints
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
use actix_web::{HttpRequest, web, Responder, HttpResponse};
|
||||
use actix_web::http::header::ContentType;
|
||||
use jzon::object;
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use crate::include_file;
|
||||
|
||||
lazy_static! {
|
||||
static ref LIST_CACHE: Mutex<HashMap<String, String>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
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"] = load_list("Bundle").into();
|
||||
response["Movie"] = load_list("Movie").into();
|
||||
response["Sound"] = load_list("Sound").into();
|
||||
|
||||
let body = jzon::stringify(response);
|
||||
HttpResponse::Ok()
|
||||
.insert_header(("content-type", ContentType::json()))
|
||||
.insert_header(("content-length", body.len()))
|
||||
.body(body)
|
||||
}
|
||||
|
||||
fn load_list(name: &str) -> String {
|
||||
if let Some(cached) = LIST_CACHE.lock().unwrap().get(name) {
|
||||
return cached.clone();
|
||||
}
|
||||
let rel = format!("asset_lists/{}.json", name);
|
||||
let list = crate::runtime::read_masterdata_file(&rel)
|
||||
.and_then(|b| String::from_utf8(b).ok())
|
||||
.unwrap_or_else(|| match name {
|
||||
"Bundle" => include_file!("src/router/asset_lists/Bundle.json"),
|
||||
"Movie" => include_file!("src/router/asset_lists/Movie.json"),
|
||||
"Sound" => include_file!("src/router/asset_lists/Sound.json"),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
|
||||
LIST_CACHE.lock().unwrap().insert(name.to_string(), list.clone());
|
||||
list
|
||||
}
|
||||
|
||||
async fn supported() -> impl Responder {
|
||||
"SUPPORTED"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -40,27 +40,6 @@ fn region_subdir(region: Region) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(bytes) = csv_bytes(region, table_name) {
|
||||
rv[table_name] = String::from_utf8(bytes).unwrap_or_default().into();
|
||||
}
|
||||
}
|
||||
|
||||
rv
|
||||
}
|
||||
|
||||
pub fn csv_bytes(region: Region, name: &str) -> Option<Vec<u8>> {
|
||||
let rel = format!("{}/{}.csv", region_subdir(region), name);
|
||||
if let Some(bytes) = crate::runtime::read_masterdata_file(&rel) {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
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))
|
||||
.route("/{platform}/{LANG}", web::get().to(mst))
|
||||
);
|
||||
}
|
||||
|
||||
async fn mst(req: HttpRequest) -> impl Responder {
|
||||
let lang = req.match_info().get("LANG").unwrap_or("JP");
|
||||
|
||||
let region = match lang.to_ascii_uppercase().as_str() {
|
||||
"JP" => Region::Jp,
|
||||
_ => Region::En, // idk
|
||||
};
|
||||
|
||||
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 {
|
||||
"SUPPORTED"
|
||||
}
|
||||
Reference in New Issue
Block a user