- `sharry::Client` fn signatures - `sharry::ClientError` rework - `file::Uploading` saves `file_id` instead of `patch_uri` - `impl sharry::Client for ureq::Agent` into separate file
87 lines
2.1 KiB
Rust
87 lines
2.1 KiB
Rust
use std::fmt;
|
|
|
|
use log::trace;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
|
pub struct Uri {
|
|
protocol: String,
|
|
base_url: String,
|
|
}
|
|
|
|
impl fmt::Display for Uri {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "{}://{}", self.protocol, self.base_url)
|
|
}
|
|
}
|
|
|
|
impl Uri {
|
|
pub fn new(protocol: impl Into<String>, base_url: impl Into<String>) -> Self {
|
|
Self {
|
|
protocol: protocol.into(),
|
|
base_url: base_url.into(),
|
|
}
|
|
}
|
|
|
|
fn endpoint(&self, path: fmt::Arguments) -> String {
|
|
let uri = format!("{}://{}/api/v2/{path}", self.protocol, self.base_url);
|
|
trace!("endpoint: {uri:?}");
|
|
uri
|
|
}
|
|
|
|
pub fn share_create(&self) -> String {
|
|
self.endpoint(format_args!("alias/upload/new"))
|
|
}
|
|
|
|
pub fn share_notify(&self, share_id: &str) -> String {
|
|
self.endpoint(format_args!("alias/mail/notify/{share_id}"))
|
|
}
|
|
|
|
pub fn file_create(&self, share_id: &str) -> String {
|
|
self.endpoint(format_args!("alias/upload/{share_id}/files/tus"))
|
|
}
|
|
|
|
pub fn file_patch(&self, share_id: &str, file_id: &str) -> String {
|
|
self.endpoint(format_args!("alias/upload/{share_id}/files/tus/{file_id}"))
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Debug)]
|
|
#[allow(non_snake_case)]
|
|
pub struct NewShareRequest {
|
|
name: String,
|
|
validity: u32,
|
|
description: Option<String>,
|
|
maxViews: u32,
|
|
password: Option<String>,
|
|
}
|
|
|
|
impl NewShareRequest {
|
|
pub fn new(
|
|
name: impl Into<String>,
|
|
description: Option<impl Into<String>>,
|
|
max_views: u32,
|
|
) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
validity: 0,
|
|
description: description.map(Into::into),
|
|
maxViews: max_views,
|
|
password: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct NewShareResponse {
|
|
pub success: bool,
|
|
pub message: String,
|
|
pub id: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
#[allow(dead_code)]
|
|
pub struct NotifyShareResponse {
|
|
pub success: bool,
|
|
pub message: String,
|
|
}
|