From abd7489885ffcf76f7f9943ef9e4cd4c304f4d7c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 23 Jan 2024 20:05:39 +0100 Subject: use cache name for etag --- server/src/routes/ui/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'server/src/routes/ui/mod.rs') diff --git a/server/src/routes/ui/mod.rs b/server/src/routes/ui/mod.rs index 3a006a9..ea78ea5 100644 --- a/server/src/routes/ui/mod.rs +++ b/server/src/routes/ui/mod.rs @@ -17,6 +17,7 @@ use std::{ hash::{Hash, Hasher}, io::Cursor, os::unix::prelude::MetadataExt, + path::Path, pin::Pin, }; use tokio::{fs::File, io::AsyncRead}; @@ -66,9 +67,13 @@ impl AsyncRead for Defer { pub struct CacheControlFile(File, String); impl CacheControlFile { - pub async fn new(f: File) -> Self { + pub async fn new_cachekey(p: &Path) -> anyhow::Result { + let tag = p.file_name().unwrap().to_str().unwrap().to_owned(); + let f = File::open(p).await?; + Ok(Self(f, tag)) + } + pub async fn new_mtime(f: File) -> Self { let meta = f.metadata().await.unwrap(); - // TODO ETag should be cache path (or something like that) so federation clients can dedup assets let modified = meta.mtime(); let mut h = DefaultHasher::new(); modified.hash(&mut h); -- cgit v1.2.3-70-g09d2