fixed formatting
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use colored::*;
|
||||
use futures::future::join_all;
|
||||
use crate::cli::Args;
|
||||
use crate::settings::Config;
|
||||
use crate::files::{execute_move, FileBatch, is_text_file, read_file_sample};
|
||||
use crate::files::{FileBatch, execute_move, is_text_file, read_file_sample};
|
||||
use crate::gemini::GeminiClient;
|
||||
use crate::models::OrganizationPlan;
|
||||
use crate::settings::Config;
|
||||
use crate::storage::{Cache, UndoLog};
|
||||
use colored::*;
|
||||
use futures::future::join_all;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -137,35 +137,38 @@ pub async fn handle_organization(
|
||||
);
|
||||
|
||||
let client_arc: Arc<GeminiClient> = Arc::new(client);
|
||||
let semaphore: Arc<tokio::sync::Semaphore> = Arc::new(tokio::sync::Semaphore::new(args.max_concurrent));
|
||||
let semaphore: Arc<tokio::sync::Semaphore> =
|
||||
Arc::new(tokio::sync::Semaphore::new(args.max_concurrent));
|
||||
|
||||
let tasks: Vec<_> = plan
|
||||
.files
|
||||
.iter_mut()
|
||||
.zip(batch.paths.iter())
|
||||
.map(|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| {
|
||||
let client: Arc<GeminiClient> = Arc::clone(&client_arc);
|
||||
let filename: String = file_category.filename.clone();
|
||||
let category: String = file_category.category.clone();
|
||||
let path: PathBuf = path.clone();
|
||||
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore);
|
||||
.map(
|
||||
|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| {
|
||||
let client: Arc<GeminiClient> = Arc::clone(&client_arc);
|
||||
let filename: String = file_category.filename.clone();
|
||||
let category: String = file_category.category.clone();
|
||||
let path: PathBuf = path.clone();
|
||||
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore);
|
||||
|
||||
async move {
|
||||
if is_text_file(&path) {
|
||||
let _permit = semaphore.acquire().await.unwrap();
|
||||
if let Some(content) = read_file_sample(&path, 5000) {
|
||||
println!("Reading content of {}...", filename.green());
|
||||
client
|
||||
.get_ai_sub_category(&filename, &category, &content)
|
||||
.await
|
||||
async move {
|
||||
if is_text_file(&path) {
|
||||
let _permit = semaphore.acquire().await.unwrap();
|
||||
if let Some(content) = read_file_sample(&path, 5000) {
|
||||
println!("Reading content of {}...", filename.green());
|
||||
client
|
||||
.get_ai_sub_category(&filename, &category, &content)
|
||||
.await
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
.collect();
|
||||
|
||||
let sub_categories: Vec<String> = join_all(tasks).await;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use colored::*;
|
||||
use crate::models::OrganizationPlan;
|
||||
use crate::storage::UndoLog;
|
||||
use colored::*;
|
||||
use std::io;
|
||||
use std::{ffi::OsStr, fs, path::Path};
|
||||
|
||||
pub fn execute_move(
|
||||
base_path: &Path,
|
||||
plan: OrganizationPlan,
|
||||
mut undo_log: Option<&mut UndoLog>,
|
||||
) {
|
||||
pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Option<&mut UndoLog>) {
|
||||
println!("\n{}", "--- EXECUTION PLAN ---".bold().underline());
|
||||
|
||||
if plan.files.is_empty() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use colored::*;
|
||||
use crate::storage::UndoLog;
|
||||
use colored::*;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::models::OrganizationPlan;
|
||||
use crate::storage::Cache;
|
||||
use crate::gemini::errors::GeminiError;
|
||||
use crate::gemini::prompt::PromptBuilder;
|
||||
use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse};
|
||||
use crate::models::OrganizationPlan;
|
||||
use crate::storage::Cache;
|
||||
use reqwest::Client;
|
||||
use serde_json::json;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -5,4 +5,6 @@ pub mod types;
|
||||
|
||||
pub use client::GeminiClient;
|
||||
pub use errors::GeminiError;
|
||||
pub use types::{Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part};
|
||||
pub use types::{
|
||||
Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::models::{FileCategory, OrganizationPlan};
|
||||
use crate::gemini::types::OrganizationPlanResponse;
|
||||
use crate::models::{FileCategory, OrganizationPlan};
|
||||
|
||||
impl OrganizationPlanResponse {
|
||||
pub fn to_organization_plan(self) -> OrganizationPlan {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
pub mod cli;
|
||||
pub mod settings;
|
||||
pub mod files;
|
||||
pub mod gemini;
|
||||
pub mod models;
|
||||
pub mod settings;
|
||||
pub mod storage;
|
||||
|
||||
pub use cli::Args;
|
||||
pub use settings::Config;
|
||||
pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves};
|
||||
pub use gemini::GeminiClient;
|
||||
pub use gemini::GeminiError;
|
||||
pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan};
|
||||
pub use settings::Config;
|
||||
pub use storage::{Cache, UndoLog};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use noentropy::cli::{Args, orchestrator::{handle_organization, handle_undo}};
|
||||
use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder};
|
||||
use clap::Parser;
|
||||
use noentropy::cli::{
|
||||
Args,
|
||||
orchestrator::{handle_organization, handle_undo},
|
||||
};
|
||||
use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod organization;
|
||||
pub mod metadata;
|
||||
pub mod move_record;
|
||||
pub mod organization;
|
||||
|
||||
pub use organization::{FileCategory, OrganizationPlan};
|
||||
pub use metadata::{CacheEntry, FileMetadata};
|
||||
pub use move_record::{FileMoveRecord, MoveStatus};
|
||||
pub use organization::{FileCategory, OrganizationPlan};
|
||||
|
||||
@@ -136,4 +136,3 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ fn test_validate_api_key_invalid() {
|
||||
#[test]
|
||||
fn test_validate_folder_path_valid() {
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
assert!(Prompter::validate_folder_path(
|
||||
temp_dir.path()
|
||||
));
|
||||
assert!(Prompter::validate_folder_path(temp_dir.path()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -52,9 +50,7 @@ fn test_validate_folder_path_invalid() {
|
||||
)));
|
||||
|
||||
let temp_file = tempfile::NamedTempFile::new().unwrap();
|
||||
assert!(!Prompter::validate_folder_path(
|
||||
temp_file.path()
|
||||
));
|
||||
assert!(!Prompter::validate_folder_path(temp_file.path()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -199,4 +199,3 @@ impl Cache {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ pub use undo_log::UndoLog;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::storage::{Cache, UndoLog};
|
||||
use crate::models::{FileMoveRecord, MoveStatus};
|
||||
use crate::storage::{Cache, UndoLog};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
@@ -79,7 +79,7 @@ mod tests {
|
||||
let record = FileMoveRecord::new(
|
||||
PathBuf::from("/from"),
|
||||
PathBuf::from("/to"),
|
||||
MoveStatus::Completed
|
||||
MoveStatus::Completed,
|
||||
);
|
||||
assert_eq!(record.status, MoveStatus::Completed);
|
||||
}
|
||||
|
||||
@@ -179,4 +179,3 @@ impl UndoLog {
|
||||
usage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user