Browse Source

Here's an idea: Move backends to their own modules

Instead of having a bunch of things in "storage", let's have a
"filesystem" module, with its configuration and backend; let's have a
"joplin" module, with its configuration and backend; and so on.
master
Julio Biason 3 years ago
parent
commit
e9d781b155
  1. 5
      src/config/config.rs
  2. 27
      src/filesystem/config.rs
  3. 2
      src/filesystem/mod.rs
  4. 3
      src/filesystem/storage.rs
  5. 5
      src/main.rs
  6. 1
      src/storage/mod.rs

5
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<Favourite>,
mastodon: Data,
filesystem: Option<FilesystemConfig>,
// joplin: Option<JoplinConfig>,
// org: Option<OrgConfig>,
}
/// 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);
}

27
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 <https://www.gnu.org/licenses/>.
*/
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,
}

2
src/filesystem/mod.rs

@ -0,0 +1,2 @@
pub mod config;
pub mod storage;

3
src/storage/filesystem.rs → 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.

5
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

1
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;

Loading…
Cancel
Save