diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:11:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:47:29 +0100 |
commit | 7323709537c6ff14136cd79fb07606cd79391758 (patch) | |
tree | 3d817d449d4c0a821b9b5073c8acf826c6ccfda1 /transcoder/src/image.rs | |
parent | cbb2e163abfefd8ed61c41a096d5d6c27b4721b4 (diff) | |
download | jellything-7323709537c6ff14136cd79fb07606cd79391758.tar jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.bz2 jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.zst |
refactor asset system pt. 1
Diffstat (limited to 'transcoder/src/image.rs')
-rw-r--r-- | transcoder/src/image.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index 5df21a9..20f7e0c 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -6,37 +6,33 @@ use crate::LOCAL_IMAGE_TRANSCODING_TASKS; use anyhow::Context; use image::imageops::FilterType; -use jellybase::{cache::async_cache_file, AssetLocationExt}; -use jellycommon::AssetLocation; +use jellybase::cache::{async_cache_file, CachePath}; use log::{debug, info}; use rgb::FromSlice; use std::{ fs::File, io::{BufReader, Read, Seek, SeekFrom}, + path::PathBuf, }; use tokio::io::AsyncWriteExt; pub async fn transcode( - asset: AssetLocation, + path: PathBuf, quality: f32, speed: u8, width: usize, -) -> anyhow::Result<AssetLocation> { - let original_path = asset.path(); - let asset = asset.clone(); +) -> anyhow::Result<CachePath> { Ok(async_cache_file( &[ "image-tc", - original_path.as_os_str().to_str().unwrap(), + path.clone().as_os_str().to_str().unwrap(), &format!("{width} {quality} {speed}"), ], move |mut output| async move { let _permit = LOCAL_IMAGE_TRANSCODING_TASKS.acquire().await?; - info!("encoding {asset:?} (speed={speed}, quality={quality}, width={width})"); + info!("encoding {path:?} (speed={speed}, quality={quality}, width={width})"); let encoded = tokio::task::spawn_blocking(move || { - let original_path = asset.path(); - let mut file = - BufReader::new(File::open(&original_path).context("opening source")?); + let mut file = BufReader::new(File::open(&path).context("opening source")?); // TODO: use better image library that supports AVIF let is_avif = { |