pub struct CloudreveAPI { /* private fields */ }Expand description
Unified Cloudreve API client
This client automatically detects the API version (v3 or v4) and routes all requests to the appropriate endpoints. It handles authentication differences transparently.
Implementations§
Source§impl CloudreveAPI
Authentication methods for CloudreveAPI
impl CloudreveAPI
Authentication methods for CloudreveAPI
Sourcepub async fn login(
&mut self,
email: &str,
password: &str,
) -> Result<LoginResponse, Error>
pub async fn login( &mut self, email: &str, password: &str, ) -> Result<LoginResponse, Error>
Login with email and password
This method handles both v3 (session cookie) and v4 (JWT token) authentication. After successful login, the authentication is stored internally.
Sourcepub fn get_token(&self) -> Result<TokenInfo, Error>
pub fn get_token(&self) -> Result<TokenInfo, Error>
Get the current authentication token for caching purposes
Returns the token info if authenticated, suitable for saving to CLI cache.
Sourcepub fn set_token(&mut self, token: &str) -> Result<(), Error>
pub fn set_token(&mut self, token: &str) -> Result<(), Error>
Set authentication token from cache
Use this method when restoring a previous session from cache.
Do not call this after login() - the token is already stored internally.
Get the session cookie (for V3 API)
Returns the session cookie if using V3 API, None otherwise.
Source§impl CloudreveAPI
WebDAV operations methods for CloudreveAPI
impl CloudreveAPI
WebDAV operations methods for CloudreveAPI
Sourcepub async fn list_dav_accounts(
&self,
page_size: u32,
) -> Result<DavListResponse, Error>
pub async fn list_dav_accounts( &self, page_size: u32, ) -> Result<DavListResponse, Error>
List WebDAV accounts
Returns a unified list of WebDAV accounts regardless of API version.
Sourcepub async fn create_dav_account(
&self,
uri: &str,
name: &str,
readonly: bool,
proxy: bool,
) -> Result<(), Error>
pub async fn create_dav_account( &self, uri: &str, name: &str, readonly: bool, proxy: bool, ) -> Result<(), Error>
Create a WebDAV account
Creates a new WebDAV account. Only available in V4.
Source§impl CloudreveAPI
Download methods for CloudreveAPI
impl CloudreveAPI
Download methods for CloudreveAPI
Source§impl CloudreveAPI
File operation methods for CloudreveAPI
impl CloudreveAPI
File operation methods for CloudreveAPI
Sourcepub async fn list_files(
&self,
path: &str,
page: Option<u32>,
page_size: Option<u32>,
) -> Result<FileList, Error>
pub async fn list_files( &self, path: &str, page: Option<u32>, page_size: Option<u32>, ) -> Result<FileList, Error>
List files in a directory
Returns a unified file list regardless of API version.
Sourcepub async fn list_files_all(
&self,
path: &str,
page_size: Option<u32>,
) -> Result<FileListAll, Error>
pub async fn list_files_all( &self, path: &str, page_size: Option<u32>, ) -> Result<FileListAll, Error>
List all files in a directory with automatic pagination
This method automatically fetches all pages for V4 API and combines them. For V3 API, it returns the single page result (no pagination support).
Sourcepub async fn create_directory(&self, path: &str) -> Result<(), Error>
pub async fn create_directory(&self, path: &str) -> Result<(), Error>
Create a directory
Creates a new directory at the specified path.
Sourcepub async fn delete(&self, target: DeleteTarget) -> Result<(), Error>
pub async fn delete(&self, target: DeleteTarget) -> Result<(), Error>
Delete a file or directory
Accepts either a path or URI for deletion.
Sourcepub async fn batch_delete(&self, paths: &[&str]) -> Result<DeleteResult, Error>
pub async fn batch_delete(&self, paths: &[&str]) -> Result<DeleteResult, Error>
Batch delete multiple files and/or folders
This method accepts multiple paths and deletes them all in a single API call. Files and folders can be mixed in the same request. The server handles recursive deletion of folder contents automatically.
§Arguments
paths- Slice of paths to delete (can mix files and folders)
§Example
// Delete multiple items at once
api.batch_delete(&[
"/folder/file1.txt",
"/folder/file2.txt",
"/another_folder", // folder will be deleted recursively
]).await?;Sourcepub async fn get_file_info(&self, path: &str) -> Result<FileInfo, Error>
pub async fn get_file_info(&self, path: &str) -> Result<FileInfo, Error>
Get file information by path or URI
Returns unified file information regardless of API version.
Sourcepub async fn rename(&self, path: &str, new_name: &str) -> Result<(), Error>
pub async fn rename(&self, path: &str, new_name: &str) -> Result<(), Error>
Rename a file or directory
Renames a file or directory at the given path to a new name.
Sourcepub async fn move_file(&self, src: &str, dest: &str) -> Result<(), Error>
pub async fn move_file(&self, src: &str, dest: &str) -> Result<(), Error>
Move a file or directory
Moves a file or directory from source path to destination path.
Sourcepub async fn copy_file(&self, src: &str, dest: &str) -> Result<(), Error>
pub async fn copy_file(&self, src: &str, dest: &str) -> Result<(), Error>
Copy a file or directory
Copies a file or directory from source path to destination path.
Sourcepub async fn upload_file(
&self,
path: &str,
content: Vec<u8>,
policy_id: Option<&str>,
) -> Result<(), Error>
pub async fn upload_file( &self, path: &str, content: Vec<u8>, policy_id: Option<&str>, ) -> Result<(), Error>
Upload a file
Uploads a file to the specified path. Returns the uploaded file info.
Sourcepub async fn download_file(&self, path: &str) -> Result<String, Error>
pub async fn download_file(&self, path: &str) -> Result<String, Error>
Download a file
Returns the download URL for the file.
Sourcepub async fn restore_file(&self, path: &str) -> Result<(), Error>
pub async fn restore_file(&self, path: &str) -> Result<(), Error>
Restore a file from trash
Restores a file or directory from the trash. Only available in V4.
Source§impl CloudreveAPI
Share methods for CloudreveAPI
impl CloudreveAPI
Share methods for CloudreveAPI
Create a share link for a file or directory
Creates a share link with optional expiration and password.
List all shares
Returns a list of all share links for the current user.
Update a share link
Updates an existing share link with new settings.
Delete a share link
Deletes an existing share link.
Source§impl CloudreveAPI
Site configuration methods for CloudreveAPI
impl CloudreveAPI
Site configuration methods for CloudreveAPI
Sourcepub async fn get_site_config(
&self,
section: Option<&str>,
) -> Result<SiteConfigValue, Error>
pub async fn get_site_config( &self, section: Option<&str>, ) -> Result<SiteConfigValue, Error>
Get site configuration (unified API for V3 and V4)
V4: supports section parameter (basic, login, explorer, etc.) V3: ignores section, returns all config
Source§impl CloudreveAPI
User management methods for CloudreveAPI
impl CloudreveAPI
User management methods for CloudreveAPI
Sourcepub async fn get_user_info(&self) -> Result<UserInfo, Error>
pub async fn get_user_info(&self) -> Result<UserInfo, Error>
Get user information
Returns unified user information regardless of API version.
Sourcepub async fn get_storage_quota(&self) -> Result<StorageQuota, Error>
pub async fn get_storage_quota(&self) -> Result<StorageQuota, Error>
Get storage quota information
Returns unified storage quota regardless of API version.
Source§impl CloudreveAPI
impl CloudreveAPI
Sourcepub async fn new(base_url: &str) -> Result<Self, Error>
pub async fn new(base_url: &str) -> Result<Self, Error>
Create a new API client with automatic version detection
This method probes the server to determine which API version it supports, preferring v4 over v3 when both are available.
Sourcepub fn with_version(base_url: &str, version: ApiVersion) -> Result<Self, Error>
pub fn with_version(base_url: &str, version: ApiVersion) -> Result<Self, Error>
Create a new API client with a specific version
This method creates a client for the specified API version without probing. Useful when the version is already known (e.g., from cached token).
Sourcepub fn api_version(&self) -> ApiVersion
pub fn api_version(&self) -> ApiVersion
Get the detected API version
Sourcepub fn inner(&self) -> &UnifiedClient
pub fn inner(&self) -> &UnifiedClient
Get access to the underlying UnifiedClient
This is a temporary method for advanced use cases where direct V3/V4 client access is needed. In the future, all operations should be available through CloudreveAPI methods.
Sourcepub fn inner_mut(&mut self) -> &mut UnifiedClient
pub fn inner_mut(&mut self) -> &mut UnifiedClient
Get mutable access to the underlying UnifiedClient
This is a temporary method for advanced use cases where direct V3/V4 client access is needed.
Sourcepub async fn get_server_version(&self) -> Result<String, Error>
pub async fn get_server_version(&self) -> Result<String, Error>
Get the server version
Returns the Cloudreve server version by pinging the /site/ping endpoint.