2025-06-25 23:42:00 +00:00
|
|
|
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"))
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 01:47:38 +00:00
|
|
|
pub fn share_notify(&self, share_id: &super::ShareID) -> String {
|
2025-06-25 23:42:00 +00:00
|
|
|
self.endpoint(format_args!("alias/mail/notify/{share_id}"))
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 01:47:38 +00:00
|
|
|
pub fn file_create(&self, share_id: &super::ShareID) -> String {
|
2025-06-25 23:42:00 +00:00
|
|
|
self.endpoint(format_args!("alias/upload/{share_id}/files/tus"))
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 01:47:38 +00:00
|
|
|
pub fn file_patch(&self, share_id: &super::ShareID, file_id: &super::FileID) -> String {
|
2025-06-25 23:42:00 +00:00
|
|
|
self.endpoint(format_args!("alias/upload/{share_id}/files/tus/{file_id}"))
|
|
|
|
|
}
|
|
|
|
|
}
|