shrupl/src/sharry/api.rs

64 lines
1.4 KiB
Rust

use std::fmt::Display;
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<String>, base_url: impl Into<String>) -> Self {
Self {
protocol: protocol.into(),
base_url: base_url.into(),
}
}
}
impl Display for Uri {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}://{}/api/v2", self.protocol, self.base_url)
}
}
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct NewShareRequest {
name: String,
validity: u32,
description: Option<String>,
maxViews: u32,
password: Option<String>,
}
impl NewShareRequest {
pub fn new(
name: impl Into<String>,
description: Option<impl Into<String>>,
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,
}