Small QOL changes

This commit is contained in:
Neshura 2023-12-17 20:17:00 +01:00
parent 9a26d2821f
commit d3d61f6602
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 13 additions and 9 deletions

View file

@ -55,7 +55,7 @@ pub(crate) struct SeriesConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct PostConfig { pub(crate) struct PostConfig {
pub(crate) community_name: String, pub(crate) name: String,
pub(crate) pin_settings: PinConfig, pub(crate) pin_settings: PinConfig,
pub(crate) post_body: PostBody, pub(crate) post_body: PostBody,
} }

View file

@ -6,29 +6,33 @@ use std::io::Write;
use std::path::Path; use std::path::Path;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct SeriesHistory { pub(crate) struct SeriesHistory {
pub(crate) series: HashMap<String, PostHistory>, pub(crate) series: HashMap<String, PostHistory>,
} }
impl SeriesHistory { impl SeriesHistory {
pub(crate) fn load_history() -> Result<Option<Self>, Box<dyn Error>> { pub(crate) fn load_history() -> Result<Self, Box<dyn Error>> {
match Path::new("history.toml").exists() { match Path::new("history.toml").exists() {
true => { true => {
let file_contents: String = fs::read_to_string("history.toml")?; let file_contents: String = fs::read_to_string("history.toml")?;
let history: Result<SeriesHistory, toml::de::Error> = match file_contents.len() { let history: Result<SeriesHistory, toml::de::Error> = match file_contents.len() {
0 => return Ok(None), 0 => return Ok(SeriesHistory {
series: HashMap::new(),
}),
_ => toml::from_str(file_contents.as_str()), _ => toml::from_str(file_contents.as_str()),
}; };
match history { match history {
Ok(data) => Ok(Some(data)), Ok(data) => Ok(data),
Err(e) => Err(Box::new(e)) Err(e) => Err(Box::new(e))
} }
}, },
false => { false => {
Ok(None) Ok(SeriesHistory {
series: HashMap::new(),
})
} }
} }
} }
@ -72,9 +76,9 @@ impl SeriesHistory {
} }
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct PostHistory { pub(crate) struct PostHistory {
parts: HashMap<String, PostHistoryInner>, pub(crate) parts: HashMap<String, PostHistoryInner>,
} }
impl PostHistory { impl PostHistory {
@ -96,7 +100,7 @@ impl PostHistory {
} }
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct PostHistoryInner { pub(crate) struct PostHistoryInner {
pub(crate) volume: String, pub(crate) volume: String,
pub(crate) chapter: String, pub(crate) chapter: String,