CloudreveAPI

Struct CloudreveAPI 

Source
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

Source

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.

Source

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.

Source

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

Source

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.

Source

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

pub async fn update_dav_account( &self, id: &str, uri: Option<&str>, name: Option<&str>, readonly: Option<bool>, proxy: Option<bool>, ) -> Result<(), Error>

Update a WebDAV account

Updates an existing WebDAV account. Only available in V4.

Source

pub async fn delete_dav_account(&self, id: &str) -> Result<(), Error>

Delete a WebDAV account

Deletes a WebDAV account. Only available in V4.

Source§

impl CloudreveAPI

Download methods for CloudreveAPI

Source

pub async fn create_download_url(&self, path: &str) -> Result<String, Error>

Create a download URL for a file

Returns a download URL that can be used to download the file.

Source§

impl CloudreveAPI

File operation methods for CloudreveAPI

Source

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.

Source

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).

Source

pub async fn create_directory(&self, path: &str) -> Result<(), Error>

Create a directory

Creates a new directory at the specified path.

Source

pub async fn delete(&self, target: DeleteTarget) -> Result<(), Error>

Delete a file or directory

Accepts either a path or URI for deletion.

Source

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?;
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn download_file(&self, path: &str) -> Result<String, Error>

Download a file

Returns the download URL for the file.

Source

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

pub async fn preview_file(&self, file_id: &str) -> Result<String, Error>

Preview a file

Returns preview information for the file. For V3, requires file ID.

Source

pub async fn get_thumbnail(&self, file_id: &str) -> Result<String, Error>

Get thumbnail for a file

Returns thumbnail information for the file. For V3, requires file ID.

Source§

impl CloudreveAPI

Share methods for CloudreveAPI

Source

pub async fn create_share( &self, path: &str, _name: Option<&str>, expires_in: Option<u32>, password: Option<&str>, ) -> Result<String, Error>

Create a share link for a file or directory

Creates a share link with optional expiration and password.

Source

pub async fn list_shares(&self) -> Result<Vec<ShareItem>, Error>

List all shares

Returns a list of all share links for the current user.

Source

pub async fn update_share( &self, id: &str, props: &ShareUpdateProps, ) -> Result<(), Error>

Update a share link

Updates an existing share link with new settings.

Source

pub async fn delete_share(&self, id: &str) -> Result<(), Error>

Delete a share link

Deletes an existing share link.

Source§

impl CloudreveAPI

Site configuration methods for CloudreveAPI

Source

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

Source

pub async fn get_user_info(&self) -> Result<UserInfo, Error>

Get user information

Returns unified user information regardless of API version.

Source

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

Source

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.

Source

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).

Source

pub fn api_version(&self) -> ApiVersion

Get the detected API version

Source

pub fn base_url(&self) -> &str

Get the base URL

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for CloudreveAPI

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more