pict-rs-aggregator/src/pict.rs

105 lines
2 KiB
Rust
Raw Normal View History

2021-09-19 19:32:04 +00:00
#[derive(Clone, Copy, Debug, serde::Deserialize)]
2020-12-08 21:59:55 +00:00
pub(crate) enum Extension {
2023-07-14 01:01:47 +00:00
#[serde(rename = "avif")]
Avif,
2020-12-08 21:59:55 +00:00
#[serde(rename = "jpg")]
Jpg,
#[serde(rename = "webp")]
Webp,
}
impl std::fmt::Display for Extension {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
2023-07-14 01:01:47 +00:00
Self::Avif => write!(f, "avif"),
2020-12-08 21:59:55 +00:00
Self::Jpg => write!(f, "jpg"),
Self::Webp => write!(f, "webp"),
}
}
}
#[derive(serde::Deserialize)]
pub(crate) struct Image {
file: String,
delete_token: String,
details: Details,
2020-12-08 21:59:55 +00:00
}
impl Image {
pub(crate) fn file(&self) -> &str {
&self.file
}
pub(crate) fn delete_token(&self) -> &str {
&self.delete_token
}
pub(crate) fn width(&self) -> u32 {
self.details.width
}
pub(crate) fn height(&self) -> u32 {
self.details.height
}
}
#[derive(serde::Deserialize)]
pub(crate) struct Details {
pub(super) width: u32,
pub(super) height: u32,
2020-12-08 21:59:55 +00:00
}
#[derive(serde::Deserialize)]
pub(crate) struct Images {
msg: String,
code: Option<String>,
2020-12-08 21:59:55 +00:00
files: Option<Vec<Image>>,
}
impl Images {
2022-05-27 23:27:44 +00:00
pub(crate) fn msg(&self) -> &str {
&self.msg
}
pub(crate) fn code(&self) -> Option<&str> {
self.code.as_deref()
}
2022-05-27 23:27:44 +00:00
pub(crate) fn files(&self) -> impl Iterator<Item = &Image> {
self.files.iter().flat_map(|v| v.iter())
}
}
#[derive(Clone, serde::Deserialize)]
pub(crate) struct Upload {
upload_id: String,
}
impl Upload {
pub(crate) fn id(&self) -> &str {
&self.upload_id
}
}
#[derive(serde::Deserialize)]
pub(crate) struct Uploads {
msg: String,
uploads: Option<Vec<Upload>>,
}
impl Uploads {
2020-12-08 21:59:55 +00:00
pub(crate) fn is_err(&self) -> bool {
2022-05-27 23:27:44 +00:00
self.uploads.is_none()
2020-12-08 21:59:55 +00:00
}
pub(crate) fn message(&self) -> &str {
&self.msg
}
2022-05-27 23:27:44 +00:00
pub(crate) fn files(&self) -> impl Iterator<Item = &Upload> {
self.uploads.iter().flat_map(|v| v.iter())
2020-12-08 21:59:55 +00:00
}
}