rusty_files/server/
models.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3use chrono::{DateTime, Utc};
4
5// ============ Search Models ============
6
7#[derive(Debug, Deserialize)]
8pub struct SearchRequest {
9    pub query: String,
10
11    #[serde(default)]
12    pub mode: SearchMode,
13
14    #[serde(default)]
15    pub filters: SearchFilters,
16
17    #[serde(default = "default_limit")]
18    pub limit: usize,
19
20    #[serde(default)]
21    pub offset: usize,
22}
23
24#[derive(Debug, Deserialize, Serialize, Default)]
25#[serde(rename_all = "lowercase")]
26pub enum SearchMode {
27    #[default]
28    Exact,
29    Fuzzy,
30    Regex,
31    Glob,
32}
33
34#[derive(Debug, Deserialize, Default)]
35pub struct SearchFilters {
36    pub extensions: Option<Vec<String>>,
37    pub size_min: Option<u64>,
38    pub size_max: Option<u64>,
39    pub modified_after: Option<DateTime<Utc>>,
40    pub modified_before: Option<DateTime<Utc>>,
41    pub scope: Option<SearchScope>,
42}
43
44#[derive(Debug, Deserialize, Serialize)]
45#[serde(rename_all = "lowercase")]
46pub enum SearchScope {
47    Name,
48    Path,
49    Content,
50    All,
51}
52
53#[derive(Debug, Serialize)]
54pub struct SearchResponse {
55    pub results: Vec<FileResult>,
56    pub total: usize,
57    pub took_ms: u64,
58    pub has_more: bool,
59}
60
61#[derive(Debug, Serialize, Clone)]
62pub struct FileResult {
63    pub path: PathBuf,
64    pub name: String,
65    pub size: u64,
66    pub modified: DateTime<Utc>,
67    pub file_type: FileType,
68    pub score: f32,
69
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub content_preview: Option<String>,
72}
73
74#[derive(Debug, Serialize, Clone)]
75#[serde(rename_all = "lowercase")]
76pub enum FileType {
77    File,
78    Directory,
79    Symlink,
80}
81
82// ============ Index Models ============
83
84#[derive(Debug, Deserialize)]
85pub struct IndexRequest {
86    pub path: PathBuf,
87
88    #[serde(default)]
89    pub recursive: bool,
90
91    #[serde(default)]
92    pub follow_symlinks: bool,
93
94    #[serde(default)]
95    pub exclusions: Vec<String>,
96}
97
98#[derive(Debug, Serialize)]
99pub struct IndexResponse {
100    pub indexed_count: usize,
101    pub skipped_count: usize,
102    pub error_count: usize,
103    pub took_ms: u64,
104    pub status: IndexStatus,
105}
106
107#[derive(Debug, Serialize)]
108#[serde(rename_all = "lowercase")]
109pub enum IndexStatus {
110    Completed,
111    Partial,
112    Failed,
113}
114
115#[derive(Debug, Serialize)]
116pub struct IndexProgress {
117    pub current: usize,
118    pub total: usize,
119    pub current_path: PathBuf,
120    pub percentage: f32,
121}
122
123// ============ Update Models ============
124
125#[derive(Debug, Deserialize)]
126pub struct UpdateRequest {
127    pub path: PathBuf,
128}
129
130#[derive(Debug, Serialize)]
131pub struct UpdateResponse {
132    pub added: usize,
133    pub updated: usize,
134    pub removed: usize,
135    pub took_ms: u64,
136}
137
138// ============ Watch Models ============
139
140#[derive(Debug, Deserialize)]
141pub struct WatchRequest {
142    pub path: PathBuf,
143
144    #[serde(default)]
145    pub recursive: bool,
146}
147
148#[derive(Debug, Serialize)]
149pub struct WatchResponse {
150    pub watch_id: String,
151    pub path: PathBuf,
152    pub status: String,
153}
154
155#[derive(Debug, Serialize, Clone)]
156pub struct FileChangeEvent {
157    pub event_type: FileEventType,
158    pub path: PathBuf,
159    pub timestamp: DateTime<Utc>,
160}
161
162#[derive(Debug, Serialize, Deserialize, Clone)]
163#[serde(rename_all = "lowercase")]
164pub enum FileEventType {
165    Created,
166    Modified,
167    Deleted,
168    Renamed,
169}
170
171// ============ Stats Models ============
172
173#[derive(Debug, Serialize)]
174pub struct StatsResponse {
175    pub total_files: usize,
176    pub total_directories: usize,
177    pub total_size: u64,
178    pub index_size_mb: f64,
179    pub last_update: Option<DateTime<Utc>>,
180    pub uptime_seconds: u64,
181    pub performance: PerformanceStats,
182}
183
184#[derive(Debug, Serialize)]
185pub struct PerformanceStats {
186    pub total_searches: u64,
187    pub avg_search_time_ms: f64,
188    pub cache_hit_rate: f32,
189    pub memory_usage_mb: f64,
190}
191
192// ============ Health Models ============
193
194#[derive(Debug, Serialize)]
195pub struct HealthResponse {
196    pub status: HealthStatus,
197    pub version: String,
198    pub uptime_seconds: u64,
199    pub checks: Vec<HealthCheck>,
200}
201
202#[derive(Debug, Serialize, Clone)]
203#[serde(rename_all = "lowercase")]
204pub enum HealthStatus {
205    Healthy,
206    Degraded,
207    Unhealthy,
208}
209
210#[derive(Debug, Serialize)]
211pub struct HealthCheck {
212    pub name: String,
213    pub status: HealthStatus,
214    pub message: Option<String>,
215    pub response_time_ms: Option<u64>,
216}
217
218// ============ Error Models ============
219
220#[derive(Debug, Serialize)]
221pub struct ErrorResponse {
222    pub error: String,
223    pub message: String,
224    pub code: u16,
225
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub details: Option<serde_json::Value>,
228}
229
230// ============ Utilities ============
231
232fn default_limit() -> usize {
233    100
234}