mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-08-26 15:02:18 +08:00
Redo endpoints to get all data at once
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user