From 6cb479acc61ab19f655cedd878283b214e352a3d Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 4 Oct 2022 23:55:44 +0300 Subject: media: Use ETag and If-None-Match Note: this requires a reindex of the media database. For the default CAS backend, use the following: ```bash for i in */*/*/*/*.json; do etag="$(echo $i | sed -e 's/\///g' -e 's/\.json$//')"; mv "$i" "$i.bak" cat "$i.bak" | jq '. + { "etag": '\""$etag"\"'}' > "$i" rm "$i.bak" done ``` This change is backwards compatible, but caching headers won't be emitted without etags present in the metadata. Actual etags are backend-specific and might differ from backend to backend. --- kittybox-rs/src/media/storage/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'kittybox-rs/src/media/storage/mod.rs') diff --git a/kittybox-rs/src/media/storage/mod.rs b/kittybox-rs/src/media/storage/mod.rs index b34da88..4ef7c7a 100644 --- a/kittybox-rs/src/media/storage/mod.rs +++ b/kittybox-rs/src/media/storage/mod.rs @@ -17,6 +17,8 @@ pub struct Metadata { pub filename: Option, /// The recorded length of the file. pub length: Option, + /// The e-tag of a file. Note: it must be a strong e-tag, for example, a hash. + pub etag: Option, } impl From<&Field<'_>> for Metadata { fn from(field: &Field<'_>) -> Self { @@ -25,7 +27,8 @@ impl From<&Field<'_>> for Metadata { .map(|i| i.to_owned()), filename: field.file_name() .map(|i| i.to_owned()), - length: None + length: None, + etag: None, } } } -- cgit 1.4.1