1pub mod category;
35pub mod management;
36pub mod query;
37
38pub use category::{
39 BtListOptions, Category, CategoryCountOptions, CategorySearchOptions, DocumentListOptions,
40 ImageListOptions, VideoListOptions,
41};
42pub use management::{FolderCreateOptions, FolderInfo};
43pub use query::{
44 FileInfo, FileMeta, ListAllOptions, ListAllResult, ListOptions, SearchOptions,
45 SemanticSearchOptions,
46};
47
48use std::sync::Arc;
49
50use crate::client::TokenGetter;
51use crate::errors::NetDiskResult;
52use crate::http::HttpClient;
53use category::FileCategoryExt;
54use management::FileManagementExt;
55use query::FileQueryExt;
56
57#[derive(Debug, Clone)]
80pub struct FileClient {
81 http_client: HttpClient,
82 token_getter: Arc<dyn TokenGetter>,
83}
84
85impl FileClient {
86 pub fn new(http_client: HttpClient, token_getter: Arc<dyn TokenGetter>) -> Self {
90 FileClient {
91 http_client,
92 token_getter,
93 }
94 }
95
96 pub fn http_client(&self) -> &HttpClient {
98 &self.http_client
99 }
100
101 pub async fn list_directory(&self, dir: &str) -> NetDiskResult<Vec<FileInfo>> {
105 FileQueryExt::list_directory(self, dir).await
106 }
107
108 pub async fn list_directory_with_options(
110 &self,
111 dir: &str,
112 options: ListOptions,
113 ) -> NetDiskResult<Vec<FileInfo>> {
114 FileQueryExt::list_directory_with_options(self, dir, options).await
115 }
116
117 pub async fn list_all(&self, path: &str, start: i32, limit: i32) -> NetDiskResult<ListAllResult> {
122 FileQueryExt::list_all(self, path, start, limit).await
123 }
124
125 pub async fn list_all_with_options(
127 &self,
128 path: &str,
129 options: ListAllOptions,
130 ) -> NetDiskResult<ListAllResult> {
131 FileQueryExt::list_all_with_options(self, path, options).await
132 }
133
134 pub async fn get_file_info(&self, path: &str) -> NetDiskResult<FileInfo> {
136 FileQueryExt::get_file_info(self, path).await
137 }
138
139 pub async fn get_file_meta(&self, fs_id: u64) -> NetDiskResult<FileMeta> {
141 FileQueryExt::get_file_meta(self, fs_id).await
142 }
143
144 pub async fn search_files(&self, key: &str, dir: &str) -> NetDiskResult<(Vec<FileInfo>, bool)> {
146 FileQueryExt::search_files(self, key, dir).await
147 }
148
149 pub async fn search_files_with_options(
151 &self,
152 key: &str,
153 options: SearchOptions,
154 ) -> NetDiskResult<(Vec<FileInfo>, bool)> {
155 FileQueryExt::search_files_with_options(self, key, options).await
156 }
157
158 pub async fn semantic_search(&self, query: &str) -> NetDiskResult<Vec<FileInfo>> {
160 FileQueryExt::semantic_search(self, query).await
161 }
162
163 pub async fn semantic_search_with_options(
165 &self,
166 query: &str,
167 options: SemanticSearchOptions,
168 ) -> NetDiskResult<Vec<FileInfo>> {
169 FileQueryExt::semantic_search_with_options(self, query, options).await
170 }
171
172 pub async fn create_folder(&self, path: &str) -> NetDiskResult<FolderInfo> {
176 FileManagementExt::create_folder(self, path).await
177 }
178
179 pub async fn create_folder_with_options(
181 &self,
182 path: &str,
183 options: FolderCreateOptions,
184 ) -> NetDiskResult<FolderInfo> {
185 FileManagementExt::create_folder_with_options(self, path, options).await
186 }
187
188 pub async fn rename(&self, path: &str, new_name: &str) -> NetDiskResult<()> {
190 FileManagementExt::rename(self, path, new_name).await
191 }
192
193 pub async fn delete(&self, path: &str) -> NetDiskResult<()> {
195 FileManagementExt::delete(self, path).await
196 }
197
198 pub async fn move_file(&self, path: &str, dest: &str) -> NetDiskResult<()> {
200 FileManagementExt::move_file(self, path, dest).await
201 }
202
203 pub async fn copy_file(&self, path: &str, dest: &str) -> NetDiskResult<()> {
205 FileManagementExt::copy_file(self, path, dest).await
206 }
207
208 pub async fn get_category_file_count(&self, category: u32) -> NetDiskResult<u64> {
212 let token = self.token_getter.get_token().await?;
213 FileCategoryExt::get_category_file_count(self, &token, category).await
214 }
215
216 pub async fn get_category_file_count_with_options(
218 &self,
219 category: u32,
220 options: CategoryCountOptions,
221 ) -> NetDiskResult<u64> {
222 let token = self.token_getter.get_token().await?;
223 FileCategoryExt::get_category_file_count_with_options(self, &token, category, options).await
224 }
225
226 pub async fn search_category_files(
228 &self,
229 category: u32,
230 start: i32,
231 limit: i32,
232 ) -> NetDiskResult<(Vec<FileInfo>, u64)> {
233 let token = self.token_getter.get_token().await?;
234 FileCategoryExt::search_category_files(self, &token, category, start, limit).await
235 }
236
237 pub async fn search_category_files_with_options(
239 &self,
240 category: &str,
241 options: CategorySearchOptions,
242 ) -> NetDiskResult<(Vec<FileInfo>, u64)> {
243 let token = self.token_getter.get_token().await?;
244 FileCategoryExt::search_category_files_with_options(self, &token, category, options).await
245 }
246
247 pub async fn list_documents(
249 &self,
250 parent_path: &str,
251 page: i32,
252 num: i32,
253 ) -> NetDiskResult<Vec<FileInfo>> {
254 let token = self.token_getter.get_token().await?;
255 FileCategoryExt::list_documents(self, &token, parent_path, page, num).await
256 }
257
258 pub async fn list_documents_with_options(
260 &self,
261 options: DocumentListOptions,
262 ) -> NetDiskResult<Vec<FileInfo>> {
263 let token = self.token_getter.get_token().await?;
264 FileCategoryExt::list_documents_with_options(self, &token, options).await
265 }
266
267 pub async fn list_images(
269 &self,
270 parent_path: &str,
271 page: i32,
272 num: i32,
273 ) -> NetDiskResult<Vec<FileInfo>> {
274 let token = self.token_getter.get_token().await?;
275 FileCategoryExt::list_images(self, &token, parent_path, page, num).await
276 }
277
278 pub async fn list_images_with_options(
280 &self,
281 options: ImageListOptions,
282 ) -> NetDiskResult<Vec<FileInfo>> {
283 let token = self.token_getter.get_token().await?;
284 FileCategoryExt::list_images_with_options(self, &token, options).await
285 }
286
287 pub async fn list_videos(
289 &self,
290 parent_path: &str,
291 page: i32,
292 num: i32,
293 ) -> NetDiskResult<Vec<FileInfo>> {
294 let token = self.token_getter.get_token().await?;
295 FileCategoryExt::list_videos(self, &token, parent_path, page, num).await
296 }
297
298 pub async fn list_videos_with_options(
300 &self,
301 options: VideoListOptions,
302 ) -> NetDiskResult<Vec<FileInfo>> {
303 let token = self.token_getter.get_token().await?;
304 FileCategoryExt::list_videos_with_options(self, &token, options).await
305 }
306
307 pub async fn list_torrents(
309 &self,
310 parent_path: &str,
311 page: i32,
312 num: i32,
313 ) -> NetDiskResult<Vec<FileInfo>> {
314 let token = self.token_getter.get_token().await?;
315 FileCategoryExt::list_torrents(self, &token, parent_path, page, num).await
316 }
317
318 pub async fn list_torrents_with_options(
320 &self,
321 options: BtListOptions,
322 ) -> NetDiskResult<Vec<FileInfo>> {
323 let token = self.token_getter.get_token().await?;
324 FileCategoryExt::list_torrents_with_options(self, &token, options).await
325 }
326}