use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub(crate) enum WaifuApiResponse {
WaifuResponse(WaifuResponse),
WaifuError(WaifuError),
Delete(bool),
}
#[derive(Debug, Deserialize, Clone)]
pub struct WaifuResponse {
pub token: String,
pub url: String,
#[serde(rename = "retentionPeriod")]
pub retention_period: serde_json::Value,
pub options: Option<WaifuResponseOptions>,
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
pub struct WaifuResponseOptions {
#[serde(rename = "hideFilename")]
pub hide_filename: bool,
#[serde(rename = "oneTimeDownload")]
pub one_time_download: bool,
pub protected: bool,
}
#[derive(Debug, Deserialize, Clone)]
pub struct WaifuError {
pub name: String,
pub message: String,
pub status: u16,
}
impl std::fmt::Display for WaifuError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"WaifuError {} ({})\nMessage: {}",
self.name, self.status, self.message
)
}
}
impl std::error::Error for WaifuError {}
#[derive(Debug, Default, Clone)]
pub struct WaifuUploadRequest {
pub(crate) file: Option<String>,
pub(crate) url: Option<String>,
pub(crate) bytes: Option<Vec<u8>>,
pub(crate) filename: Option<String>,
pub(crate) expires: Option<String>,
pub(crate) hide_filename: bool,
pub(crate) password: Option<String>,
pub(crate) one_time_download: bool,
}
impl WaifuUploadRequest {
pub fn new() -> Self {
Self::default()
}
pub fn file(mut self, file: impl AsRef<Path>) -> Self {
let file = file.as_ref().display().to_string();
self.file = Some(file);
self
}
pub fn url(mut self, url: impl AsRef<str>) -> Self {
self.url = Some(url.as_ref().to_string());
self
}
pub fn bytes(mut self, bytes: Vec<u8>, filename: impl AsRef<str>) -> Self {
self.bytes = Some(bytes);
self.filename = Some(filename.as_ref().to_string());
self
}
pub fn expires(mut self, expires: impl AsRef<str>) -> Self {
self.expires = Some(expires.as_ref().to_string());
self
}
pub fn hide_filename(mut self, hide: bool) -> Self {
self.hide_filename = hide;
self
}
pub fn password(mut self, password: impl AsRef<str>) -> Self {
self.password = Some(password.as_ref().to_string());
self
}
pub fn one_time_download(mut self, otd: bool) -> Self {
self.one_time_download = otd;
self
}
}
#[derive(Debug, Default, Clone)]
pub struct WaifuGetRequest {
pub(crate) token: String,
pub(crate) formatted: bool,
}
impl WaifuGetRequest {
pub fn new(token: impl AsRef<str>) -> Self {
Self {
token: token.as_ref().to_string(),
..Default::default()
}
}
pub fn formatted(mut self, format: bool) -> Self {
self.formatted = format;
self
}
}
#[derive(Debug, Default, Clone, Serialize)]
pub struct WaifuModificationRequest {
#[serde(skip)]
pub(crate) token: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) password: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "previousPassword")]
pub(crate) previous_password: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "customExpiry")]
pub(crate) custom_expiry: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "hideFilename")]
pub(crate) hide_filename: Option<bool>,
}
impl WaifuModificationRequest {
pub fn new(token: impl AsRef<str>) -> Self {
Self {
token: token.as_ref().to_string(),
..Default::default()
}
}
pub fn password(mut self, password: impl AsRef<str>) -> Self {
self.password = Some(password.as_ref().to_string());
self
}
pub fn previous_password(mut self, prev_pwd: impl AsRef<str>) -> Self {
self.previous_password = Some(prev_pwd.as_ref().to_string());
self
}
pub fn custom_expiry(mut self, expiry: impl AsRef<str>) -> Self {
self.custom_expiry = Some(expiry.as_ref().to_string());
self
}
pub fn hide_filename(mut self, hide: bool) -> Self {
self.hide_filename = Some(hide);
self
}
}