use crate::database::db::PdfDatabase;
use crate::indexer::scanner::scan_directory;
use dirs;
use std::path::Path;
pub fn init_command(dir_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
let db_path = get_database_path()?;
let db = PdfDatabase::new(&db_path)?;
scan_directory(dir_path, &db)?;
println!(
"\nIndexed {} PDFs in {}\n",
db.count_pdfs()?,
db_path.display()
);
Ok(())
}
pub fn search_command(query: &str) -> Result<(), Box<dyn std::error::Error>> {
println!("đ Search not implemented yet: '{}'", query);
Ok(())
}
pub fn recent_command(limit: i32) -> Result<(), Box<dyn std::error::Error>> {
println!("đ
Recent not implemented yet (limit: {})", limit);
Ok(())
}
pub fn list_command(all: bool) -> Result<(), Box<dyn std::error::Error>> {
println!("đ List not implemented yet (all: {})", all);
Ok(())
}
pub fn cleanup_command() -> Result<(), Box<dyn std::error::Error>> {
let data_dir = dirs::data_dir().expect("Failed to get data directory");
let pdfx_dir = data_dir.join("pdfx");
if pdfx_dir.exists() {
std::fs::remove_dir_all(&pdfx_dir)?;
println!(
"\nâ
Cleaned up pdfx data directory: {}\n",
pdfx_dir.display()
);
println!("đī¸ Removed database and all indexed data\n");
} else {
println!("\nâšī¸ No pdfx data found to clean up\n");
}
Ok(())
}
fn get_database_path() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
let data_dir = dirs::data_dir().expect("Failed to get data directory");
let pdfx_dir = data_dir.join("pdfx");
std::fs::create_dir_all(&pdfx_dir)?;
let db_path = pdfx_dir.join("db.sqlite");
Ok(db_path)
}