From 66ad791ff82e7c3a6a294f34603ec49e9f5a0416 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Wed, 10 Jul 2024 22:33:33 -0500 Subject: [PATCH] Added configurable NPPS4 server address for sif1 account linking --- docker/start.sh | 10 +++++----- src/main.rs | 7 ++++++- src/router/user.rs | 13 +++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) mode change 100644 => 100755 docker/start.sh diff --git a/docker/start.sh b/docker/start.sh old mode 100644 new mode 100755 index 7540d55..91e5a1a --- a/docker/start.sh +++ b/docker/start.sh @@ -3,8 +3,8 @@ port="${PORT:-8080}" directory="${DIRECTORY:-/data/}" -if [ "$HTTPS" = "true" ]; then - /root/ew/ew --path $directory --port $port --https -else - /root/ew/ew --path $directory --port $port -fi +npps4="${NPPS4_ADDRESS:-http://127.0.0.1:51376}" + +https=$([ "$HTTPS" = "true" ] && echo "--https" || echo "") + +/root/ew/ew --path $directory --port $port --npps4 $npps4 $https diff --git a/src/main.rs b/src/main.rs index 546fc9f..24d7219 100644 --- a/src/main.rs +++ b/src/main.rs @@ -211,7 +211,10 @@ pub struct Args { path: String, #[arg(long, default_value_t = false, help = "Serve gree headers with https. WILL NOT ACCEPT HTTPS REQUESTS")] - https: bool + https: bool, + + #[arg(long, default_value = "http://127.0.0.1:51376", help = "Address to NPPS4 server for sif account linking")] + npps4: String } pub fn get_args() -> Args { @@ -236,6 +239,8 @@ async fn main() -> std::io::Result<()> { println!("Server started: http://0.0.0.0:{}", port); println!("Data path is set to {}", args.path); + println!("Sif1 transfer requests will attempt to contact NPPS4 at {}", host); + if args.https { println!("Note: gree is set to https mode. http requests will fail on jp clients."); } diff --git a/src/router/user.rs b/src/router/user.rs index 44928dc..2ee328b 100644 --- a/src/router/user.rs +++ b/src/router/user.rs @@ -322,11 +322,16 @@ fn generate_passcode_sha1(transfer_id: String, transfer_code: String) -> String } async fn npps4_req(sha_id: String) -> Option { + let args = crate::get_args(); + + let mut host = args.npps4; + while host.ends_with("/") { + host.pop(); + } + let url = format!("{}/ewexport?sha1={}", host, sha_id); + println!("Polling NPPS4 at {}", host); + let client = reqwest::Client::new(); - // TODO - ability to configure in admin webui? - let hostname = "http://127.0.0.1:51376"; - let url = format!("{}/ewexport?sha1={}", hostname, sha_id); - println!("Polling NPPS4 at {}", hostname); let response = client.get(url); let response_body = response.send().await.ok()?.text().await.ok()?; Some(json::parse(&response_body).ok()?)