From 002070ad9192a8727f7a90df4a7f737d638f2da4 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Thu, 11 Jul 2024 09:09:02 -0500 Subject: [PATCH] Add server endpoint for server information page --- src/main.rs | 19 ++++++++++++++++++- src/router.rs | 1 + src/router/webui.rs | 25 ++++++++++++++++++++++++- webui/src/help/Help.jsx | 16 ++++++++++------ 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1e58a51..a70c185 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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] diff --git a/src/router.rs b/src/router.rs index 7eaf72d..5fd7a4b 100644 --- a/src/router.rs +++ b/src/router.rs @@ -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 } } diff --git a/src/router/webui.rs b/src/router/webui.rs index 813aeac..a734898 100644 --- a/src/router/webui.rs +++ b/src/router/webui.rs @@ -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)) + +} diff --git a/webui/src/help/Help.jsx b/webui/src/help/Help.jsx index 9b07308..7d11cc6 100644 --- a/webui/src/help/Help.jsx +++ b/webui/src/help/Help.jsx @@ -1,19 +1,19 @@ import { useState, useParams, useEffect } from 'react' import './Help.css' import Request from '../Request.jsx' +let init = false; function Help() { const [downloadUrl, setDownloadUrl] = useState(
Contact your server admin, asking for a patched apk. Examples can be found here.
); const [downloadUrliOSGL, setDownloadUrliOSGL] = useState("https://ethanthesleepy.one/public/lovelive/sif2/sif2-gl.ipa"); const [downloadUrliOSJP, setDownloadUrliOSJP] = useState("https://ethanthesleepy.one/public/lovelive/sif2/sif2-jp.ipa"); - const [assetUrl, setAssetUrl] = useState("http://sif2.sif.moe"); - let init = false; + const [assetUrl, setAssetUrl] = useState("https://sif2.sif.moe"); useEffect(() => { - if (init) return; - init = true; (async () => { + if (init) return; + init = true; let resp = await Request("/api/webui/serverInfo"); if (resp.result !== "OK") { return; @@ -32,12 +32,16 @@ function Help() {
Your server admin has a link to download! Download Japan
); } + if (resp.data.links.assets) { + setAssetUrl(resp.data.links.assets); + } + if (!resp.data.links.ios) return; if (resp.data.links.ios.japan) { setDownloadUrliOSJP(resp.data.links.ios.japan); } if (resp.data.links.ios.global) { - setDownloadUrliOSJP(resp.data.links.ios.global); + setDownloadUrliOSGL(resp.data.links.ios.global); } })(); @@ -53,7 +57,7 @@ function Help() {

{downloadUrl}

So I got the server running, how do I install the app? (iOS)

-

Running on iOS is much simpler than Android, thanks to triangle on the discord. You first download an ipa file for global or Japan, and use Sideloadly (or your preferred application installer) to install the app. Then open settings, navigate to the app you just installed, and input the server url (Which is likely "{window.location.origin}", though this may not be the case). If you have any errors opening the app, make sure none of the urls in settings end with a slash (/).

+

Running on iOS is much simpler than Android, thanks to triangle on the discord. You first download an ipa file for global or Japan, and use Sideloadly (or your preferred application installer) to install the app. Then open settings, navigate to the app you just installed, and input the server url (Which is likely "{window.location.origin}", though this may not be the case), and the asset url, which is "{assetUrl}". If you have any errors opening the app, make sure none of the urls in settings end with a slash (/).

Help! I'm trying to open the app and it shows as "unavailable" (iOS)

Do not delete it, Just re-sideload the app. This is an Apple "security" feature.