shrupl/src/sharry/api.rs

71 lines
1.5 KiB
Rust
Raw Normal View History

2025-05-23 01:11:11 +00:00
use std::fmt::Display;
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 {
2025-05-23 01:11:11 +00:00
pub fn new_protocol(base_url: impl Into<String>, protocol: impl Into<String>) -> 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-23 01:11:11 +00:00
pub fn new(base_url: impl Into<String>) -> Self {
2025-05-22 21:07:49 +00:00
Self::new_protocol(base_url, "https")
}
2025-05-23 22:13:17 +00:00
pub(super) fn get_endpoint(&self, endpoint: impl Display) -> 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)]
2025-05-23 01:11:11 +00:00
pub struct NewShareRequest {
name: Option<String>,
2025-05-22 17:34:44 +00:00
validity: u32,
2025-05-23 01:11:11 +00:00
description: String,
2025-05-22 17:34:44 +00:00
maxViews: u32,
2025-05-23 01:11:11 +00:00
password: Option<String>,
2025-05-22 17:34:44 +00:00
}
2025-05-23 01:11:11 +00:00
impl NewShareRequest {
pub fn new(
name: Option<impl Into<String>>,
description: impl Into<String>,
max_views: u32,
) -> Self {
2025-05-22 17:34:44 +00:00
Self {
2025-05-23 01:11:11 +00:00
name: name.map(Into::into),
2025-05-22 17:34:44 +00:00
validity: 0,
2025-05-23 01:11:11 +00:00
description: description.into(),
2025-05-22 17:34:44 +00:00
maxViews: max_views,
password: None,
}
}
}
#[derive(Deserialize, Debug)]
2025-05-23 22:13:17 +00:00
pub(super) struct NewShareResponse {
2025-05-22 17:34:44 +00:00
pub success: bool,
pub message: String,
pub id: String,
}
2025-05-22 21:07:49 +00:00
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
2025-05-23 22:13:17 +00:00
pub(super) struct NotifyShareResponse {
2025-05-22 21:07:49 +00:00
pub success: bool,
pub message: String,
}