2025-05-22 17:34:44 +00:00
|
|
|
use log::debug;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2025-05-22 21:07:49 +00:00
|
|
|
pub struct URI {
|
2025-05-22 17:34:44 +00:00
|
|
|
protocol: String,
|
|
|
|
|
base_url: String,
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 21:07:49 +00:00
|
|
|
impl URI {
|
|
|
|
|
pub fn new_protocol(base_url: &str, protocol: &str) -> Self {
|
2025-05-22 17:34:44 +00:00
|
|
|
Self {
|
2025-05-22 21:07:49 +00:00
|
|
|
protocol: protocol.into(),
|
2025-05-22 17:34:44 +00:00
|
|
|
base_url: base_url.into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 21:07:49 +00:00
|
|
|
pub fn new(base_url: &str) -> Self {
|
|
|
|
|
Self::new_protocol(base_url, "https")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_endpoint(&self, endpoint: &str) -> String {
|
2025-05-22 17:34:44 +00:00
|
|
|
let uri = format!("{}://{}/api/v2/{}", self.protocol, self.base_url, endpoint);
|
|
|
|
|
debug!("uri: {:?}", uri);
|
|
|
|
|
|
|
|
|
|
uri
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
|
pub struct NewShareRequest<'t> {
|
|
|
|
|
name: Option<&'t str>,
|
|
|
|
|
validity: u32,
|
|
|
|
|
description: &'t str,
|
|
|
|
|
maxViews: u32,
|
|
|
|
|
password: Option<&'t str>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'t> NewShareRequest<'t> {
|
|
|
|
|
pub fn new(name: Option<&'t str>, description: &'t str, max_views: u32) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
name: name,
|
|
|
|
|
validity: 0,
|
|
|
|
|
description: description,
|
|
|
|
|
maxViews: max_views,
|
|
|
|
|
password: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
|
pub struct NewShareResponse {
|
|
|
|
|
pub success: bool,
|
|
|
|
|
pub message: String,
|
|
|
|
|
pub id: String,
|
|
|
|
|
}
|
2025-05-22 21:07:49 +00:00
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
pub struct NotifyShareResponse {
|
|
|
|
|
pub success: bool,
|
|
|
|
|
pub message: String,
|
|
|
|
|
}
|