69 lines
1.7 KiB
Rust
69 lines
1.7 KiB
Rust
use std::{error::Error};
|
|
use serde_derive::{Deserialize, Serialize};
|
|
use crate::config::PostBody::Description;
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
pub(crate) struct Config {
|
|
pub(crate) instance: String,
|
|
pub(crate) status_post_url: Option<String>,
|
|
pub(crate) config_reload_seconds: u32,
|
|
pub(crate) series: Vec<SeriesConfig>,
|
|
}
|
|
|
|
impl Config {
|
|
pub(crate) fn new() -> Result<Self, Box<dyn Error>> {
|
|
todo!()
|
|
}
|
|
|
|
pub(crate) fn load() -> Result<Self, Box<dyn Error>> {
|
|
let cfg: Self = confy::load_path("./config.toml")?;
|
|
if cfg.instance.is_empty() {
|
|
panic!("config.toml not found!")
|
|
}
|
|
Ok(cfg)
|
|
}
|
|
|
|
pub(crate) fn save() -> Result<(), Box<dyn Error>> {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Config {
|
|
instance: "".to_string(),
|
|
status_post_url: None,
|
|
config_reload_seconds: 21600,
|
|
series: vec![]
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub(crate) struct SeriesConfig {
|
|
pub(crate) slug: String,
|
|
pub(crate) parted: bool,
|
|
pub(crate) prepub_community: PostConfig,
|
|
pub(crate) volume_community: PostConfig,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub(crate) struct PostConfig {
|
|
pub(crate) community_name: String,
|
|
pub(crate) pin_settings: PinConfig,
|
|
pub(crate) post_body: PostBody,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub(crate) struct PinConfig {
|
|
pub(crate) pin_new_post_local: bool,
|
|
pub(crate) pin_new_post_community: bool,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
|
#[serde(tag = "body_type", content = "body_content")]
|
|
pub(crate) enum PostBody {
|
|
None,
|
|
Description,
|
|
Custom(String),
|
|
}
|