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
16	patterns:Vec<String>,
17
18	exclude_patterns:Option<Vec<String>>,
19
20	max_depth:Option<u32>,
21) -> Result<IndexResultDTO::Struct, String> {
22	dev_log!(
23		"grpc",
24		"[WindAirCommands] IndexFiles called: {} with patterns: {:?}",
25		path,
26		patterns
27	);
28
29	let air_address = GetAirAddress::Fn()?;
30
31	let client = GetOrCreateAirClient::Fn(air_address).await?;
32
33	let request_id = uuid::Uuid::new_v4().to_string();
34
35	let index_info = client
36		.index_files(
37			request_id,
38			path,
39			patterns,
40			exclude_patterns.unwrap_or_default(),
41			max_depth.unwrap_or(100),
42		)
43		.await
44		.map_err(|e| format!("File indexing failed: {:?}", e))?;
45
46	let result = IndexResultDTO::Struct {
47		success:true,
48
49		files_indexed:index_info.files_indexed,
50
51		total_size:index_info.total_size,
52	};
53
54	dev_log!(
55		"grpc",
56		"[WindAirCommands] File indexing completed: {} files",
57		result.files_indexed
58	);
59
60	Ok(result)
61}