diff options
author | metamuffin <metamuffin@disroot.org> | 2023-08-06 13:52:09 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-08-06 13:52:09 +0200 |
commit | c3c4734beb7b9650936b3c74df21d72a597cd94c (patch) | |
tree | 3728d62a70cfc65231beac41ae62f0da4d971308 /server/src/routes/ui/assets.rs | |
parent | 8551bf2e34d9543fa41a83fae785ed81d6a6c10f (diff) | |
download | jellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar jellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar.bz2 jellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar.zst |
transcode images
Diffstat (limited to 'server/src/routes/ui/assets.rs')
-rw-r--r-- | server/src/routes/ui/assets.rs | 24 |
1 files changed, 3 insertions, 21 deletions
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<Database>, id: String, role: AssetRole, - width: Option<u32>, + width: Option<usize>, ) -> 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), - } - } -} |