Refactor structure
This commit is contained in:
35
ui/src/helpers/mod.rs
Executable file
35
ui/src/helpers/mod.rs
Executable file
@@ -0,0 +1,35 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use tokio::fs;
|
||||
use crawler::DLSITE_IMG_FOLDER;
|
||||
use models::{APP_CONFIG_DIR, APP_DATA_DIR};
|
||||
|
||||
pub async fn initialize_folders() -> color_eyre::Result<()> {
|
||||
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?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_all_folders(paths: &[&Path]) -> color_eyre::Result<Vec<PathBuf>> {
|
||||
let mut folders: Vec<PathBuf> = 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)
|
||||
}
|
||||
Reference in New Issue
Block a user