about summary refs log tree commit diff
path: root/kittybox-rs/src/media/storage
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs/src/media/storage')
-rw-r--r--kittybox-rs/src/media/storage/file.rs6
-rw-r--r--kittybox-rs/src/media/storage/mod.rs5
2 files changed, 9 insertions, 2 deletions
diff --git a/kittybox-rs/src/media/storage/file.rs b/kittybox-rs/src/media/storage/file.rs
index 1e0ff0e..42149aa 100644
--- a/kittybox-rs/src/media/storage/file.rs
+++ b/kittybox-rs/src/media/storage/file.rs
@@ -113,6 +113,7 @@ impl MediaStore for FileStore {
         let metapath = self.base.join(domain_str.as_str()).join(&metafilename);
         let metatemppath = self.base.join(domain_str.as_str()).join(metafilename + ".tmp");
         metadata.length = std::num::NonZeroUsize::new(length);
+        metadata.etag = Some(hex::encode(&hash));
         debug!("File path: {}, metadata: {}", filepath.display(), metapath.display());
         {
             let parent = filepath.parent().unwrap();
@@ -188,7 +189,8 @@ mod tests {
         let metadata = Metadata {
             filename: Some("style.css".to_string()),
             content_type: Some("text/css".to_string()),
-            length: None
+            length: None,
+            etag: None,
         };
 
         // write through the interface
@@ -216,6 +218,7 @@ mod tests {
         assert_eq!(meta.content_type.as_deref(), Some("text/css"));
         assert_eq!(meta.filename.as_deref(), Some("style.css"));
         assert_eq!(meta.length.map(|i| i.get()), Some(file.len()));
+        assert!(meta.etag.is_some());
 
         // read back the data using the interface
         let (metadata, read_back) = {
@@ -235,6 +238,7 @@ mod tests {
         assert_eq!(metadata.content_type.as_deref(), Some("text/css"));
         assert_eq!(meta.filename.as_deref(), Some("style.css"));
         assert_eq!(meta.length.map(|i| i.get()), Some(file.len()));
+        assert!(meta.etag.is_some());
 
     }
 }
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<String>,
     /// The recorded length of the file.
     pub length: Option<NonZeroUsize>,
+    /// The e-tag of a file. Note: it must be a strong e-tag, for example, a hash.
+    pub etag: Option<String>,
 }
 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,
         }
     }
 }