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: ClientImplementations§
Source§impl ApiV3Client
impl ApiV3Client
Sourcepub async fn create_download(
&self,
request: &Aria2CreateRequest<'_>,
) -> Result<(), Error>
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.
Sourcepub async fn list_downloading(&self) -> Result<Vec<Aria2DownloadingTask>, Error>
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.
Sourcepub async fn list_finished(&self) -> Result<Vec<Aria2FinishedTask>, Error>
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§impl ApiV3Client
impl ApiV3Client
Sourcepub async fn list_directory(&self, path: &str) -> Result<DirectoryList, Error>
pub async fn list_directory(&self, path: &str) -> Result<DirectoryList, Error>
List directory contents
Sourcepub async fn create_directory(
&self,
request: &CreateDirectoryRequest<'_>,
) -> Result<(), Error>
pub async fn create_directory( &self, request: &CreateDirectoryRequest<'_>, ) -> Result<(), Error>
Create a directory
Source§impl ApiV3Client
impl ApiV3Client
Sourcepub async fn search_files(
&self,
keyword: &str,
path: &str,
) -> Result<DirectoryList, Error>
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.
pub async fn upload_file( &self, request: &UploadFileRequest<'_>, ) -> Result<UploadSession, Error>
pub async fn upload_chunk( &self, session_id: &str, chunk_index: u32, data: Vec<u8>, ) -> Result<(), Error>
Sourcepub async fn update_file_content(
&self,
id: &str,
content: Vec<u8>,
) -> Result<(), Error>
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。
Sourcepub async fn delete_upload_session(&self, session_id: &str) -> Result<(), Error>
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.
Sourcepub async fn delete_all_upload_sessions(&self) -> Result<(), Error>
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.
pub async fn download_file(&self, id: &str) -> Result<DownloadUrl, Error>
pub async fn get_file_source( &self, request: &FileSourceRequest, ) -> Result<Vec<FileSource>, Error>
Sourcepub async fn preview_file(&self, id: &str) -> Result<Vec<u8>, Error>
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 识别。
Sourcepub async fn get_thumbnail(&self, id: &str) -> Result<Vec<u8>, Error>
pub async fn get_thumbnail(&self, id: &str) -> Result<Vec<u8>, Error>
拉取缩略图(GET /file/thumb/{id})。
和 Self::preview_file 一样:301 跳转或原始图片字节,不是 JSON。
pub async fn create_file( &self, request: &CreateFileRequest<'_>, ) -> Result<(), Error>
Source§impl ApiV3Client
impl ApiV3Client
Sourcepub async fn get_object_property(
&self,
id: &str,
is_folder: Option<bool>,
trace_root: Option<bool>,
) -> Result<Property, Error>
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
Sourcepub async fn rename_object(
&self,
request: &RenameObjectRequest<'_>,
) -> Result<(), Error>
pub async fn rename_object( &self, request: &RenameObjectRequest<'_>, ) -> Result<(), Error>
Rename object
Sourcepub async fn move_object(
&self,
request: &MoveObjectRequest<'_>,
) -> Result<(), Error>
pub async fn move_object( &self, request: &MoveObjectRequest<'_>, ) -> Result<(), Error>
Move object
Sourcepub async fn copy_object(
&self,
request: &CopyObjectRequest<'_>,
) -> Result<(), Error>
pub async fn copy_object( &self, request: &CopyObjectRequest<'_>, ) -> Result<(), Error>
Copy object
Sourcepub async fn delete_object(
&self,
request: &DeleteObjectRequest<'_>,
) -> Result<(), Error>
pub async fn delete_object( &self, request: &DeleteObjectRequest<'_>, ) -> Result<(), Error>
Delete object
Source§impl ApiV3Client
impl ApiV3Client
Source§impl ApiV3Client
impl ApiV3Client
Create a share link
Note: The V3 API may return either an ApiResponse
Source§impl ApiV3Client
impl ApiV3Client
Sourcepub async fn get_site_config(&self) -> Result<SiteConfig, Error>
pub async fn get_site_config(&self) -> Result<SiteConfig, Error>
Get site configuration
Sourcepub async fn get_captcha(&mut self) -> Result<CaptchaResponse, Error>
pub async fn get_captcha(&mut self) -> Result<CaptchaResponse, Error>
Get CAPTCHA for login
Sourcepub async fn is_captcha_required(&self) -> Result<bool, Error>
pub async fn is_captcha_required(&self) -> Result<bool, Error>
Check if CAPTCHA is required for login
Sourcepub async fn get_user_storage(&self) -> Result<StorageInfo, Error>
pub async fn get_user_storage(&self) -> Result<StorageInfo, Error>
Get user storage information
Sourcepub async fn get_version(&self) -> Result<VersionInfo, Error>
pub async fn get_version(&self) -> Result<VersionInfo, Error>
Get API version information
Sourcepub async fn get_user_settings(&self) -> Result<UserSetting, Error>
pub async fn get_user_settings(&self) -> Result<UserSetting, Error>
Get user settings
Sourcepub async fn get_task_queue(&self, page: i32) -> Result<UserTaskList, Error>
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
impl ApiV3Client
Sourcepub async fn get_webdav_accounts(&self) -> Result<Vec<WebdavAccount>, Error>
pub async fn get_webdav_accounts(&self) -> Result<Vec<WebdavAccount>, Error>
Get WebDAV accounts
Source§impl ApiV3Client
impl ApiV3Client
pub fn new(base_url: &str) -> Self
pub fn get_url(&self, endpoint: &str) -> String
pub async fn get<T>(&self, endpoint: &str) -> Result<T, Error>where
T: DeserializeOwned + Debug,
pub async fn post<T>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, Error>where
T: DeserializeOwned + Debug,
Sourcepub async fn post_raw(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<String, Error>
pub async fn post_raw( &self, endpoint: &str, body: &impl Serialize, ) -> Result<String, Error>
POST request that returns raw text instead of parsing JSON
pub async fn put<T>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, Error>where
T: DeserializeOwned + Debug,
pub async fn patch<T>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, Error>where
T: DeserializeOwned + Debug,
pub async fn delete<T>(&self, endpoint: &str) -> Result<T, Error>where
T: DeserializeOwned + Debug,
pub async fn delete_with_body<T>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, Error>where
T: DeserializeOwned + Debug,
Trait Implementations§
Source§impl Clone for ApiV3Client
impl Clone for ApiV3Client
Source§fn clone(&self) -> ApiV3Client
fn clone(&self) -> ApiV3Client
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more