mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 08:42:20 +08:00
Redo endpoints to get all data at once
This commit is contained in:
@@ -27,7 +27,7 @@ pub mod items;
|
|||||||
pub mod databases;
|
pub mod databases;
|
||||||
pub mod location;
|
pub mod location;
|
||||||
pub mod event_ranking;
|
pub mod event_ranking;
|
||||||
pub mod file_lists;
|
pub mod asset_lists;
|
||||||
mod master_data;
|
mod master_data;
|
||||||
|
|
||||||
use actix_web::{
|
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) {
|
pub fn configure(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
actix_web::web::scope("/api")
|
actix_web::web::scope("/api")
|
||||||
.configure(file_lists::routes)
|
.configure(asset_lists::routes)
|
||||||
.configure(master_data::routes)
|
.configure(master_data::routes)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/router/asset_lists.rs
Normal file
29
src/router/asset_lists.rs
Normal file
@@ -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"
|
||||||
|
}
|
||||||
@@ -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]> {
|
pub fn csv_bytes(region: Region, name: &str) -> Option<&'static [u8]> {
|
||||||
dir_for(region)
|
dir_for(region)
|
||||||
.get_file(format!("{name}.csv"))
|
.get_file(format!("{name}.csv"))
|
||||||
|
|||||||
@@ -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"))
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||||
|
use actix_web::http::header::ContentType;
|
||||||
use crate::router::databases::csv::{self, Region};
|
use crate::router::databases::csv::{get_all, Region};
|
||||||
|
|
||||||
pub fn routes(cfg: &mut web::ServiceConfig) {
|
pub fn routes(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("/masterdata")
|
web::scope("/masterdata")
|
||||||
.route("/supported", web::get().to(supported))
|
.route("/supported", web::get().to(supported))
|
||||||
.service(
|
.route("/{platform}/{LANG}", web::get().to(mst))
|
||||||
web::scope("/{platform}/{LANG}")
|
|
||||||
.route("/{MST}", web::get().to(mst))
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mst(req: HttpRequest) -> impl Responder {
|
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 lang = req.match_info().get("LANG").unwrap_or("JP");
|
||||||
|
|
||||||
let region = match lang.to_ascii_uppercase().as_str() {
|
let region = match lang.to_ascii_uppercase().as_str() {
|
||||||
@@ -22,13 +18,12 @@ async fn mst(req: HttpRequest) -> impl Responder {
|
|||||||
_ => Region::En, // idk
|
_ => Region::En, // idk
|
||||||
};
|
};
|
||||||
|
|
||||||
match csv::csv_bytes(region, mst_name) {
|
let body = get_all(region);
|
||||||
Some(body) => HttpResponse::Ok()
|
let body = jzon::stringify(body);
|
||||||
.insert_header(("content-type", "text/csv; charset=utf-8"))
|
HttpResponse::Ok()
|
||||||
.insert_header(("content-length", body.len()))
|
.insert_header(("content-type", ContentType::json()))
|
||||||
.body(body),
|
.insert_header(("content-length", body.len()))
|
||||||
None => HttpResponse::NotFound().finish(),
|
.body(body)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn supported() -> impl Responder {
|
async fn supported() -> impl Responder {
|
||||||
|
|||||||
Reference in New Issue
Block a user