Browse Source

Use rfc3339 dates for details responses

main
Aode (lion) 3 months ago
parent
commit
05533f7e3a
  1. 35
      README.md
  2. 20
      src/details.rs

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.

20
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<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…
Cancel
Save