From 888a933e56fafa1b4dc59e5d79861b131662d24c Mon Sep 17 00:00:00 2001 From: kernelkind Date: Sat, 15 Feb 2025 23:09:57 -0500 Subject: [PATCH] support multiple media cache files Signed-off-by: kernelkind --- crates/notedeck/src/app.rs | 4 +++- crates/notedeck/src/imgcache.rs | 12 ++++++++++-- crates/notedeck/src/lib.rs | 2 +- crates/notedeck_columns/src/app.rs | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs index 170cef8..8cc79b5 100644 --- a/crates/notedeck/src/app.rs +++ b/crates/notedeck/src/app.rs @@ -129,7 +129,9 @@ impl Notedeck { let _ = std::fs::create_dir_all(&dbpath_str); - let img_cache_dir = path.path(DataPathType::Cache).join(MediaCache::rel_dir()); + let img_cache_dir = path + .path(DataPathType::Cache) + .join(MediaCache::rel_dir(crate::imgcache::MediaCacheType::Image)); let _ = std::fs::create_dir_all(img_cache_dir.clone()); let map_size = if cfg!(target_os = "windows") { diff --git a/crates/notedeck/src/imgcache.rs b/crates/notedeck/src/imgcache.rs index 509cff3..0ba841d 100644 --- a/crates/notedeck/src/imgcache.rs +++ b/crates/notedeck/src/imgcache.rs @@ -25,6 +25,11 @@ pub struct MediaCache { url_imgs: MediaCacheMap, } +pub enum MediaCacheType { + Image, + Gif, +} + impl MediaCache { pub fn new(cache_dir: path::PathBuf) -> Self { Self { @@ -33,8 +38,11 @@ impl MediaCache { } } - pub fn rel_dir() -> &'static str { - "img" + pub fn rel_dir(cache_type: MediaCacheType) -> &'static str { + match cache_type { + MediaCacheType::Image => "img", + MediaCacheType::Gif => "gif", + } } /* diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs index 49e70d8..78f6892 100644 --- a/crates/notedeck/src/lib.rs +++ b/crates/notedeck/src/lib.rs @@ -31,7 +31,7 @@ pub use context::AppContext; pub use error::{Error, FilterError}; pub use filter::{FilterState, FilterStates, UnifiedSubscription}; pub use fonts::NamedFontFamily; -pub use imgcache::{get_texture, MediaCache, TexturedImage}; +pub use imgcache::{get_texture, MediaCache, MediaCacheType, TexturedImage}; pub use muted::{MuteFun, Muted}; pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf}; pub use notecache::{CachedNote, NoteCache}; diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs index 568001d..c624aed 100644 --- a/crates/notedeck_columns/src/app.rs +++ b/crates/notedeck_columns/src/app.rs @@ -464,7 +464,9 @@ impl Damus { let decks_cache = DecksCache::default(); let path = DataPath::new(&data_path); - let imgcache_dir = path.path(DataPathType::Cache).join(MediaCache::rel_dir()); + let imgcache_dir = path + .path(DataPathType::Cache) + .join(MediaCache::rel_dir(notedeck::MediaCacheType::Image)); let _ = std::fs::create_dir_all(imgcache_dir.clone()); let debug = true;