From ac7cb0ddeeebfad2d5df579b4e1518eda2a8cf22 Mon Sep 17 00:00:00 2001 From: red binder Date: Mon, 4 May 2026 21:27:32 +0200 Subject: [PATCH 1/2] Add token type to GraphQL requests --- Cargo.lock | 10 ++++++++++ src/graphql/mod.rs | 26 +++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5050606..fd6a9c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2552,6 +2552,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "openssl-src" +version = "300.6.0+3.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8e8cbfd3a4a8c8f089147fd7aaa33cf8c7450c4d09f8f80698a0cf093abeff4" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.114" @@ -2560,6 +2569,7 @@ checksum = "13ce1245cd07fcc4cfdb438f7507b0c7e4f3849a69fd84d52374c66d83741bb6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs index 633be82..b8ce114 100644 --- a/src/graphql/mod.rs +++ b/src/graphql/mod.rs @@ -48,7 +48,8 @@ impl juniper::Context for Context {} struct TokenInfo { pid: i32, expire_date: NaiveDateTime, - title_id: Option + title_id: Option, + token_type: i32 } #[derive(GraphQLObject)] @@ -60,6 +61,16 @@ struct UserInfo { mii_data: String, } +#[derive(GraphQLObject)] +#[graphql(description = "User information from a token")] +struct TokenUserInfo { + username: String, + account_level: i32, + nex_password: String, + mii_data: String, + token_type: i32, +} + #[derive(GraphQLObject)] #[graphql(description = "User information from a username")] pub struct UserInfoWithPId { @@ -96,13 +107,14 @@ impl Query { pid: data.pid, expire_date: token_info.expires, title_id: token_info.title_id, + token_type: token_info.token_type, }) } async fn user_from_token( token_data: String, context: &Context, - ) -> Option { + ) -> Option { let data = match TokenData::decode(&token_data) { Some(data) => data, None => { @@ -111,6 +123,13 @@ impl Query { } }; + let token_info = + sqlx::query!( + "select * from tokens where pid = $1 and token_id = $2 and random = $3", + data.pid, data.token_id, data.random + ). + fetch_one(&context.pool).await.ok()?; + let user = match sqlx::query!( "SELECT username, account_level, nex_password, mii_data FROM users WHERE pid = $1", data.pid @@ -127,11 +146,12 @@ impl Query { let nex_password = user.nex_password; - Some(UserInfo { + Some(TokenUserInfo { username: user.username, account_level: user.account_level, nex_password, mii_data: user.mii_data.replace('\n', "").replace('\r', ""), + token_type: token_info.token_type }) } From 4422a9d2c7cd275cebc05f644a3079b29fec4e44 Mon Sep 17 00:00:00 2001 From: red binder Date: Sun, 10 May 2026 10:43:29 +0200 Subject: [PATCH 2/2] Use cargo chef --- Dockerfile | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c1b107..b518a60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,32 @@ # syntax=docker/dockerfile:1 - -FROM rust:alpine as builder - -RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static protobuf-dev lld perl make - +FROM rust:alpine AS chef +RUN apk add --no-cache musl-dev lld g++ make perl openssl-dev openssl-libs-static protobuf-dev +RUN cargo install cargo-chef WORKDIR /app -COPY Cargo.toml Cargo.lock ./ -COPY mii ./mii -RUN mkdir src && echo "fn main() {println!(\"dummy\");}" > src/main.rs -RUN OPENSSL_LIB_DIR=/usr/lib OPENSSL_INCLUDE_DIR=/usr/include/openssl OPENSSL_STATIC=1 RUSTFLAGS="-C target-feature=+aes,+sse -C relocation-model=static -C linker=ld.lld" cargo build --target x86_64-unknown-linux-musl --profile prod - +FROM chef AS planner COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN touch src/main.rs +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json ENV SQLX_OFFLINE=true -RUN RUSTFLAGS="-C target-feature=+aes,+sse -C relocation-model=static -C linker=ld.lld" cargo build --profile prod --target x86_64-unknown-linux-musl +ENV RUSTFLAGS="-C target-feature=+aes,+sse -C relocation-model=static -C linker=ld.lld" + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/app/target \ + cargo chef cook --profile prod --recipe-path recipe.json --target x86_64-unknown-linux-musl + +COPY . . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/app/target \ + cargo build --profile prod --target x86_64-unknown-linux-musl && \ + mkdir -p /app/dist && \ + cp /app/target/x86_64-unknown-linux-musl/prod/account /app/dist/ FROM scratch AS final - WORKDIR / - -# Copy the compiled binary from the builder stage -COPY --from=builder /app/target/x86_64-unknown-linux-musl/prod/account /account +COPY --from=builder /app/dist/account /account COPY --from=builder /app/res /res - -# Set executable permissions -# RUN chmod +x /account - -# Command to run the application -ENTRYPOINT ["/account"] +ENTRYPOINT ["/account"] \ No newline at end of file