use std::fmt; use log::trace; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Hash)] pub struct Uri { protocol: String, base_url: String, } impl Uri { pub fn with_protocol(protocol: impl Into, base_url: impl Into) -> Self { Self { protocol: protocol.into(), base_url: base_url.into(), } } pub fn endpoint(&self, endpoint: impl fmt::Display) -> String { let uri = format!("{self}/{endpoint}"); trace!("endpoint: {uri:?}"); uri } } impl fmt::Display for Uri { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}://{}/api/v2", self.protocol, self.base_url) } } #[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(super) struct NewShareResponse { pub success: bool, pub message: String, pub id: String, } #[derive(Deserialize, Debug)] #[allow(dead_code)] pub(super) struct NotifyShareResponse { pub success: bool, pub message: String, }