Refactor config
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
pub mod db;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use tokio::fs;
|
||||
use crate::constants::{APP_CONFIG_DIR, APP_DATA_DIR, APP_DB_DATA_DIR};
|
||||
use crate::config::types::ApplicationConfig;
|
||||
use crate::constants::{APP_CONFIG_DIR, APP_DATA_DIR};
|
||||
use crate::crawler::DLSITE_IMG_FOLDER;
|
||||
|
||||
|
||||
pub async fn initialize_folders() -> color_eyre::Result<()> {
|
||||
let app_conf = ApplicationConfig::get_config()?;
|
||||
if !APP_CONFIG_DIR.exists() {
|
||||
fs::create_dir_all(APP_CONFIG_DIR.as_path()).await?;
|
||||
}
|
||||
@@ -18,16 +20,17 @@ pub async fn initialize_folders() -> color_eyre::Result<()> {
|
||||
if !DLSITE_IMG_FOLDER.exists() {
|
||||
fs::create_dir_all(DLSITE_IMG_FOLDER.as_path()).await?;
|
||||
}
|
||||
if !APP_DB_DATA_DIR.exists() {
|
||||
fs::create_dir_all(APP_DB_DATA_DIR.as_path()).await?;
|
||||
let db_path = Path::new(&app_conf.basic_config.db_path);
|
||||
if !db_path.exists() {
|
||||
fs::create_dir_all(db_path).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_all_folders(paths: &Vec<PathBuf>) -> color_eyre::Result<Vec<PathBuf>> {
|
||||
pub async fn get_all_folders(paths: Vec<&Path>) -> color_eyre::Result<Vec<PathBuf>> {
|
||||
let mut folders: Vec<PathBuf> = Vec::new();
|
||||
for path in paths {
|
||||
let path = path.as_path();
|
||||
let path = path.to_path_buf();
|
||||
if !path.exists() {
|
||||
return Err(eyre!("{:?} {}", path.blue(), "does not exist".red()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user