Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindAirCommands/
IndexFiles.rs

1//! `IndexFiles` Tauri command - kick off a directory index
2//! pass on the Air daemon, with include / exclude globs and
3//! a depth cap.
4
5use crate::{
6	IPC::WindAirCommands::{GetAirAddress, GetOrCreateAirClient, IndexResultDTO},
7	dev_log,
8};
9
10#[tauri::command]
11pub async fn IndexFiles(
12	path:String,
13
14	patterns:Vec<String>,
15
16	exclude_patterns:Option<Vec<String>>,
17
18	max_depth:Option<u32>,
19) -> Result<IndexResultDTO::Struct, String> {
20	dev_log!(
21		"grpc",
22		"[WindAirCommands] IndexFiles called: {} with patterns: {:?}",
23		path,
24		patterns
25	);
26
27	let air_address = GetAirAddress::Fn()?;
28
29	let client = GetOrCreateAirClient::Fn(air_address).await?;
30
31	let request_id = uuid::Uuid::new_v4().to_string();
32
33	let index_info = client
34		.index_files(
35			request_id,
36			path,
37			patterns,
38			exclude_patterns.unwrap_or_default(),
39			max_depth.unwrap_or(100),
40		)
41		.await
42		.map_err(|e| format!("File indexing failed: {:?}", e))?;
43
44	let result = IndexResultDTO::Struct {
45		success:true,
46
47		files_indexed:index_info.files_indexed,
48
49		total_size:index_info.total_size,
50	};
51
52	dev_log!(
53		"grpc",
54		"[WindAirCommands] File indexing completed: {} files",
55		result.files_indexed
56	);
57
58	Ok(result)
59}