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 /server/src/routes | |
parent | ec8a9312a86d97e69d746bbbdbfb7228a37a26df (diff) | |
download | jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar.bz2 jellything-853a0022084a503b4747dfadd4e217b950ec6d8d.tar.zst |
dont transcode federated assets
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/ui/assets.rs | 38 |
1 files changed, 20 insertions, 18 deletions
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!(), } } |