From d5d79a73a2c832cced481d62ed24e6a74277969a Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 11 Aug 2026 22:27:37 -0400 Subject: [PATCH] Server config --- .gitignore | 3 +++ src/config.rs | 35 +++++++++++++++++++++++++++++++++++ src/main.rs | 1 + src/protocol/mod.rs | 6 ++++++ src/server.rs | 4 +++- 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/config.rs diff --git a/.gitignore b/.gitignore index 0728338..57c39e9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ target # Added by cargo /target + +private.key +config.json diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..656a55d --- /dev/null +++ b/src/config.rs @@ -0,0 +1,35 @@ +use std::path::PathBuf; + +use serde::{Deserialize, Serialize}; + +use crate::protocol::ServerMeta; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub meta: ServerMeta, +} + +impl Config { + pub fn new() -> Self { + Self { + meta: ServerMeta { + name: "New Server".to_string(), + description: String::new(), + }, + } + } + + pub async fn get() -> anyhow::Result { + let config_path = PathBuf::from("config.json"); + + if !config_path.exists() { + let config = Config::new(); + tokio::fs::write(config_path, &serde_json::to_string_pretty(&config)?).await?; + Ok(config) + } else { + Ok(serde_json::from_str( + &tokio::fs::read_to_string(config_path).await?, + )?) + } + } +} diff --git a/src/main.rs b/src/main.rs index 5acf2b6..26aaa8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +pub mod config; pub mod protocol; pub mod server; pub mod signature; diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 1bd8dfa..e7ead39 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -14,6 +14,12 @@ pub struct Client { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ClientMeta {} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerMeta { + pub name: String, + pub description: String, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "method")] pub enum ClientMethod { diff --git a/src/server.rs b/src/server.rs index eff425d..c57c2b3 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,16 +6,18 @@ use axum::{ }; use ed25519_dalek::SigningKey; -use crate::protocol::Client; +use crate::{config::Config, protocol::Client}; pub struct Server { pub key: SigningKey, + pub config: Config, } impl Server { pub async fn new() -> anyhow::Result> { Ok(Arc::new(Self { key: crate::signature::get().await?, + config: Config::get().await?, })) } }