From c3c4734beb7b9650936b3c74df21d72a597cd94c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 6 Aug 2023 13:52:09 +0200 Subject: transcode images --- server/src/routes/ui/assets.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'server/src/routes/ui') diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 8a14133..2d175f9 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -8,7 +8,6 @@ use crate::{ routes::ui::{account::session::Session, error::MyError, CacheControlFile}, }; use anyhow::anyhow; -use jellybase::CONF; use jellycommon::AssetLocation; use log::info; use rocket::{get, http::ContentType, FromFormField, State, UriDisplayQuery}; @@ -29,7 +28,7 @@ pub async fn r_item_assets( db: &State, id: String, role: AssetRole, - width: Option, + width: Option, ) -> Result<(ContentType, CacheControlFile), MyError> { let node = db.node.get(&id)?.ok_or(anyhow!("node does not exist"))?; let mut asset = match role { @@ -48,27 +47,10 @@ pub async fn r_item_assets( let asset = asset.unwrap_or(AssetLocation::Assets( PathBuf::from_str("fallback.jpeg").unwrap(), )); - let path = asset.path(); + let path = jellytranscoder::image::transcode(asset, 50., 5, width.unwrap_or(2048))?; info!("loading asset from {path:?}"); - let ext = path - .extension() - .map(|e| e.to_str().unwrap()) - .unwrap_or("jpeg"); Ok(( - ContentType::from_extension(ext).unwrap(), + ContentType::AVIF, CacheControlFile::new(File::open(path).await?).await, )) } - -pub trait AssetLocationExt { - fn path(&self) -> PathBuf; -} -impl AssetLocationExt for AssetLocation { - fn path(&self) -> PathBuf { - match self { - AssetLocation::Assets(p) => CONF.asset_path.join(p), - AssetLocation::Cache(p) => CONF.cache_path.join(p), - AssetLocation::Library(p) => CONF.library_path.join(p), - } - } -} -- cgit v1.2.3-70-g09d2