Server config

This commit is contained in:
2026-08-11 22:27:37 -04:00
parent c910769eb3
commit d5d79a73a2
5 changed files with 48 additions and 1 deletions
+3
View File
@@ -24,3 +24,6 @@ target
# Added by cargo
/target
private.key
config.json
+35
View File
@@ -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<Self> {
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?,
)?)
}
}
}
+1
View File
@@ -1,3 +1,4 @@
pub mod config;
pub mod protocol;
pub mod server;
pub mod signature;
+6
View File
@@ -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 {
+3 -1
View File
@@ -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<Arc<Self>> {
Ok(Arc::new(Self {
key: crate::signature::get().await?,
config: Config::get().await?,
}))
}
}