aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-23 20:05:39 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-23 20:05:39 +0100
commitabd7489885ffcf76f7f9943ef9e4cd4c304f4d7c (patch)
tree4ee9cd8ad07f8ab7ec6fbcc822926037cadbd53e /server/src/routes
parent3ca7df883ab71c278086a593ed25699ce6b1a608 (diff)
downloadjellything-abd7489885ffcf76f7f9943ef9e4cd4c304f4d7c.tar
jellything-abd7489885ffcf76f7f9943ef9e4cd4c304f4d7c.tar.bz2
jellything-abd7489885ffcf76f7f9943ef9e4cd4c304f4d7c.tar.zst
use cache name for etag
Diffstat (limited to 'server/src/routes')
-rw-r--r--server/src/routes/ui/assets.rs3
-rw-r--r--server/src/routes/ui/mod.rs9
2 files changed, 8 insertions, 4 deletions
diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs
index d5d2839..7973b0c 100644
--- a/server/src/routes/ui/assets.rs
+++ b/server/src/routes/ui/assets.rs
@@ -19,7 +19,6 @@ pub use jellycommon::AssetRole;
use jellycommon::{AssetLocation, LocalTrack, PeopleGroup, SourceTrackKind, TrackSource};
use log::info;
use rocket::{get, http::ContentType, State};
-use tokio::fs::File;
#[get("/n/<id>/asset?<role>&<width>")]
pub async fn r_item_assets(
@@ -152,6 +151,6 @@ async fn asset_with_res(
info!("loading asset from {path:?}");
Ok((
ContentType::AVIF,
- CacheControlFile::new(File::open(path.path()).await.context("opening file")?).await,
+ CacheControlFile::new_cachekey(&path.path()).await?,
))
}
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<Self> {
+ 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);