pub mod category;
pub mod management;
pub mod query;
pub use category::{
BtListOptions, Category, CategoryCountOptions, CategorySearchOptions, DocumentListOptions,
ImageListOptions, VideoListOptions,
};
pub use management::{FolderCreateOptions, FolderInfo};
pub use query::{
FileInfo, FileMeta, ListAllOptions, ListAllResult, ListOptions, SearchOptions,
SemanticSearchOptions,
};
use std::sync::Arc;
use crate::client::TokenGetter;
use crate::errors::NetDiskResult;
use crate::http::HttpClient;
use category::FileCategoryExt;
use management::FileManagementExt;
use query::FileQueryExt;
#[derive(Debug, Clone)]
pub struct FileClient {
http_client: HttpClient,
token_getter: Arc<dyn TokenGetter>,
}
impl FileClient {
pub fn new(http_client: HttpClient, token_getter: Arc<dyn TokenGetter>) -> Self {
FileClient {
http_client,
token_getter,
}
}
pub fn http_client(&self) -> &HttpClient {
&self.http_client
}
pub async fn list_directory(&self, dir: &str) -> NetDiskResult<Vec<FileInfo>> {
FileQueryExt::list_directory(self, dir).await
}
pub async fn list_directory_with_options(
&self,
dir: &str,
options: ListOptions,
) -> NetDiskResult<Vec<FileInfo>> {
FileQueryExt::list_directory_with_options(self, dir, options).await
}
pub async fn list_all(&self, path: &str, start: i32, limit: i32) -> NetDiskResult<ListAllResult> {
FileQueryExt::list_all(self, path, start, limit).await
}
pub async fn list_all_with_options(
&self,
path: &str,
options: ListAllOptions,
) -> NetDiskResult<ListAllResult> {
FileQueryExt::list_all_with_options(self, path, options).await
}
pub async fn get_file_info(&self, path: &str) -> NetDiskResult<FileInfo> {
FileQueryExt::get_file_info(self, path).await
}
pub async fn get_file_meta(&self, fs_id: u64) -> NetDiskResult<FileMeta> {
FileQueryExt::get_file_meta(self, fs_id).await
}
pub async fn search_files(&self, key: &str, dir: &str) -> NetDiskResult<(Vec<FileInfo>, bool)> {
FileQueryExt::search_files(self, key, dir).await
}
pub async fn search_files_with_options(
&self,
key: &str,
options: SearchOptions,
) -> NetDiskResult<(Vec<FileInfo>, bool)> {
FileQueryExt::search_files_with_options(self, key, options).await
}
pub async fn semantic_search(&self, query: &str) -> NetDiskResult<Vec<FileInfo>> {
FileQueryExt::semantic_search(self, query).await
}
pub async fn semantic_search_with_options(
&self,
query: &str,
options: SemanticSearchOptions,
) -> NetDiskResult<Vec<FileInfo>> {
FileQueryExt::semantic_search_with_options(self, query, options).await
}
pub async fn create_folder(&self, path: &str) -> NetDiskResult<FolderInfo> {
FileManagementExt::create_folder(self, path).await
}
pub async fn create_folder_with_options(
&self,
path: &str,
options: FolderCreateOptions,
) -> NetDiskResult<FolderInfo> {
FileManagementExt::create_folder_with_options(self, path, options).await
}
pub async fn rename(&self, path: &str, new_name: &str) -> NetDiskResult<()> {
FileManagementExt::rename(self, path, new_name).await
}
pub async fn delete(&self, path: &str) -> NetDiskResult<()> {
FileManagementExt::delete(self, path).await
}
pub async fn move_file(&self, path: &str, dest: &str) -> NetDiskResult<()> {
FileManagementExt::move_file(self, path, dest).await
}
pub async fn copy_file(&self, path: &str, dest: &str) -> NetDiskResult<()> {
FileManagementExt::copy_file(self, path, dest).await
}
pub async fn get_category_file_count(&self, category: u32) -> NetDiskResult<u64> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::get_category_file_count(self, &token, category).await
}
pub async fn get_category_file_count_with_options(
&self,
category: u32,
options: CategoryCountOptions,
) -> NetDiskResult<u64> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::get_category_file_count_with_options(self, &token, category, options).await
}
pub async fn search_category_files(
&self,
category: u32,
start: i32,
limit: i32,
) -> NetDiskResult<(Vec<FileInfo>, u64)> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::search_category_files(self, &token, category, start, limit).await
}
pub async fn search_category_files_with_options(
&self,
category: &str,
options: CategorySearchOptions,
) -> NetDiskResult<(Vec<FileInfo>, u64)> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::search_category_files_with_options(self, &token, category, options).await
}
pub async fn list_documents(
&self,
parent_path: &str,
page: i32,
num: i32,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_documents(self, &token, parent_path, page, num).await
}
pub async fn list_documents_with_options(
&self,
options: DocumentListOptions,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_documents_with_options(self, &token, options).await
}
pub async fn list_images(
&self,
parent_path: &str,
page: i32,
num: i32,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_images(self, &token, parent_path, page, num).await
}
pub async fn list_images_with_options(
&self,
options: ImageListOptions,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_images_with_options(self, &token, options).await
}
pub async fn list_videos(
&self,
parent_path: &str,
page: i32,
num: i32,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_videos(self, &token, parent_path, page, num).await
}
pub async fn list_videos_with_options(
&self,
options: VideoListOptions,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_videos_with_options(self, &token, options).await
}
pub async fn list_torrents(
&self,
parent_path: &str,
page: i32,
num: i32,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_torrents(self, &token, parent_path, page, num).await
}
pub async fn list_torrents_with_options(
&self,
options: BtListOptions,
) -> NetDiskResult<Vec<FileInfo>> {
let token = self.token_getter.get_token().await?;
FileCategoryExt::list_torrents_with_options(self, &token, options).await
}
}