Add server endpoint for server information page

This commit is contained in:
Ethan O'Brien
2024-07-11 09:09:02 -05:00
parent 8c9af03928
commit 002070ad91
4 changed files with 53 additions and 8 deletions

View File

@ -41,7 +41,24 @@ pub struct Args {
https: bool,
#[arg(long, default_value = "http://127.0.0.1:51376", help = "Address to NPPS4 server for sif account linking")]
npps4: String
npps4: String,
//below options are for the "Help" page
#[arg(long, default_value = "", help = "Link to patched android global apk for this server.")]
global_android: String,
#[arg(long, default_value = "", help = "Link to patched android japan apk for this server.")]
japan_android: String,
#[arg(long, default_value = "", help = "Link to patched iOS global apk for this server.")]
global_ios: String,
#[arg(long, default_value = "", help = "Link to patched iOS japan apk for this server.")]
japan_ios: String,
#[arg(long, default_value = "", help = "Link to asset server.")]
assets_url: String
}
#[actix_web::main]

View File

@ -181,6 +181,7 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse {
"/webui/logout" => webui::logout(req),
"/api/webui/admin" => webui::admin(req),
"/api/webui/export" => webui::export(req),
"/api/webui/serverInfo" => webui::server_info(req),
_ => api_req(req, body).await
}
}

View File

@ -172,7 +172,7 @@ pub fn main(req: HttpRequest) -> HttpResponse {
}
}
}
if req.path() != "/" && req.path() != "/home/" && req.path() != "/import/" && req.path() != "/admin/" {
if req.path() != "/" && req.path() != "/home/" && req.path() != "/import/" && req.path() != "/admin/" && req.path() != "/help/" {
return HttpResponse::Found()
.insert_header(("Location", "/"))
.body("");
@ -238,3 +238,26 @@ pub fn export(req: HttpRequest) -> HttpResponse {
.body(json::stringify(resp))
}
pub fn server_info(_req: HttpRequest) -> HttpResponse {
let args = crate::get_args();
let resp = object!{
result: "OK",
data: {
account_import: get_config()["import"].as_bool().unwrap(),
links: {
global: args.global_android,
japan: args.japan_android,
ios: {
global: args.global_ios,
japan: args.japan_ios
},
assets: args.assets_url
}
}
};
HttpResponse::Ok()
.insert_header(ContentType::json())
.body(json::stringify(resp))
}