support multiple media cache files

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-02-15 23:09:57 -05:00
parent 7c2b4775f1
commit 888a933e56
4 changed files with 17 additions and 5 deletions

View File

@@ -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") {

View File

@@ -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",
}
}
/*

View File

@@ -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};

View File

@@ -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;