Browse Source

Now with 100% more dynamic dispatching!

master
Julio Biason 5 years ago
parent
commit
279432fbd4
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 20
      src/main.rs
  4. 7
      src/storage/data.rs

2
Cargo.lock generated

@ -260,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "downfav" name = "downfav"
version = "0.3.1" version = "0.3.2"
dependencies = [ dependencies = [
"elefren 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "html2md 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",

2
Cargo.toml

@ -1,6 +1,6 @@
[package] [package]
name = "downfav" name = "downfav"
version = "0.3.1" version = "0.3.2"
authors = ["Julio Biason <julio.biason@pm.me>"] authors = ["Julio Biason <julio.biason@pm.me>"]
edition = "2018" edition = "2018"

20
src/main.rs

@ -25,6 +25,7 @@ use elefren::prelude::*;
use crate::storage::data::Data; use crate::storage::data::Data;
use crate::storage::filesystem::Filesystem; use crate::storage::filesystem::Filesystem;
use crate::storage::joplin::Joplin; use crate::storage::joplin::Joplin;
use crate::storage::storage::Storage;
mod config; mod config;
mod storage; mod storage;
@ -33,12 +34,17 @@ fn main() {
let config = dbg!(config::Config::get()); let config = dbg!(config::Config::get());
let client = dbg!(get_mastodon_connection()); let client = dbg!(get_mastodon_connection());
let top = dbg!(config.last_favorite.to_string()); let top = dbg!(config.last_favorite.to_string());
let joplin_storage = if let Some(joplin_config) = &config.joplin { // let joplin_storage = if let Some(joplin_config) = &config.joplin {
Some(Joplin::new_from_config(&joplin_config)) // Some(Joplin::new_from_config(&joplin_config))
// } else {
// None
// };
// let fs_storage = Filesystem::new();
let storage: Box<dyn Storage> = if let Some(joplin) = &config.joplin {
Box::new(Joplin::new_from_config(&joplin))
} else { } else {
None Box::new(Filesystem::new())
}; };
let fs_storage = Filesystem::new();
let most_recent_favourite = client let most_recent_favourite = client
.favourites() .favourites()
@ -47,11 +53,7 @@ fn main() {
.take_while(|record| dbg!(record).id != top) .take_while(|record| dbg!(record).id != top)
.map(|record| { .map(|record| {
let conversion = dbg!(Data::from(dbg!(&record))); let conversion = dbg!(Data::from(dbg!(&record)));
if let Some(joplin) = &joplin_storage { storage.save(&conversion);
conversion.save(joplin);
} else {
conversion.save(&fs_storage);
}
record record
}) })
.fold(None, { .fold(None, {

7
src/storage/data.rs

@ -22,7 +22,6 @@ use elefren::entities::status::Status;
use html2md; use html2md;
use crate::storage::attachment::Attachment; use crate::storage::attachment::Attachment;
use crate::storage::storage::Storage;
/// Our data content. /// Our data content.
#[derive(Debug)] #[derive(Debug)]
@ -53,12 +52,6 @@ impl From<&Status> for Data {
} }
} }
impl Data {
pub fn save<T: Storage>(&self, storage: &T) {
storage.save(self);
}
}
fn build_text(status: &Status) -> String { fn build_text(status: &Status) -> String {
let base_content = html2md::parse_html(&status.content); let base_content = html2md::parse_html(&status.content);
let source = &status.url; let source = &status.url;

Loading…
Cancel
Save