Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Main Cloudreve API client

Implementations§

Source§

impl Client

Source

pub fn new(config: ClientConfig) -> Self

Create a new API client

Source

pub fn set_on_credential_refreshed(&mut self, callback: OnCredentialRefreshed)

Set a callback to be invoked when credentials are refreshed

The callback receives the new token information and can perform async operations such as persisting tokens to storage.

§Example
use cloudreve_sdk_api::{Client, ClientConfig};
use std::sync::Arc;

let mut client = Client::new(ClientConfig::new("https://cloudreve.example"));
client.set_on_credential_refreshed(Arc::new(|token| {
    Box::pin(async move {
        // Save token to storage
        println!("New access token: {}", token.access_token);
    })
}));
Source

pub fn clear_on_credential_refreshed(&mut self)

Clear the credential refresh callback

Source

pub fn set_on_credential_invalid(&mut self, callback: OnCredentialInvalid)

Set a callback to be invoked when credentials are invalid or expired

This callback is triggered when the API returns error codes indicating authentication failure: 401 (LoginRequired), 40020 (CredentialInvalid), or 40089 (SessionExpired).

Source

pub fn clear_on_credential_invalid(&mut self)

Clear the credential invalid callback

Source

pub async fn set_tokens(&self, access_token: String, refresh_token: String)

Set authentication tokens

Source

pub async fn set_tokens_with_expiry(&self, token: &Token) -> ApiResult<()>

Set tokens from a Token response with explicit expiration times.

Source

pub async fn clear_tokens(&self)

Clear all authentication tokens

Source

pub async fn set_purchase_ticket(&self, ticket: Option<String>)

Set the purchase ticket for subsequent requests

Source

pub async fn send<T, R>( &self, path: &str, method: Method, body: Option<&T>, options: RequestOptions, ) -> ApiResult<R>

Send an API request with automatic token refresh

Source

pub async fn get<R>(&self, path: &str, options: RequestOptions) -> ApiResult<R>

Send a GET request

Source

pub async fn post<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>

Send a POST request

Source

pub async fn put<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>

Send a PUT request

Source

pub async fn delete<R>( &self, path: &str, options: RequestOptions, ) -> ApiResult<R>

Send a DELETE request

Source

pub async fn delete_with_body<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>

Send a DELETE request with body

Source

pub async fn patch<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>

Send a PATCH request

Trait Implementations§

Source§

impl ExplorerApi for Client

Source§

fn list_files<'life0, 'life1, 'async_trait>( &'life0 self, params: &'life1 ListFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<ListResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List files in a directory
Source§

fn get_file_thumb<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, _context_hint: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = ApiResult<FileThumbResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get file thumbnail
Source§

fn get_file_info<'life0, 'life1, 'async_trait>( &'life0 self, params: &'life1 GetFileInfoService, ) -> Pin<Box<dyn Future<Output = ApiResult<FileResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get file information
Source§

fn create_file<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 CreateFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<FileResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new file or folder
Source§

fn delete_files<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 DeleteFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete files
Source§

fn rename_file<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 RenameFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<FileResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Rename a file
Source§

fn move_files<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 MoveFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Move files
Source§

fn restore_files<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 DeleteFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Restore files from trash
Source§

fn patch_metadata<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 PatchMetadataService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Patch file metadata
Source§

fn get_file_url<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 FileURLService, ) -> Pin<Box<dyn Future<Output = ApiResult<FileURLResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get file entity URL
Source§

fn unlock_files<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 UnlockFileService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Unlock files
Source§

fn set_current_version<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 VersionControlService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set current version
Source§

fn delete_version<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 VersionControlService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete version
Source§

fn update_file<'life0, 'life1, 'async_trait>( &'life0 self, params: &'life1 FileUpdateService, data: Bytes, ) -> Pin<Box<dyn Future<Output = ApiResult<FileResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update file content
Source§

fn get_storage_policy_options<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<Vec<StoragePolicy>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get storage policy options
Source§

fn mount_storage_policy<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 MountPolicyService, ) -> Pin<Box<dyn Future<Output = ApiResult<Vec<StoragePolicy>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mount storage policy
Source§

fn set_permissions<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 SetPermissionService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set file permissions
Source§

fn create_upload_session<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 UploadSessionRequest, ) -> Pin<Box<dyn Future<Output = ApiResult<UploadCredential>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create upload session
Source§

fn upload_chunk<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, chunk_index: usize, data: Bytes, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Upload chunk
Source§

fn upload_chunk_stream<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, chunk_index: usize, content_length: u64, body: Body, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Upload chunk using streaming body (for large chunks)
Source§

fn delete_upload_session<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 DeleteUploadSessionService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete upload session
Source§

fn complete_s3_upload<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, policy_type: &'life1 str, session_id: &'life2 str, session_key: &'life3 str, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Complete S3-like upload
Source§

fn complete_onedrive_upload<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, session_key: &'life2 str, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Complete OneDrive upload
Source§

impl ExplorerApiExt for Client

Source§

fn list_files_all<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, previous_response: Option<&'life1 ListAllRes<ListResponse>>, uri: &'life2 str, page_size: i32, ) -> Pin<Box<dyn Future<Output = ApiResult<ListAllRes<ListResponse>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

impl FileEventsApi for Client

Source§

fn subscribe_file_events<'life0, 'life1, 'async_trait>( &'life0 self, uri: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<FileEventSubscription>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Subscribe to file events for a given URI. Read more
Source§

impl SiteApi for Client

Source§

fn get_site_config<'life0, 'life1, 'async_trait>( &'life0 self, section: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<SiteConfig>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get site configuration
Source§

fn get_captcha<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<CaptchaResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get captcha
Source§

fn create_abuse_report<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 CreateAbuseReportService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create abuse report
Source§

impl UserApi for Client

Source§

fn login<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, email: &'life1 str, password: &'life2 str, ) -> Pin<Box<dyn Future<Output = ApiResult<LoginResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Login with email and password
Source§

fn login_2fa<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, otp: &'life1 str, session_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = ApiResult<LoginResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Login with 2FA code
Source§

fn get_user_me<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<User>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get current user information
Source§

fn get_user_capacity<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<Capacity>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get user capacity information
Source§

fn get_user_storage_policies<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<Vec<StoragePolicy>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get user storage policies
Source§

fn get_user_settings<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ApiResult<UserSettings>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get user settings
Source§

fn patch_user_settings<'life0, 'life1, 'async_trait>( &'life0 self, settings: &'life1 PatchUserSetting, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update user settings
Source§

fn get_credit_log<'life0, 'life1, 'async_trait>( &'life0 self, params: &'life1 GetCreditLogService, ) -> Pin<Box<dyn Future<Output = ApiResult<CreditChangeLogResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get credit change log
Source§

fn sign_up<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 SignUpService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sign up a new user
Source§

fn send_reset_email<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 SendResetEmailService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send password reset email
Source§

fn reset_password<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ResetPasswordService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reset password with secret
Source§

impl WorkflowApi for Client

Source§

fn create_archive<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ArchiveWorkflowService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create archive task
Source§

fn extract_archive<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ArchiveWorkflowService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Extract archive task
Source§

fn relocate<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 RelocateWorkflowService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Relocate files task
Source§

fn remote_download<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 DownloadWorkflowService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remote download task
Source§

fn import<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ImportWorkflowService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Import files task
Source§

fn list_tasks<'life0, 'life1, 'async_trait>( &'life0 self, params: &'life1 ListTaskService, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskListResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List tasks
Source§

fn get_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<TaskResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get task by ID
Source§

fn cancel_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel task
Source§

fn delete_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete task
Source§

fn set_download_files<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, request: &'life2 SetDownloadFilesService, ) -> Pin<Box<dyn Future<Output = ApiResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Set download files for a task

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> 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: Sized + 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: Sized + 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, 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