omegaupload/server/src/paste.rs

33 lines
842 B
Rust
Raw Normal View History

2021-10-16 16:50:11 +00:00
use axum::body::Bytes;
2021-10-22 01:35:54 +00:00
use chrono::Utc;
use omegaupload_common::Expiration;
2021-10-16 16:50:11 +00:00
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Paste {
2021-10-19 09:18:33 +00:00
pub expiration: Option<Expiration>,
2021-10-16 16:50:11 +00:00
pub bytes: Bytes,
}
impl Paste {
pub fn new(expiration: impl Into<Option<Expiration>>, bytes: Bytes) -> Self {
Self {
expiration: expiration.into(),
bytes,
}
}
pub fn expired(&self) -> bool {
self.expiration
.map(|expires| match expires {
Expiration::BurnAfterReading => false,
2021-10-19 09:18:33 +00:00
Expiration::UnixTime(expiration) => expiration < Utc::now(),
2021-10-16 16:50:11 +00:00
})
.unwrap_or_default()
}
pub const fn is_burn_after_read(&self) -> bool {
matches!(self.expiration, Some(Expiration::BurnAfterReading))
}
}