Use rfc3339 dates for details responses

This commit is contained in:
Aode (lion) 2022-04-08 13:36:06 -05:00
parent 7436f15267
commit 05533f7e3a
2 changed files with 23 additions and 32 deletions

View file

@ -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.

View file

@ -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(),
}
}
}