diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-01-24 23:06:33 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-01-24 23:06:33 +0100 |
| commit | 2bcccb18a6cb8bf836f57c3d86f759b19699def2 (patch) | |
| tree | ef55a10c6d9703677a983b8ca900fb4578a08eb3 /transcoder/src/image.rs | |
| parent | b2e88a8beabf04adc28947cf82996e8692a68b71 (diff) | |
| download | jellything-2bcccb18a6cb8bf836f57c3d86f759b19699def2.tar jellything-2bcccb18a6cb8bf836f57c3d86f759b19699def2.tar.bz2 jellything-2bcccb18a6cb8bf836f57c3d86f759b19699def2.tar.zst | |
cache as object
Diffstat (limited to 'transcoder/src/image.rs')
| -rw-r--r-- | transcoder/src/image.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index 14b3e53..eaf8b86 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -3,21 +3,29 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use image::imageops::FilterType; -use jellycache::{cache, cache_read, HashKey}; +use jellycache::{Cache, HashKey}; use log::{debug, info}; use rgb::FromSlice; use std::io::Cursor; -pub fn transcode(key: &str, quality: u32, speed: u8, width: usize) -> Result<Vec<u8>> { - cache( +pub fn transcode( + cache: &Cache, + key: &str, + quality: u32, + speed: u8, + width: usize, +) -> Result<Vec<u8>> { + cache.cache( &format!( "transcode/image/{}-W{width}-Q{quality}-S{speed}", HashKey(key) ), move || { - let input = cache_read(key)?.ok_or(anyhow!("transcode cache key missing"))?; + let input = cache + .read(key)? + .ok_or(anyhow!("transcode cache key missing"))?; info!("encoding image (speed={speed}, quality={quality}, width={width})"); // TODO: use better image library that supports AVIF |