diff --git a/src/config/config.rs b/src/config/config.rs index 4d86f38..8214b1b 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -27,6 +27,7 @@ use serde_derive::Deserialize; use serde_derive::Serialize; use crate::config::errors::ConfigError; +use crate::filesystem::config::FilesystemConfig; /// The last seen favourite #[derive(Serialize, Deserialize, Debug)] @@ -39,6 +40,9 @@ struct Favourite { struct AccountConfig { favourite: Option, mastodon: Data, + filesystem: Option, + // joplin: Option, + // org: Option, } /// The main configuration @@ -75,6 +79,7 @@ impl Config { let account_data = AccountConfig { favourite: None, mastodon: configuration, + filesystem: None, }; self.0.insert(name.into(), account_data); } diff --git a/src/filesystem/config.rs b/src/filesystem/config.rs new file mode 100644 index 0000000..a89518a --- /dev/null +++ b/src/filesystem/config.rs @@ -0,0 +1,27 @@ +/* + DOWNFAV - Download Favourites + Copyright (C) 2020 Julio Biason + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +use serde_derive::Deserialize; +use serde_derive::Serialize; + +/// Configuration for the Filesystem backend +#[derive(Serialize, Deserialize, Debug)] +pub struct FilesystemConfig { + /// Path where files will be stored. + pub path: String, +} diff --git a/src/filesystem/mod.rs b/src/filesystem/mod.rs new file mode 100644 index 0000000..d5c5ab2 --- /dev/null +++ b/src/filesystem/mod.rs @@ -0,0 +1,2 @@ +pub mod config; +pub mod storage; diff --git a/src/storage/filesystem.rs b/src/filesystem/storage.rs similarity index 95% rename from src/storage/filesystem.rs rename to src/filesystem/storage.rs index 6c68109..75f1d02 100644 --- a/src/storage/filesystem.rs +++ b/src/filesystem/storage.rs @@ -47,7 +47,8 @@ impl Filesystem { /// Make sure the path structure exists for saving the data. fn create_dirs(&self, data: &Data) { - std::fs::create_dir_all(self.dir(data)).expect("Failed to create storage directory"); + std::fs::create_dir_all(self.dir(data)) + .expect("Failed to create storage directory"); } /// Save the content in the directory. diff --git a/src/main.rs b/src/main.rs index c92b4e4..018ee18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,14 +21,15 @@ use std::io; use elefren::helpers::cli; use elefren::prelude::*; +use crate::filesystem::storage::Filesystem; use crate::storage::data::Data; -use crate::storage::filesystem::Filesystem; use crate::storage::joplin::Joplin; use crate::storage::org::Org; use crate::storage::storage::Storage; mod args; mod config; +mod filesystem; mod storage; fn main() { @@ -46,7 +47,7 @@ fn add_account(name: &str) { let mut config = config::config::Config::open().unwrap(); let connection_info = connect_to_mastodon(); config.add_account(name, connection_info); - config.save(); + config.save().unwrap(); } /// Retrieve favourites diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 04fbd0f..1cb83a4 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -18,7 +18,6 @@ pub mod attachment; pub mod data; -pub mod filesystem; pub mod helpers; pub mod joplin; pub mod org;