diff --git a/README.md b/README.md index 0fe78a5..9f30617 100644 --- a/README.md +++ b/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. diff --git a/src/details.rs b/src/details.rs index 37ddc50..1fc5e27 100644 --- a/src/details.rs +++ b/src/details.rs @@ -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, - 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 for std::time::SystemTime { + fn from(this: MaybeHumanDate) -> Self { + match this { + MaybeHumanDate::OldDate(old) => old.into(), + MaybeHumanDate::HumanDate(human) => human.into(), + } + } +}