diff options
author | metamuffin <metamuffin@disroot.org> | 2024-04-10 14:35:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-04-10 14:35:34 +0200 |
commit | 853a0022084a503b4747dfadd4e217b950ec6d8d (patch) | |
tree | 680e65fd0c5d37d416e1e4db3e0f1dd2d8064e17 | |
parent | ec8a9312a86d97e69d746bbbdbfb7228a37a26df (diff) | |
download | jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar.bz2 jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar.zst |
dont transcode federated assets
-rw-r--r-- | base/src/assetfed.rs | 8 | ||||
-rw-r--r-- | server/src/routes/ui/assets.rs | 38 | ||||
-rw-r--r-- | web/script/player/mod.ts | 2 |
3 files changed, 29 insertions, 19 deletions
diff --git a/base/src/assetfed.rs b/base/src/assetfed.rs index e7c0124..4ca587b 100644 --- a/base/src/assetfed.rs +++ b/base/src/assetfed.rs @@ -69,4 +69,12 @@ impl AssetInner { .context("asset token has invalid format")?; Ok(data) } + + /// Returns `true` if the asset inner is [`Federated`]. + /// + /// [`Federated`]: AssetInner::Federated + #[must_use] + pub fn is_federated(&self) -> bool { + matches!(self, Self::Federated { .. }) + } } diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 5b9f70e..115c02a 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -27,16 +27,27 @@ pub async fn r_asset( token: &str, width: Option<usize>, ) -> MyResult<(ContentType, CacheControlFile)> { + let width = width.unwrap_or(2048); let asset = AssetInner::deser(token)?; - let source = resolve_asset(asset, fed).await.context("resolving asset")?; + let path = if let AssetInner::Federated { host, asset } = asset { + let session = fed.get_session(&host).await?; - // fit the resolution into a finite set so the maximum cache is finite too. - let width = 2usize.pow(width.unwrap_or(2048).clamp(128, 2048).ilog2()); - // TODO configure avif quality and speed. - let path = jellytranscoder::image::transcode(source, 50., 5, width) - .await - .context("transcoding asset")?; + let asset = base64::engine::general_purpose::URL_SAFE.encode(asset); + async_cache_file(&["fed-asset", &asset], |out| async { + session.asset(out, &asset, width).await + }) + .await? + } else { + let source = resolve_asset(asset).await.context("resolving asset")?; + + // fit the resolution into a finite set so the maximum cache is finite too. + let width = 2usize.pow(width.clamp(128, 2048).ilog2()); + // TODO configure avif quality and speed. + jellytranscoder::image::transcode(source, 50., 5, width) + .await + .context("transcoding asset")? + }; info!("loading asset from {path:?}"); Ok(( ContentType::AVIF, @@ -44,21 +55,12 @@ pub async fn r_asset( )) } -pub async fn resolve_asset(asset: AssetInner, fed: &State<Federation>) -> anyhow::Result<PathBuf> { +pub async fn resolve_asset(asset: AssetInner) -> anyhow::Result<PathBuf> { match asset { - AssetInner::Federated { host, asset } => { - let session = fed.get_session(&host).await?; - - let asset = base64::engine::general_purpose::URL_SAFE.encode(asset); - Ok(async_cache_file(&["fed-asset", &asset], |out| async { - session.asset(out, &asset, 2048).await - }) - .await? - .abs()) - } AssetInner::Cache(c) => Ok(c.abs()), AssetInner::Assets(c) => Ok(CONF.asset_path.join(c)), AssetInner::Library(c) => Ok(CONF.library_path.join(c)), + _ => unreachable!(), } } diff --git a/web/script/player/mod.ts b/web/script/player/mod.ts index 3774c62..59aae99 100644 --- a/web/script/player/mod.ts +++ b/web/script/player/mod.ts @@ -310,7 +310,7 @@ function send_player_progress(node_id: string, player: Player) { function mouse_idle(e: HTMLElement, timeout: number): OVar<boolean> { let ct: number; const idle = new OVar(false) - e.onmouseleave = () => { + e.onmouseleave = () => { clearTimeout(ct) } e.onmousemove = () => { |