refactor: rewrite in rust
All checks were successful
Continuous Integration / Lint, Check & Test (push) Successful in 1m38s
Continuous Integration / Build Package (push) Successful in 1m54s

This commit is contained in:
Konstantin Fickel 2026-03-29 18:19:15 +02:00
parent 20a3e8b437
commit ed493cff29
Signed by: kfickel
GPG key ID: A793722F9933C1A5
72 changed files with 5684 additions and 3688 deletions

44
src/config.rs Normal file
View file

@ -0,0 +1,44 @@
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
use std::env;
use std::fs;
use std::path::PathBuf;
use crate::error::StreamdError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Settings {
pub base_folder: String,
}
impl Default for Settings {
fn default() -> Self {
Self {
base_folder: env::current_dir()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|_| ".".to_string()),
}
}
}
impl Settings {
pub fn load() -> Result<Self, StreamdError> {
let config_path = Self::config_path();
if config_path.exists() {
let content = fs::read_to_string(&config_path)?;
let settings: Settings = serde_yaml::from_str(&content)?;
Ok(settings)
} else {
Ok(Settings::default())
}
}
fn config_path() -> PathBuf {
if let Some(proj_dirs) = ProjectDirs::from("", "", "streamd") {
proj_dirs.config_dir().join("config.yaml")
} else {
PathBuf::from("~/.config/streamd/config.yaml")
}
}
}