Added FTPS backups
+ Made remote backups more generic, should be easier to add new backup types in the future + General cleanup + clippy + fmt
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
mod remote;
|
||||
|
||||
use crate::config::remote::{FTPSConfig, SFTPConfig};
|
||||
use config::{Config, ConfigError, File};
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// World types supported
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub enum WorldType {
|
||||
/// The End (DIM1)
|
||||
END,
|
||||
/// Nether (DIM-1)
|
||||
NETHER,
|
||||
/// Overworld
|
||||
OVERWORLD,
|
||||
}
|
||||
|
||||
impl From<String> for WorldType {
|
||||
/// Convert config strings to WorldType
|
||||
fn from(string: String) -> Self {
|
||||
match string.as_str() {
|
||||
"END" => WorldType::END,
|
||||
"NETHER" => WorldType::NETHER,
|
||||
_ => WorldType::OVERWORLD,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Config for individual world configuration
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct WorldConfig {
|
||||
pub world_name: String,
|
||||
pub save_radius: u64,
|
||||
pub world_type: Option<WorldType>,
|
||||
}
|
||||
|
||||
/// Config for doing backups
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct BackupConfig {
|
||||
pub minecraft_dir: PathBuf,
|
||||
pub output_dir: PathBuf,
|
||||
pub backups_to_keep: u64,
|
||||
pub discord_webhook: Option<String>,
|
||||
}
|
||||
|
||||
/// Config for remote backups
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct RemoteBackupConfig {
|
||||
pub backups_to_keep: u64,
|
||||
pub sftp: Option<SFTPConfig>,
|
||||
pub ftps: Option<FTPSConfig>,
|
||||
}
|
||||
|
||||
/// Configs
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct AlbatrossConfig {
|
||||
pub backup: BackupConfig,
|
||||
pub world_config: Option<Vec<WorldConfig>>,
|
||||
pub remote: Option<RemoteBackupConfig>,
|
||||
}
|
||||
|
||||
impl AlbatrossConfig {
|
||||
/// Create new backup from file
|
||||
pub fn new(config_path: &str) -> Result<Self, ConfigError> {
|
||||
let mut cfg = Config::new();
|
||||
cfg.merge(File::with_name(config_path))?;
|
||||
|
||||
cfg.try_into()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user