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, "width": 800,
"height": 800, "height": 800,
"content_type": "image/jpeg", "content_type": "image/jpeg",
"created_at": [ "created_at": "2022-04-08T18:33:42.957791698Z"
2020,
345,
67376,
394363487
]
} }
}, },
{ {
@ -216,12 +211,7 @@ pict-rs offers the following endpoints:
"width": 400, "width": 400,
"height": 400, "height": 400,
"content_type": "image/jpeg", "content_type": "image/jpeg",
"created_at": [ "created_at": "2022-04-08T18:33:42.957791698Z"
2020,
345,
67376,
394363487
]
} }
}, },
{ {
@ -231,12 +221,7 @@ pict-rs offers the following endpoints:
"width": 400, "width": 400,
"height": 400, "height": 400,
"content_type": "image/jpeg", "content_type": "image/jpeg",
"created_at": [ "created_at": "2022-04-08T18:33:42.957791698Z"
2020,
345,
67376,
394363487
]
} }
} }
], ],
@ -280,12 +265,7 @@ pict-rs offers the following endpoints:
"width": 400, "width": 400,
"height": 400, "height": 400,
"content_type": "image/jpeg", "content_type": "image/jpeg",
"created_at": [ "created_at": "2022-04-08T18:33:42.957791698Z"
2020,
345,
67376,
394363487
]
} }
} }
], ],
@ -309,12 +289,7 @@ pict-rs offers the following endpoints:
"width": 800, "width": 800,
"height": 537, "height": 537,
"content_type": "image/webp", "content_type": "image/webp",
"created_at": [ "created_at": "2022-04-08T18:33:42.957791698Z"
2020,
345,
67376,
394363487
]
} }
``` ```
- `GET /image/process.{ext}?src={file}&...` get a file with transformations applied. - `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 crate::{error::Error, magick::ValidInputType, serde_str::Serde, store::Store};
use actix_web::web; 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)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub(crate) struct Details { pub(crate) struct Details {
width: usize, width: usize,
height: usize, height: usize,
content_type: Serde<mime::Mime>, content_type: Serde<mime::Mime>,
created_at: time::OffsetDateTime, created_at: MaybeHumanDate,
} }
impl Details { impl Details {
@ -49,7 +56,7 @@ impl Details {
width, width,
height, height,
content_type: Serde::new(content_type), 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() 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(),
}
}
}