|
1 | 1 | ## API Documentation |
2 | 2 |
|
3 | | -The Rust backend provides the following commands that can be invoked from the frontend: |
| 3 | +The Rust backend provides the following command that can be invoked from the frontend: |
4 | 4 |
|
5 | | -### 1. get_folders_with_images |
6 | | - |
7 | | -- **Description**: Retrieves folders containing images from a specified directory. |
8 | | -- **Parameters**: |
9 | | - - `directory`: String |
10 | | -- **Returns**: `Vec<PathBuf>` |
11 | | - |
12 | | -### 2. get_images_in_folder |
13 | | - |
14 | | -- **Description**: Gets all images in a specific folder. |
15 | | -- **Parameters**: |
16 | | - - `folder_path`: String |
17 | | -- **Returns**: `Vec<PathBuf>` |
18 | | - |
19 | | -### 3. get_all_images_with_cache |
20 | | - |
21 | | -- **Description**: Retrieves all images from multiple directories, organized by year and month, with caching. |
22 | | -- **Parameters**: |
23 | | - - `directories`: Vec<String> |
24 | | -- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>` |
25 | | - |
26 | | -### 4. get_all_videos_with_cache |
27 | | - |
28 | | -- **Description**: Retrieves all videos from multiple directories, organized by year and month, with caching. |
29 | | -- **Parameters**: |
30 | | - - `directories`: Vec<String> |
31 | | -- **Returns**: `Result<HashMap<u32, HashMap<u32, Vec<String>>>, String>` |
32 | | - |
33 | | -### 5. delete_cache |
34 | | - |
35 | | -- **Description**: Deletes all cached data. |
36 | | -- **Parameters**: None |
37 | | -- **Returns**: `bool` |
38 | | - |
39 | | -### 6. share_file |
40 | | - |
41 | | -- **Description**: Opens the file in the system's default file manager and selects it. |
42 | | -- **Parameters**: |
43 | | - - `path`: String |
44 | | -- **Returns**: `Result<(), String>` |
45 | | - |
46 | | -### 7. save_edited_image |
47 | | - |
48 | | -- **Description**: Saves an edited image with applied filters and adjustments. |
49 | | -- **Parameters**: |
50 | | - - `image_data`: Vec<u8> |
51 | | - - `save_path`: String |
52 | | - - `filter`: String |
53 | | - - `brightness`: i32 |
54 | | - - `contrast`: i32 |
55 | | - - `vibrance`: i32 |
56 | | - - `exposure`: i32 |
57 | | - - `temperature`: i32 |
58 | | - - `sharpness`: i32 |
59 | | - - `vignette`: i32 |
60 | | - - `highlights`: i32 |
61 | | -- **Returns**: `Result<(), String>` |
62 | | - |
63 | | -### 8. get_server_path |
| 5 | +### get_server_path |
64 | 6 |
|
65 | 7 | - **Description**: Retrieves the path to the server resources directory. |
66 | 8 | - **Parameters**: *None* |
67 | 9 | - **Returns**: `Result<String, String>` |
68 | | -### 9. move_to_secure_folder |
69 | | - |
70 | | -- **Description**: Moves a file to the secure folder with encryption. |
71 | | -- **Parameters**: |
72 | | - - `path`: String |
73 | | - - `password`: String |
74 | | -- **Returns**: `Result<(), String>` |
75 | | - |
76 | | -### 10. create_secure_folder |
77 | | - |
78 | | -- **Description**: Creates a new secure folder with password protection. |
79 | | -- **Parameters**: |
80 | | - - `password`: String |
81 | | -- **Returns**: `Result<(), String>` |
82 | | - |
83 | | -### 11. unlock_secure_folder |
84 | | - |
85 | | -- **Description**: Unlocks the secure folder with the provided password. |
86 | | -- **Parameters**: |
87 | | - - `password`: String |
88 | | -- **Returns**: `Result<bool, String>` |
89 | | - |
90 | | -### 12. get_secure_media |
91 | | - |
92 | | -- **Description**: Retrieves all media files from the secure folder. |
93 | | -- **Parameters**: |
94 | | - - `password`: String |
95 | | -- **Returns**: `Result<Vec<SecureMedia>, String>` |
96 | | - |
97 | | -### 13. remove_from_secure_folder |
98 | | - |
99 | | -- **Description**: Removes a file from the secure folder. |
100 | | -- **Parameters**: |
101 | | - - `file_name`: String |
102 | | - - `password`: String |
103 | | -- **Returns**: `Result<(), String>` |
104 | | - |
105 | | -### 14. check_secure_folder_status |
106 | | - |
107 | | -- **Description**: Checks if the secure folder is set up. |
108 | | -- **Parameters**: None |
109 | | -- **Returns**: `Result<bool, String>` |
110 | | - |
111 | | -### 15. get_random_memories |
112 | | - |
113 | | -- **Description**: Retrieves random memory images from specified directories. |
114 | | -- **Parameters**: |
115 | | - - `directories`: Vec<String> |
116 | | - - `count`: usize |
117 | | -- **Returns**: `Result<Vec<MemoryImage>, String>` |
118 | | - |
119 | | -### 16. open_folder |
120 | | - |
121 | | -- **Description**: Opens the parent folder of the specified file path. |
122 | | -- **Parameters**: |
123 | | - - `path`: String |
124 | | -- **Returns**: `Result<(), String>` |
125 | | - |
126 | | -### 17. open_with |
127 | | - |
128 | | -- **Description**: Opens a file with the system's "Open With" dialog. |
129 | | -- **Parameters**: |
130 | | - - `path`: String |
131 | | -- **Returns**: `Result<(), String>` |
132 | | - |
133 | | -### 18. set_wallpaper |
134 | | - |
135 | | -- **Description**: Sets an image as the desktop wallpaper. |
136 | | -- **Parameters**: |
137 | | - - `path`: String |
138 | | -- **Returns**: `Result<(), String>` |
139 | | - |
140 | | -## Data Structures |
141 | | - |
142 | | -### SecureMedia |
143 | | - |
144 | | -```rust |
145 | | -pub struct SecureMedia { |
146 | | - pub id: String, |
147 | | - pub url: String, |
148 | | - pub path: String, |
149 | | -} |
150 | | -``` |
151 | | - |
152 | | -### MemoryImage |
153 | | - |
154 | | -```rust |
155 | | -pub struct MemoryImage { |
156 | | - path: String, |
157 | | - created_at: DateTime<Utc>, |
158 | | -} |
159 | | -``` |
160 | 10 |
|
161 | 11 | ## Usage Examples |
162 | 12 |
|
163 | 13 | ```javascript |
164 | 14 | // In your frontend JavaScript/TypeScript code: |
165 | 15 | import { invoke } from "@tauri-apps/api/tauri"; |
166 | 16 |
|
167 | | -// Example: Get all images with cache from multiple directories |
168 | | -const imagesData = await invoke("get_all_images_with_cache", { |
169 | | - directories: ["/path/to/images1", "/path/to/images2"], |
170 | | -}); |
171 | | - |
172 | | -// Example: Share a file |
173 | | -await invoke("share_file", { path: "/path/to/file.jpg" }); |
174 | | - |
175 | | -// Example: Save edited image |
176 | | -await invoke("save_edited_image", { |
177 | | - image_data: imageBytes, |
178 | | - save_path: "/path/to/save/edited.jpg", |
179 | | - filter: "grayscale(100%)", |
180 | | - brightness: 10, |
181 | | - contrast: 20, |
182 | | - vibrance: 15, |
183 | | - exposure: 5, |
184 | | - temperature: 0, |
185 | | - sharpness: 10, |
186 | | - vignette: 0, |
187 | | - highlights: 0 |
188 | | -}); |
189 | | - |
190 | | -// Example: Create secure folder |
191 | | -await invoke("create_secure_folder", { password: "mySecurePassword" }); |
192 | | - |
193 | | -// Example: Move file to secure folder |
194 | | -await invoke("move_to_secure_folder", { |
195 | | - path: "/path/to/file.jpg", |
196 | | - password: "mySecurePassword" |
197 | | -}); |
198 | | - |
199 | | -// Example: Get random memories |
200 | | -const memories = await invoke("get_random_memories", { |
201 | | - directories: ["/path/to/photos"], |
202 | | - count: 5 |
203 | | -}); |
204 | | - |
205 | | -// Example: Set wallpaper |
206 | | -await invoke("set_wallpaper", { path: "/path/to/wallpaper.jpg" }); |
207 | | - |
208 | | -// Example: Delete cache |
209 | | -const cacheDeleted = await invoke("delete_cache"); |
| 17 | +// Example: Get server path |
| 18 | +const serverPath = await invoke("get_server_path"); |
| 19 | +console.log("Server path:", serverPath); |
210 | 20 | ``` |
211 | 21 |
|
212 | | -## Key Components |
213 | | - |
214 | | -- **FileService**: Handles file system operations for images and videos. |
215 | | -- **CacheService**: Manages caching of folders, images, and videos. |
216 | | -- **FileRepository**: Interacts directly with the file system to retrieve file information. |
217 | | -- **CacheRepository**: Handles reading from and writing to cache files. |
218 | | -- **Secure Storage**: Provides encrypted storage functionality with password protection. |
219 | | -- **Image Processing**: Handles image editing operations including filters, brightness, contrast, and other adjustments. |
220 | | -- **System Integration**: Provides integration with the operating system for file operations, wallpaper setting, and file management. |
221 | | - |
222 | | -## Security Features |
223 | | - |
224 | | -The API includes comprehensive security features for protecting sensitive media: |
225 | | - |
226 | | -- **Encryption**: Files moved to secure folders are encrypted using AES-256-GCM |
227 | | -- **Password Protection**: Secure folders require password authentication |
228 | | -- **Salt-based Hashing**: Uses PBKDF2 with SHA-256 for password hashing |
229 | | -- **Secure Random**: Uses cryptographically secure random number generation |
230 | | - |
231 | 22 | ## Cross-Platform Support |
232 | 23 |
|
233 | | -The API provides cross-platform support for: |
234 | | -- **Windows**: File operations, wallpaper setting, and system integration |
235 | | -- **macOS**: Native file operations and AppleScript integration |
236 | | -- **Linux**: Support for GNOME and KDE desktop environments |
| 24 | +The API provides cross-platform support using Tauri's unified `AppHandle.path().resolve(..., BaseDirectory::Resource)` for path resolution across Windows, macOS, and Linux. |
237 | 25 |
|
238 | | -This backend architecture provides efficient file management, caching capabilities, secure storage, image processing, and system integration, enhancing the overall functionality of the Tauri application. |
| 26 | +This backend provides essential path resolution functionality for the Tauri application. |
0 commit comments