Skip to main content

ApiV3Client

Struct ApiV3Client 

Source
pub struct ApiV3Client {
    pub base_url: String,
    pub http_client: Client,
    pub session_cookie: Option<String>,
}
Expand description

API v3 client structure

Fields§

§base_url: String§http_client: Client§session_cookie: Option<String>

Implementations§

Source§

impl ApiV3Client

Source

pub async fn create_download( &self, request: &Aria2CreateRequest<'_>, ) -> Result<(), Error>

Create one or more aria2 offline-download tasks.

Cloudreve v3 returns the created tasks in data (an array of objects whose exact shape varies by version, e.g. with/without gid), so we accept any JSON payload. Callers only need success/failure here — use Self::list_downloading to follow the new tasks afterwards.

Source

pub async fn list_downloading(&self) -> Result<Vec<Aria2DownloadingTask>, Error>

List in-flight aria2 tasks (GET /aria2/downloading).

Cloudreve v3 returns a flat array (no pagination wrapper). When there are no active downloads the response carries code: 0, data: null, which deserialises to an empty vector here.

Source

pub async fn list_finished(&self) -> Result<Vec<Aria2FinishedTask>, Error>

List finished aria2 tasks (GET /aria2/finished).

Cloudreve v3’s response is a flat array; the legacy /aria2/finished/:page path segment was removed years ago and no longer exists on supported servers. Returns an empty vector when the server replies with data: null.

Source

pub async fn delete_task(&self, gid: &str) -> Result<(), Error>

Cancel an aria2 task by GID.

Source§

impl ApiV3Client

Source

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

List directory contents

Source

pub async fn create_directory( &self, request: &CreateDirectoryRequest<'_>, ) -> Result<(), Error>

Create a directory

Source§

impl ApiV3Client

Source

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

Search for files by keyword, scoped to path.

Pass “/” as path to search the entire drive. The response reuses the directory listing shape, so the matches arrive in objects.

Source

pub async fn upload_file( &self, request: &UploadFileRequest<'_>, ) -> Result<UploadSession, Error>

Source

pub async fn upload_chunk( &self, session_id: &str, chunk_index: u32, data: Vec<u8>, ) -> Result<(), Error>

Source

pub async fn update_file_content( &self, id: &str, content: Vec<u8>, ) -> Result<(), Error>

原地覆盖一个已存在文件的内容(PUT /file/update/{id})。

V3 的上传会话没有 overwrite 语义:同名文件已存在时,建会话会被 GenericAfterUpload 挡回 40004 Object existed。网页端的文本编辑器保存走的 就是这个接口,服务端以 fsctx.Overwrite 模式写回原文件,id 和路径都不变。

服务端从 Content-Length 取长度,所以这里显式带上;响应仍是 HTTP 200 + body 里的 code。

Source

pub async fn delete_upload_session(&self, session_id: &str) -> Result<(), Error>

Delete one upload session by id (DELETE /file/upload/{sessionId}).

Opening a session makes V3 insert a placeholder file row that keeps the name taken. If the upload never finishes, every later upload_file for the same path fails with 40054 “Upload session existed” until the server-side GC runs (upload_session_timeout, 24h by default). Deleting the session drops that placeholder and is the only way a client can clear the conflict itself.

A session the server no longer knows returns CodeUploadSessionExpired; callers that are only cleaning up can treat that as already done.

Source

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

Delete every upload placeholder the current user owns (DELETE /file/upload).

This is the recovery path for orphan sessions whose ids the client lost (killed mid-upload, local store wiped, session created but the response never arrived). It is account-wide, so any upload still in flight loses its placeholder too — only call it when nothing else is uploading.

Source

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

Source

pub async fn get_file_source( &self, request: &FileSourceRequest, ) -> Result<Vec<FileSource>, Error>

Source

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

拉取文件预览内容(GET /file/preview/{id})。

这个端点要么 302 跳到直链、要么直接把内容写进响应体,从不返回 JSON ——早先这里按 ApiResponse<DirectoryList> 解,任何一种成功路径都会解析失败。 reqwest 默认跟随重定向,所以直接拿字节即可;出错时 V3 会回 200 + JSON 错误体, 由 Self::fetch_binary 识别。

Source

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

拉取缩略图(GET /file/thumb/{id})。

Self::preview_file 一样:301 跳转或原始图片字节,不是 JSON。

Source

pub async fn create_file( &self, request: &CreateFileRequest<'_>, ) -> Result<(), Error>

Source§

impl ApiV3Client

Source

pub async fn get_object_property( &self, id: &str, is_folder: Option<bool>, trace_root: Option<bool>, ) -> Result<Property, Error>

Get object (file/folder) property

Source

pub async fn rename_object( &self, request: &RenameObjectRequest<'_>, ) -> Result<(), Error>

Rename object

Source

pub async fn move_object( &self, request: &MoveObjectRequest<'_>, ) -> Result<(), Error>

Move object

Source

pub async fn copy_object( &self, request: &CopyObjectRequest<'_>, ) -> Result<(), Error>

Copy object

Source

pub async fn delete_object( &self, request: &DeleteObjectRequest<'_>, ) -> Result<(), Error>

Delete object

Source§

impl ApiV3Client

Source

pub async fn login(&mut self, request: &LoginRequest<'_>) -> Result<User, Error>

Login with email and password

Source

pub async fn login_2fa( &mut self, request: &OtpLoginRequest, ) -> Result<User, Error>

Login with OTP (Two-Factor Authentication)

Source

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

Logout from current session

Source§

impl ApiV3Client

Source

pub async fn create_share(&self, request: &ShareRequest) -> Result<Share, Error>

Create a share link Note: The V3 API may return either an ApiResponse object or a plain string URL

Source§

impl ApiV3Client

Source

pub async fn get_site_config(&self) -> Result<SiteConfig, Error>

Get site configuration

Source

pub async fn get_captcha(&mut self) -> Result<CaptchaResponse, Error>

Get CAPTCHA for login

Source

pub async fn is_captcha_required(&self) -> Result<bool, Error>

Check if CAPTCHA is required for login

Source

pub async fn get_user_storage(&self) -> Result<StorageInfo, Error>

Get user storage information

Source

pub async fn ping(&self) -> Result<String, Error>

Ping the server and get server version

Source

pub async fn get_version(&self) -> Result<VersionInfo, Error>

Get API version information

Source

pub async fn get_user_settings(&self) -> Result<UserSetting, Error>

Get user settings

Source

pub async fn get_task_queue(&self, page: i32) -> Result<UserTaskList, Error>

Get the user’s general task queue (GET /user/setting/tasks).

This endpoint is for Cloudreve’s broader task system (transfer, compress, etc.), not aria2 offline downloads. page is 1-based; Cloudreve returns at most ~10 entries per page along with the cumulative total.

Source§

impl ApiV3Client

Source

pub async fn get_webdav_accounts(&self) -> Result<Vec<WebdavAccount>, Error>

Get WebDAV accounts

Source§

impl ApiV3Client

Source

pub fn new(base_url: &str) -> Self

Source

pub fn get_url(&self, endpoint: &str) -> String

Source

pub async fn get<T>(&self, endpoint: &str) -> Result<T, Error>

Source

pub async fn post<T>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, Error>

Source

pub async fn post_raw( &self, endpoint: &str, body: &impl Serialize, ) -> Result<String, Error>

POST request that returns raw text instead of parsing JSON

Source

pub async fn put<T>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, Error>

Source

pub async fn patch<T>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, Error>

Source

pub async fn delete<T>(&self, endpoint: &str) -> Result<T, Error>

Source

pub async fn delete_with_body<T>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, Error>

Source

pub async fn put_text( &self, endpoint: &str, body: &impl Serialize, ) -> Result<String, Error>

PUT request that returns raw text response instead of JSON

Trait Implementations§

Source§

impl Clone for ApiV3Client

Source§

fn clone(&self) -> ApiV3Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ApiV3Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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: 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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