Skip to main content

CyberdropClient

Struct CyberdropClient 

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

Async HTTP client for a subset of Cyberdrop endpoints.

Most higher-level methods map non-2xx responses to CyberdropError. For raw access where you want to inspect status codes and bodies directly, use CyberdropClient::get.

Implementations§

Source§

impl CyberdropClient

Source

pub fn new(base_url: impl AsRef<str>) -> Result<Self, CyberdropError>

Build a client with a custom base URL.

base_url is parsed as a Url. It is then used as the base for relative API paths via Url::join, so a trailing slash is recommended.

Source

pub fn builder() -> CyberdropClientBuilder

Start configuring a client with the crate’s defaults.

Defaults:

  • Base URL: https://cyberdrop.cr/
  • Timeout: 30 seconds
  • User agent: a browser-like UA string
Source

pub fn base_url(&self) -> &Url

Current base URL.

Source

pub fn auth_token(&self) -> Option<&str>

Current auth token if configured.

Source

pub fn with_auth_token(self, token: impl Into<String>) -> Self

Return a clone of this client that applies authentication to requests.

The token is attached as an HTTP header named token.

Source

pub async fn get_album_by_id( &self, album_id: u64, ) -> Result<Album, CyberdropError>

Source

pub async fn get( &self, path: impl AsRef<str>, ) -> Result<Response, CyberdropError>

Execute a GET request against a relative path on the configured base URL.

This method returns the raw reqwest::Response and does not convert non-2xx status codes into errors. If a token is configured, it will be attached, but authentication is not required.

§Errors

Returns CyberdropError::Http on transport failures (including timeouts). This method does not map HTTP status codes to CyberdropError variants.

Source

pub async fn login( &self, username: impl Into<String>, password: impl Into<String>, ) -> Result<AuthToken, CyberdropError>

Authenticate and retrieve a token.

The returned token can be installed on a client via CyberdropClient::with_auth_token or CyberdropClientBuilder::auth_token.

§Errors
Source

pub async fn register( &self, username: impl Into<String>, password: impl Into<String>, ) -> Result<AuthToken, CyberdropError>

Register a new account and retrieve a token.

The returned token can be installed on a client via CyberdropClient::with_auth_token or CyberdropClientBuilder::auth_token.

Note: the API returns HTTP 200 even for validation failures; this method converts {"success":false,...} responses into CyberdropError::Api.

§Errors
Source

pub async fn verify_token( &self, token: impl Into<String>, ) -> Result<TokenVerification, CyberdropError>

Verify a token and fetch associated permissions.

This request does not require the client to be authenticated; the token to verify is supplied in the request body.

§Errors
Source

pub async fn get_upload_url(&self) -> Result<Url, CyberdropError>

Fetch the upload node URL for the authenticated user.

Requires an auth token (see CyberdropClient::with_auth_token).

Source

pub async fn list_albums(&self) -> Result<AlbumsList, CyberdropError>

List albums for the authenticated user.

Requires an auth token (see CyberdropClient::with_auth_token).

§Errors
Source

pub async fn list_album_files( &self, album_id: u64, ) -> Result<AlbumFilesPage, CyberdropError>

List all files in an album (“folder”) by iterating pages until exhaustion.

This calls CyberdropClient::list_album_files_page repeatedly starting at page = 0 and stops when:

  • enough files have been collected to satisfy the API-reported count, or
  • a page returns zero files, or
  • a page yields no new file IDs (defensive infinite-loop guard).

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

An AlbumFilesPage containing all collected files. The returned count is the total file count as reported by the API.

§Errors

Any error returned by CyberdropClient::list_album_files_page.

Source

pub async fn list_album_files_page( &self, album_id: u64, page: u64, ) -> Result<AlbumFilesPage, CyberdropError>

List files in an album (“folder”) for a specific page.

Page numbers are zero-based (page = 0 is the first page). This is intentionally exposed so a higher-level pagination helper can be added later.

Requires an auth token (see CyberdropClient::with_auth_token).

§Errors
Source

pub async fn create_album( &self, name: impl Into<String>, description: Option<impl Into<String>>, ) -> Result<u64, CyberdropError>

Create a new album and return its numeric ID.

Requires an auth token. If the service reports that an album with a similar name already exists, this returns CyberdropError::AlbumAlreadyExists.

§Errors
Source

pub async fn edit_album( &self, id: u64, name: impl Into<String>, description: impl Into<String>, download: bool, public: bool, request_new_link: bool, ) -> Result<EditAlbumResult, CyberdropError>

Edit an existing album (“folder”).

This endpoint updates album metadata such as name/description and visibility flags. It can also request a new link identifier.

Requires an auth token.

§Returns

The API returns either a name (typical edits) or an identifier (when requesting a new link). This crate exposes both as optional fields on EditAlbumResult.

§Errors

Request a new public link identifier for an existing album, preserving its current settings.

This is a convenience wrapper around:

  1. CyberdropClient::list_albums (to fetch current album settings)
  2. CyberdropClient::edit_album with request_new_link = true

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

The new album public URL in the form https://cyberdrop.cr/a/<identifier>.

Note: this URL is always built against https://cyberdrop.cr/ (it does not use the client’s configured base URL).

§Errors
Source

pub async fn set_album_name( &self, album_id: u64, name: impl Into<String>, ) -> Result<EditAlbumResult, CyberdropError>

Update an album name, preserving existing description and visibility flags.

This is a convenience wrapper around:

  1. CyberdropClient::list_albums (to fetch current album settings)
  2. CyberdropClient::edit_album with request_new_link = false

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

The API response mapped into an EditAlbumResult.

§Errors
Source

pub async fn set_album_description( &self, album_id: u64, description: impl Into<String>, ) -> Result<EditAlbumResult, CyberdropError>

Update an album description, preserving existing name and visibility flags.

This is a convenience wrapper around:

  1. CyberdropClient::list_albums (to fetch current album settings)
  2. CyberdropClient::edit_album with request_new_link = false

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

The API response mapped into an EditAlbumResult.

§Errors
Source

pub async fn set_album_download( &self, album_id: u64, download: bool, ) -> Result<EditAlbumResult, CyberdropError>

Update an album download flag, preserving existing name/description and public flag.

This is a convenience wrapper around:

  1. CyberdropClient::list_albums (to fetch current album settings)
  2. CyberdropClient::edit_album with request_new_link = false

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

The API response mapped into an EditAlbumResult.

§Errors
Source

pub async fn set_album_public( &self, album_id: u64, public: bool, ) -> Result<EditAlbumResult, CyberdropError>

Update an album public flag, preserving existing name/description and download flag.

This is a convenience wrapper around:

  1. CyberdropClient::list_albums (to fetch current album settings)
  2. CyberdropClient::edit_album with request_new_link = false

Requires an auth token (see CyberdropClient::with_auth_token).

§Returns

The API response mapped into an EditAlbumResult.

§Errors
Source

pub async fn upload_file( &self, file_path: impl AsRef<Path>, album_id: Option<u64>, ) -> Result<UploadedFile, CyberdropError>

Upload a single file.

Requires an auth token.

Implementation notes:

  • Small files are streamed.
  • Large files are uploaded in chunks from disk.
  • Files larger than 95_000_000 bytes are uploaded in chunks.
  • If album_id is provided, it is sent as an albumid header on the chunk/single-upload requests and included in the finishchunks payload.
§Errors
Source

pub async fn upload_file_with_progress<F>( &self, file_path: impl AsRef<Path>, album_id: Option<u64>, on_progress: F, ) -> Result<UploadedFile, CyberdropError>
where F: FnMut(UploadProgress) + Send + 'static,

Upload a single file and emit per-file progress updates.

The on_progress callback is invoked as bytes are streamed or as chunks complete.

Trait Implementations§

Source§

impl Clone for CyberdropClient

Source§

fn clone(&self) -> CyberdropClient

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
Source§

impl Debug for CyberdropClient

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: 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