diff --git a/Cargo.lock b/Cargo.lock index 5a7b726..5f5e93d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "downfav" -version = "0.3.1" +version = "0.3.2" dependencies = [ "elefren 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "html2md 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 63e12c9..0e26f14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "downfav" -version = "0.3.1" +version = "0.3.2" authors = ["Julio Biason "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 44180bc..7b74521 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ use elefren::prelude::*; use crate::storage::data::Data; use crate::storage::filesystem::Filesystem; use crate::storage::joplin::Joplin; +use crate::storage::storage::Storage; mod config; mod storage; @@ -33,12 +34,17 @@ fn main() { let config = dbg!(config::Config::get()); let client = dbg!(get_mastodon_connection()); let top = dbg!(config.last_favorite.to_string()); - let joplin_storage = if let Some(joplin_config) = &config.joplin { - Some(Joplin::new_from_config(&joplin_config)) + // let joplin_storage = if let Some(joplin_config) = &config.joplin { + // Some(Joplin::new_from_config(&joplin_config)) + // } else { + // None + // }; + // let fs_storage = Filesystem::new(); + let storage: Box = if let Some(joplin) = &config.joplin { + Box::new(Joplin::new_from_config(&joplin)) } else { - None + Box::new(Filesystem::new()) }; - let fs_storage = Filesystem::new(); let most_recent_favourite = client .favourites() @@ -47,11 +53,7 @@ fn main() { .take_while(|record| dbg!(record).id != top) .map(|record| { let conversion = dbg!(Data::from(dbg!(&record))); - if let Some(joplin) = &joplin_storage { - conversion.save(joplin); - } else { - conversion.save(&fs_storage); - } + storage.save(&conversion); record }) .fold(None, { diff --git a/src/storage/data.rs b/src/storage/data.rs index d5be3fb..eb31393 100644 --- a/src/storage/data.rs +++ b/src/storage/data.rs @@ -22,7 +22,6 @@ use elefren::entities::status::Status; use html2md; use crate::storage::attachment::Attachment; -use crate::storage::storage::Storage; /// Our data content. #[derive(Debug)] @@ -53,12 +52,6 @@ impl From<&Status> for Data { } } -impl Data { - pub fn save(&self, storage: &T) { - storage.save(self); - } -} - fn build_text(status: &Status) -> String { let base_content = html2md::parse_html(&status.content); let source = &status.url;