mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2025-04-15 04:34:21 +00:00
Use rfc3339 dates for details responses
This commit is contained in:
parent
7436f15267
commit
05533f7e3a
2 changed files with 23 additions and 32 deletions
35
README.md
35
README.md
|
@ -201,12 +201,7 @@ pict-rs offers the following endpoints:
|
|||
"width": 800,
|
||||
"height": 800,
|
||||
"content_type": "image/jpeg",
|
||||
"created_at": [
|
||||
2020,
|
||||
345,
|
||||
67376,
|
||||
394363487
|
||||
]
|
||||
"created_at": "2022-04-08T18:33:42.957791698Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -216,12 +211,7 @@ pict-rs offers the following endpoints:
|
|||
"width": 400,
|
||||
"height": 400,
|
||||
"content_type": "image/jpeg",
|
||||
"created_at": [
|
||||
2020,
|
||||
345,
|
||||
67376,
|
||||
394363487
|
||||
]
|
||||
"created_at": "2022-04-08T18:33:42.957791698Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -231,12 +221,7 @@ pict-rs offers the following endpoints:
|
|||
"width": 400,
|
||||
"height": 400,
|
||||
"content_type": "image/jpeg",
|
||||
"created_at": [
|
||||
2020,
|
||||
345,
|
||||
67376,
|
||||
394363487
|
||||
]
|
||||
"created_at": "2022-04-08T18:33:42.957791698Z"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -280,12 +265,7 @@ pict-rs offers the following endpoints:
|
|||
"width": 400,
|
||||
"height": 400,
|
||||
"content_type": "image/jpeg",
|
||||
"created_at": [
|
||||
2020,
|
||||
345,
|
||||
67376,
|
||||
394363487
|
||||
]
|
||||
"created_at": "2022-04-08T18:33:42.957791698Z"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -309,12 +289,7 @@ pict-rs offers the following endpoints:
|
|||
"width": 800,
|
||||
"height": 537,
|
||||
"content_type": "image/webp",
|
||||
"created_at": [
|
||||
2020,
|
||||
345,
|
||||
67376,
|
||||
394363487
|
||||
]
|
||||
"created_at": "2022-04-08T18:33:42.957791698Z"
|
||||
}
|
||||
```
|
||||
- `GET /image/process.{ext}?src={file}&...` get a file with transformations applied.
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
use crate::{error::Error, magick::ValidInputType, serde_str::Serde, store::Store};
|
||||
use actix_web::web;
|
||||
|
||||
#[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(untagged)]
|
||||
enum MaybeHumanDate {
|
||||
HumanDate(#[serde(with = "time::serde::rfc3339")] time::OffsetDateTime),
|
||||
OldDate(#[serde(serialize_with = "time::serde::rfc3339::serialize")] time::OffsetDateTime),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub(crate) struct Details {
|
||||
width: usize,
|
||||
height: usize,
|
||||
content_type: Serde<mime::Mime>,
|
||||
created_at: time::OffsetDateTime,
|
||||
created_at: MaybeHumanDate,
|
||||
}
|
||||
|
||||
impl Details {
|
||||
|
@ -49,7 +56,7 @@ impl Details {
|
|||
width,
|
||||
height,
|
||||
content_type: Serde::new(content_type),
|
||||
created_at: time::OffsetDateTime::now_utc(),
|
||||
created_at: MaybeHumanDate::HumanDate(time::OffsetDateTime::now_utc()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,3 +68,12 @@ impl Details {
|
|||
self.created_at.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MaybeHumanDate> for std::time::SystemTime {
|
||||
fn from(this: MaybeHumanDate) -> Self {
|
||||
match this {
|
||||
MaybeHumanDate::OldDate(old) => old.into(),
|
||||
MaybeHumanDate::HumanDate(human) => human.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue