use std::time::{Duration, SystemTime};
use serde::{Deserialize, Serialize};
use serde_json::Value;
pub(super) mod response {
use serde_json::Value;
#[derive(Debug)]
pub struct MyustResponse {
pub json: Option<Value>,
pub status_code: u16,
}
}
#[derive(Debug, Default)]
pub struct MystbinError {
pub code: u16,
pub error: Option<String>,
pub notice: Option<String>,
pub detail: Option<Value>,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct Expiry {
pub days: i32,
pub hours: i32,
pub minutes: i32,
pub seconds: i32,
}
impl Expiry {
fn total(&self) -> Duration {
let days = self.days * 24 * 60 * 60;
let hours = self.hours * 60 * 60;
let minutes = self.minutes * 60;
Duration::from_secs((days + hours + minutes + self.seconds) as u64)
}
fn add(&self) -> SystemTime {
let current_time = SystemTime::now();
match current_time.checked_add(self.total()) {
Some(new_time) => new_time,
None => current_time, }
}
fn to_vec(&self) -> Vec<(&str, i32)> {
vec![
("days", self.days),
("hours", self.hours),
("minutes", self.minutes),
("seconds", self.seconds),
]
}
pub(crate) fn invalid_field(&self) -> (String, i32) {
let expiry_vec = self.to_vec();
for field in &expiry_vec {
if field.1 < 0 {
return (field.0.to_string(), field.1);
}
}
(expiry_vec[0].0.to_string(), expiry_vec[0].1)
}
pub(crate) fn valid(&self) -> bool {
self.days >= 0 && self.hours >= 0 && self.minutes >= 0 && self.seconds >= 0
}
pub(crate) fn is_default(&self) -> bool {
*self == Self::default()
}
pub(crate) fn to_rfc3339(&self) -> String {
let form = humantime::format_rfc3339(self.add()).to_string();
form.replace("00Z", "+00:00")
}
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct File {
pub filename: String,
pub content: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Paste {
pub created_at: String,
pub expires: Option<Expiry>,
pub files: Vec<File>,
pub id: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct PasteResult {
pub created_at: String,
pub expires: Option<String>,
pub files: Vec<File>,
pub id: String,
}
#[derive(Debug, Default)]
pub struct DeleteResult {
pub succeeded: Option<Vec<String>>,
pub failed: Option<Vec<String>>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UserPaste {
pub created_at: String,
pub expires: Option<String>,
pub id: String,
}