use std::fmt; use log::trace; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct Uri(String); impl fmt::Display for Uri { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.0) } } impl AsRef<[u8]> for Uri { fn as_ref(&self) -> &[u8] { self.0.as_bytes() } } impl Uri { pub fn new(protocol: impl fmt::Display, base_url: impl fmt::Display) -> Self { Self(format!("{}://{}", protocol, base_url)) } fn endpoint(&self, path: fmt::Arguments) -> String { let uri = format!("{}/api/v2/{path}", self.0); 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, maxViews: u32, password: Option, } impl NewShareRequest { pub fn new( name: impl Into, description: Option>, 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, }