Ower creation now gives back prettier output + server meta vars as well

This commit is contained in:
shockrah 2021-02-25 14:03:34 -08:00
parent e893800dab
commit ab1c9e40f7
2 changed files with 17 additions and 11 deletions

View File

@ -158,7 +158,11 @@ async fn attempt_owner_creation(name: &str) {
match response { match response {
db::Response::Row(mut owner) => { db::Response::Row(mut owner) => {
owner.secret = owner_secret; // giving the secret itself back to the user owner.secret = owner_secret; // giving the secret itself back to the user
println!("{}", serde_json::to_string(&owner).expect("SQL query passed but serde couldn't parse the data for some reason")) let server_config = serde_json::json!({
"user": owner,
"server": meta::get_config()
});
println!("{}", serde_json::to_string_pretty(&server_config).unwrap());
}, },
db::Response::Empty => { db::Response::Empty => {
eprintln!("SQL server failed to return owner data, check configs and also the members table to make sure there's nothing there by accident"); eprintln!("SQL server failed to return owner data, check configs and also the members table to make sure there's nothing there by accident");

View File

@ -6,20 +6,22 @@ use serde_json::to_string;
use serde::Serialize; use serde::Serialize;
#[derive( Serialize)] #[derive( Serialize)]
struct Config { pub struct Config {
name: String, pub name: String,
description: String, pub description: String,
hostname: String, pub hostname: String,
port: u16 pub port: u16
} }
pub fn get_config() -> Config {
pub async fn server_meta(response: &mut Response<Body>) { Config {
let payload = Config {
name: var("SERVER_NAME").unwrap_or("No name".into()), name: var("SERVER_NAME").unwrap_or("No name".into()),
description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()), description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()),
hostname: var("SERVER_HOSTNAME").expect("Couldn't get url from environment"), hostname: var("SERVER_HOSTNAME").expect("Couldn't get url from environment"),
port: var("SERVER_PORT").expect("Couldn't get port from environment").parse::<u16>().unwrap(), port: var("SERVER_PORT").expect("Couldn't get port from environment").parse::<u16>().unwrap(),
}; }
*response.body_mut() = Body::from(to_string(&payload).unwrap()); }
pub async fn server_meta(response: &mut Response<Body>) {
*response.body_mut() = Body::from(to_string(&get_config()).unwrap());
} }