Files
sus-manager/ui/src/helpers/mod.rs
2025-12-14 21:34:06 +08:00

35 lines
1.0 KiB
Rust
Executable File

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)
}