images: make MediaCache hold MediaCacheType

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-29 11:05:08 -04:00
parent 7f01f3623d
commit d204db4b29
2 changed files with 13 additions and 10 deletions

View File

@@ -13,8 +13,8 @@ use std::time::{Duration, Instant, SystemTime};
use hex::ToHex;
use sha2::Digest;
use std::path::PathBuf;
use std::path::{self};
use std::path::{Path, PathBuf};
use tracing::warn;
pub type MediaCacheValue = Promise<Result<TexturedImage>>;
@@ -223,6 +223,7 @@ pub struct ImageFrame {
pub struct MediaCache {
pub cache_dir: path::PathBuf,
url_imgs: MediaCacheMap,
pub cache_type: MediaCacheType,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
@@ -232,10 +233,12 @@ pub enum MediaCacheType {
}
impl MediaCache {
pub fn new(cache_dir: path::PathBuf) -> Self {
pub fn new(parent_dir: &Path, cache_type: MediaCacheType) -> Self {
let cache_dir = parent_dir.join(Self::rel_dir(cache_type));
Self {
cache_dir,
url_imgs: HashMap::new(),
cache_type,
}
}
@@ -369,8 +372,8 @@ impl Images {
/// path to directory to place [`MediaCache`]s
pub fn new(path: path::PathBuf) -> Self {
Self {
static_imgs: MediaCache::new(path.join(MediaCache::rel_dir(MediaCacheType::Image))),
gifs: MediaCache::new(path.join(MediaCache::rel_dir(MediaCacheType::Gif))),
static_imgs: MediaCache::new(&path, MediaCacheType::Image),
gifs: MediaCache::new(&path, MediaCacheType::Gif),
urls: UrlMimes::new(UrlCache::new(path.join(UrlCache::rel_dir()))),
gif_states: Default::default(),
}