2025-03-05 20:28:25 +01:00
|
|
|
|
|
|
|
|
|
2025-02-24 10:43:47 +01:00
|
|
|
use std::env;
|
2025-03-09 23:47:46 +01:00
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
2025-02-27 10:25:31 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
2025-02-24 10:43:47 +01:00
|
|
|
use dotenvy::dotenv;
|
2025-03-09 23:47:46 +01:00
|
|
|
use juniper::{EmptyMutation, EmptySubscription};
|
2025-02-27 10:25:31 +01:00
|
|
|
use log::info;
|
2025-02-24 10:43:47 +01:00
|
|
|
use rocket::fairing::AdHoc;
|
2025-03-09 23:47:46 +01:00
|
|
|
use rocket::futures::FutureExt;
|
2025-02-24 10:43:47 +01:00
|
|
|
use rocket::http::Header;
|
2025-02-23 19:33:55 +01:00
|
|
|
use rocket::routes;
|
2025-02-27 10:25:31 +01:00
|
|
|
use sqlx::Postgres;
|
|
|
|
|
use sqlx::postgres::PgPoolOptions;
|
2025-03-09 23:47:46 +01:00
|
|
|
use tonic::transport::Server;
|
|
|
|
|
use crate::graphql::{Query, Schema};
|
2025-02-23 19:33:55 +01:00
|
|
|
|
|
|
|
|
mod xml;
|
|
|
|
|
mod conntest;
|
2025-02-27 10:25:31 +01:00
|
|
|
mod nnid;
|
2025-02-24 10:43:47 +01:00
|
|
|
mod account;
|
2025-02-27 10:25:31 +01:00
|
|
|
mod error;
|
|
|
|
|
mod dsresponse;
|
2025-02-27 21:49:37 +01:00
|
|
|
mod data_wrapper;
|
2025-03-09 23:47:46 +01:00
|
|
|
#[deprecated]
|
2025-03-07 15:14:43 +01:00
|
|
|
mod grpc;
|
2025-03-09 23:47:46 +01:00
|
|
|
mod graphql;
|
2025-04-26 13:38:11 +02:00
|
|
|
mod email;
|
2025-02-27 10:25:31 +01:00
|
|
|
|
|
|
|
|
type Pool = sqlx::Pool<Postgres>;
|
2025-02-23 19:33:55 +01:00
|
|
|
|
2025-03-09 23:47:46 +01:00
|
|
|
async fn start_grpc(){
|
|
|
|
|
let act_database_url = env::var("DATABASE_URL").expect("account database url is not set");
|
|
|
|
|
|
|
|
|
|
let pool = PgPoolOptions::new()
|
|
|
|
|
.max_connections(5)
|
|
|
|
|
.connect(&act_database_url)
|
|
|
|
|
.await
|
|
|
|
|
.expect("unable to create pool");
|
|
|
|
|
|
|
|
|
|
let grpc_instance = grpc::AccountService(pool);
|
|
|
|
|
|
|
|
|
|
let addr: SocketAddr =
|
|
|
|
|
SocketAddr::from((
|
|
|
|
|
env::var("ROCKET_ADDRESS").ok()
|
|
|
|
|
.map(|v| v.parse().expect("unable to read address"))
|
|
|
|
|
.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
|
|
|
|
|
7071
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move{
|
|
|
|
|
Server::builder()
|
|
|
|
|
.add_service(grpc::grpc::account_server::AccountServer::new(grpc_instance))
|
|
|
|
|
.serve(addr)
|
|
|
|
|
.await
|
|
|
|
|
.expect("unable to start grpc server");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 19:33:55 +01:00
|
|
|
#[rocket::launch]
|
|
|
|
|
async fn launch() -> _ {
|
2025-02-24 10:43:47 +01:00
|
|
|
dotenv().ok();
|
|
|
|
|
|
2025-03-09 23:47:46 +01:00
|
|
|
start_grpc().await;
|
2025-02-27 10:25:31 +01:00
|
|
|
|
|
|
|
|
let act_database_url = env::var("DATABASE_URL").expect("account database url is not set");
|
|
|
|
|
|
|
|
|
|
let pool = PgPoolOptions::new()
|
|
|
|
|
.max_connections(5)
|
|
|
|
|
.connect(&act_database_url).await
|
|
|
|
|
.expect("unable to create pool");
|
2025-02-24 10:43:47 +01:00
|
|
|
|
2025-03-09 23:47:46 +01:00
|
|
|
let graph_pool = PgPoolOptions::new()
|
|
|
|
|
.max_connections(5)
|
|
|
|
|
.connect(&act_database_url).await
|
|
|
|
|
.expect("unable to create pool");
|
|
|
|
|
|
2025-02-23 19:33:55 +01:00
|
|
|
rocket::build()
|
2025-02-27 10:25:31 +01:00
|
|
|
.manage(pool)
|
2025-03-09 23:47:46 +01:00
|
|
|
.manage(graphql::Context(graph_pool))
|
|
|
|
|
.manage(Schema::new(
|
|
|
|
|
Query,
|
|
|
|
|
EmptyMutation::new(),
|
|
|
|
|
EmptySubscription::new())
|
|
|
|
|
)
|
2025-02-24 10:43:47 +01:00
|
|
|
.attach(AdHoc::on_response("org", |_, response| Box::pin(async move {
|
2025-02-27 10:25:31 +01:00
|
|
|
//response.adjoin_header(Header::new("x-organization", "Nintendo"));
|
|
|
|
|
response.adjoin_header(Header::new("x-nintendo-date", SystemTime::now()
|
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.as_millis()
|
|
|
|
|
.to_string()
|
|
|
|
|
));
|
|
|
|
|
|
2025-02-27 21:49:37 +01:00
|
|
|
//response.adjoin_header(Header::new("Content-Type", "text/xml; charset=utf-8"));
|
2025-02-27 10:25:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
response.remove_header("x-content-type-options");
|
|
|
|
|
response.remove_header("x-frame-options");
|
|
|
|
|
response.remove_header("permissions-policy");
|
2025-02-24 10:43:47 +01:00
|
|
|
})))
|
2025-02-27 10:25:31 +01:00
|
|
|
.mount("/", routes![
|
|
|
|
|
conntest::conntest,
|
|
|
|
|
nnid::devices::current_device_status,
|
|
|
|
|
nnid::agreements::get_agreement,
|
|
|
|
|
nnid::timezones::get_timezone,
|
|
|
|
|
nnid::person_exists::person_exists,
|
2025-04-26 13:38:11 +02:00
|
|
|
nnid::support::validate,
|
|
|
|
|
nnid::support::verify_email,
|
2025-03-05 20:28:25 +01:00
|
|
|
nnid::people::create_account,
|
|
|
|
|
nnid::people::get_own_profile,
|
2025-04-26 18:17:05 +02:00
|
|
|
nnid::people::get_device_owner,
|
2025-04-26 20:25:49 +02:00
|
|
|
nnid::people::get_own_device,
|
2025-03-07 15:14:43 +01:00
|
|
|
nnid::oauth::generate_token::generate_token,
|
|
|
|
|
nnid::provider::get_nex_token,
|
2025-03-09 23:47:46 +01:00
|
|
|
nnid::provider::get_service_token,
|
|
|
|
|
nnid::mapped_ids::mapped_ids,
|
|
|
|
|
//graphql
|
|
|
|
|
graphql::graphiql,
|
|
|
|
|
graphql::playground,
|
|
|
|
|
graphql::get_graphql,
|
|
|
|
|
graphql::post_graphql,
|
2025-02-27 10:25:31 +01:00
|
|
|
])
|
2025-02-23 19:33:55 +01:00
|
|
|
}
|