From 76064feeb2b38f151a1ad54372e90889a64ec22c Mon Sep 17 00:00:00 2001 From: red binder Date: Sun, 26 Apr 2026 21:57:28 +0200 Subject: [PATCH 1/2] attempt to fix date header --- Cargo.lock | 41 ++++++++++++++++++++++++++--------------- Cargo.toml | 1 + src/main.rs | 2 +- src/nnid/mapped_ids.rs | 27 +++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7607ea..09a45cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,7 @@ dependencies = [ "sha2", "sqlx", "thiserror", + "time", "tokio", "tonic", "tonic-build", @@ -729,9 +730,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.11" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" dependencies = [ "powerfmt", ] @@ -2040,9 +2041,9 @@ dependencies = [ [[package]] name = "num-conv" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" [[package]] name = "num-integer" @@ -3006,18 +3007,28 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -3524,30 +3535,30 @@ dependencies = [ [[package]] name = "time" -version = "0.3.37" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" dependencies = [ "deranged", "itoa", "num-conv", "powerfmt", - "serde", + "serde_core", "time-core", "time-macros", ] [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "time-macros" -version = "0.2.19" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" dependencies = [ "num-conv", "time-core", diff --git a/Cargo.toml b/Cargo.toml index 1a13e1d..dfc5b32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ prost = "0.13.4" lettre = "0.11.15" rand = "0.8.5" reqwest = "0.12.12" +time = "0.3.47" diff --git a/src/main.rs b/src/main.rs index ce2900a..749df21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,7 +117,7 @@ async fn launch() -> _ { ) .attach(AdHoc::on_response("org", |_, response| Box::pin(async move { //response.adjoin_header(Header::new("x-organization", "Nintendo")); - response.adjoin_header(Header::new("x-nintendo-date", SystemTime::now() + response.adjoin_header(Header::new("X-Nintendo-Date", SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis() diff --git a/src/nnid/mapped_ids.rs b/src/nnid/mapped_ids.rs index ddcd91c..1b989a1 100644 --- a/src/nnid/mapped_ids.rs +++ b/src/nnid/mapped_ids.rs @@ -2,6 +2,12 @@ use rocket::{get, State}; use serde::Serialize; use crate::Pool; use crate::xml::Xml; +use std::io::Cursor; + +use rocket::{Request, response::{Responder, Response}}; +use rocket::http::Header; +use time::{OffsetDateTime, Time}; +use time::format_description::well_known::Rfc2822; #[derive(Serialize)] #[serde(rename = "mapped_id")] @@ -21,6 +27,23 @@ struct UserIdAndName { username: String, } +pub struct TimeResponse; + +#[rocket::async_trait] +impl<'r> Responder<'r, 'static> for TimeResponse { + fn respond_to(self, _req: &'r Request<'_>) -> rocket::response::Result<'static> { + let now = OffsetDateTime::now_utc() + .format(&Rfc2822) + .unwrap() + .replace("+0000", "GMT"); + + Response::build() + .header(Header::new("Date", now)) + .sized_body(0, Cursor::new("")) + .ok() + } +} + #[get("/v1/api/admin/mapped_ids?&&")] pub async fn mapped_ids(pool: &State, input_type: String, output_type: String, input: String) -> Option> { let pool = pool.inner(); @@ -83,6 +106,6 @@ pub async fn mapped_ids(pool: &State, input_type: String, output_type: Str } #[get("/v1/api/admin/time")] -pub fn get_time() { - // stubbed, it only needs the header. +pub fn get_time() -> TimeResponse { + TimeResponse } \ No newline at end of file From a57cd4ec19538ff03a555316c223bd0d28511dd6 Mon Sep 17 00:00:00 2001 From: red binder Date: Sun, 26 Apr 2026 22:12:41 +0200 Subject: [PATCH 2/2] readd org header --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 749df21..5cf8712 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,7 @@ async fn launch() -> _ { EmptySubscription::new()) ) .attach(AdHoc::on_response("org", |_, response| Box::pin(async move { - //response.adjoin_header(Header::new("x-organization", "Nintendo")); + response.adjoin_header(Header::new("x-organization", "Nintendo")); response.adjoin_header(Header::new("X-Nintendo-Date", SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap()