Skip to main content

Mountain/IPC/WindAirCommands/
IndexFiles.rs

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