mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 00:32:20 +08:00
Compare commits
2 Commits
4836f332f0
...
54e84fbaac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54e84fbaac | ||
|
|
41b3ea2c7f |
@@ -217,6 +217,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
"/api/webui/export" => webui::export(req),
|
"/api/webui/export" => webui::export(req),
|
||||||
"/api/webui/serverInfo" => webui::server_info(req),
|
"/api/webui/serverInfo" => webui::server_info(req),
|
||||||
"/api/webui/listCards" => webui::get_card_info(req),
|
"/api/webui/listCards" => webui::get_card_info(req),
|
||||||
|
"/api/webui/listMusic" => webui::get_music_info(req),
|
||||||
_ => api_req(req, body).await
|
_ => api_req(req, body).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use json::{JsonValue, object};
|
|||||||
use crate::include_file;
|
use crate::include_file;
|
||||||
use crate::router::{userdata, items};
|
use crate::router::{userdata, items};
|
||||||
|
|
||||||
|
//pub const FRONTEND_DOMAIN: &str = "https://sif2-api.ethanthesleepy.one";
|
||||||
|
|
||||||
fn get_config() -> JsonValue {
|
fn get_config() -> JsonValue {
|
||||||
let args = crate::get_args();
|
let args = crate::get_args();
|
||||||
object!{
|
object!{
|
||||||
@@ -32,7 +34,7 @@ fn error(msg: &str) -> HttpResponse {
|
|||||||
message: msg
|
message: msg
|
||||||
};
|
};
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.insert_header(("Access-Control-Allow-Origin", "*"))
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
|
|
||||||
@@ -51,6 +53,8 @@ pub fn login(_req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
};
|
};
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
|
//.insert_header(("Access-Control-Allow-Credentials", "true"))
|
||||||
.insert_header(("Set-Cookie", format!("ew_token={}; SameSite=Strict; HttpOnly", token.unwrap())))
|
.insert_header(("Set-Cookie", format!("ew_token={}; SameSite=Strict; HttpOnly", token.unwrap())))
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
@@ -96,6 +100,7 @@ pub fn user(req: HttpRequest) -> HttpResponse {
|
|||||||
data: data
|
data: data
|
||||||
};
|
};
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
@@ -109,6 +114,7 @@ pub fn start_loginbonus(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
let resp = userdata::webui_start_loginbonus(body["bonus_id"].as_i64().unwrap(), &token.unwrap());
|
let resp = userdata::webui_start_loginbonus(body["bonus_id"].as_i64().unwrap(), &token.unwrap());
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
@@ -122,6 +128,7 @@ pub fn set_time(req: HttpRequest, body: String) -> HttpResponse {
|
|||||||
let resp = userdata::set_server_time(body["timestamp"].as_i64().unwrap(), &token.unwrap());
|
let resp = userdata::set_server_time(body["timestamp"].as_i64().unwrap(), &token.unwrap());
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
@@ -135,6 +142,7 @@ pub fn logout(req: HttpRequest) -> HttpResponse {
|
|||||||
result: "OK"
|
result: "OK"
|
||||||
};
|
};
|
||||||
HttpResponse::Found()
|
HttpResponse::Found()
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.insert_header(ContentType::json())
|
.insert_header(ContentType::json())
|
||||||
.insert_header(("Set-Cookie", "ew_token=deleted; expires=Thu, 01 Jan 1970 00:00:00 GMT"))
|
.insert_header(("Set-Cookie", "ew_token=deleted; expires=Thu, 01 Jan 1970 00:00:00 GMT"))
|
||||||
.insert_header(("Location", "/"))
|
.insert_header(("Location", "/"))
|
||||||
@@ -203,16 +211,19 @@ pub fn server_info(_req: HttpRequest) -> HttpResponse {
|
|||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_card_info(req: HttpRequest) -> HttpResponse {
|
fn get_query_str(req: &HttpRequest, key: &str, def: &str) -> String {
|
||||||
let query_str = req.query_string();
|
let query_str = req.query_string();
|
||||||
let page: usize = query_str
|
query_str
|
||||||
.split('&')
|
.split('&')
|
||||||
.find(|s| s.starts_with("page="))
|
.find(|s| s.starts_with(&format!("{key}=")))
|
||||||
.and_then(|s| s.split('=').nth(1))
|
.and_then(|s| s.split('=').nth(1))
|
||||||
.and_then(|s| s.parse().ok())
|
.unwrap_or(def).to_string()
|
||||||
.unwrap_or(1) - 1;
|
}
|
||||||
|
|
||||||
|
pub fn get_card_info(req: HttpRequest) -> HttpResponse {
|
||||||
|
let page = get_query_str(&req, "page", "1").parse::<usize>().unwrap_or(1) - 1;
|
||||||
|
let max = get_query_str(&req, "max", "10").parse::<usize>().unwrap_or(10);
|
||||||
|
|
||||||
let max = 10;
|
|
||||||
let start = page * max;
|
let start = page * max;
|
||||||
|
|
||||||
let items = json::parse(&include_file!("src/router/webui/cards.json")).unwrap();
|
let items = json::parse(&include_file!("src/router/webui/cards.json")).unwrap();
|
||||||
@@ -237,6 +248,43 @@ pub fn get_card_info(req: HttpRequest) -> HttpResponse {
|
|||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type(ContentType::json())
|
.content_type(ContentType::json())
|
||||||
.insert_header(("Access-Control-Allow-Origin", "*"))
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
|
.body(json::stringify(resp))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_music_info(req: HttpRequest) -> HttpResponse {
|
||||||
|
let page = get_query_str(&req, "page", "1").parse::<usize>().unwrap_or(1) - 1;
|
||||||
|
let max = get_query_str(&req, "max", "10").parse::<usize>().unwrap_or(10);
|
||||||
|
let lang = get_query_str(&req, "lang", "JP");
|
||||||
|
|
||||||
|
let start = page * max;
|
||||||
|
|
||||||
|
let items = if lang == "EN" {
|
||||||
|
json::parse(&include_file!("src/router/databases/json/global/music.json")).unwrap()
|
||||||
|
} else {
|
||||||
|
json::parse(&include_file!("src/router/databases/json/music.json")).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
let page_items: Vec<_> = items.members()
|
||||||
|
.skip(start)
|
||||||
|
.take(max)
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if page_items.is_empty() {
|
||||||
|
return HttpResponse::NotFound().finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
let total_items = items.len();
|
||||||
|
let total_pages = (total_items as f64 / max as f64).ceil() as usize;
|
||||||
|
|
||||||
|
let resp = object!{
|
||||||
|
total_pages: total_pages,
|
||||||
|
current: page_items
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponse::Ok()
|
||||||
|
.content_type(ContentType::json())
|
||||||
|
//.insert_header(("Access-Control-Allow-Origin", FRONTEND_DOMAIN))
|
||||||
.body(json::stringify(resp))
|
.body(json::stringify(resp))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user