pub mod db; use std::path::{Path, PathBuf}; use color_eyre::eyre::eyre; use color_eyre::owo_colors::OwoColorize; use tokio::fs; 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?; } if !APP_DATA_DIR.exists() { fs::create_dir_all(APP_DATA_DIR.as_path()).await?; } if !DLSITE_IMG_FOLDER.exists() { fs::create_dir_all(DLSITE_IMG_FOLDER.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<&Path>) -> color_eyre::Result> { let mut folders: Vec = Vec::new(); for path in paths { let path = path.to_path_buf(); if !path.exists() { return Err(eyre!("{:?} {}", path.blue(), "does not exist".red())); } let mut dirs = fs::read_dir(path).await?; while let Some(dir) = dirs.next_entry().await? { folders.push(dir.path()); } } Ok(folders) }