mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-08-26 15:02:18 +08:00
Move from json to csv for masterdata
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use actix_web::{HttpResponse, HttpRequest, web, Responder};
|
||||
use actix_web::http::header::ContentType;
|
||||
use include_dir::{include_dir, Dir};
|
||||
|
||||
static MASTERDATA: Dir<'_> = include_dir!("src/router/masterdata/json/");
|
||||
static MASTERDATA: Dir<'_> = include_dir!("src/router/masterdata/csv/");
|
||||
|
||||
pub fn routes(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
@@ -13,11 +12,10 @@ pub fn routes(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
async fn mst(req: HttpRequest) -> impl Responder {
|
||||
let mst = req.match_info().get("MST").unwrap();
|
||||
println!("Getting masterdata {}", mst);
|
||||
if let Some(file) = MASTERDATA.get_file(format!("{mst}.json")) {
|
||||
if let Some(file) = MASTERDATA.get_file(format!("{mst}.csv")) {
|
||||
let body = file.contents();
|
||||
return HttpResponse::Ok()
|
||||
.insert_header(ContentType::json())
|
||||
.insert_header(("content-type", "text/csv; charset=utf-8"))
|
||||
.insert_header(("content-length", body.len()))
|
||||
.body(body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user