Skip to main content

Mountain/IPC/WindAirCommands/
IndexFiles.rs

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