From 7323709537c6ff14136cd79fb07606cd79391758 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 24 Jan 2024 18:11:23 +0100 Subject: refactor asset system pt. 1 --- transcoder/src/image.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'transcoder/src/image.rs') 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 { - let original_path = asset.path(); - let asset = asset.clone(); +) -> anyhow::Result { 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 = { -- cgit v1.2.3-70-g09d2