From bafc36cbb2287ecb3b806cb32118a9ee9d5f7170 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 9 Apr 2026 19:55:19 +0900 Subject: auto-caching setup --- src/App.svelte | 23 ++- src/lib/cache/autoCacheService.ts | 255 ++++++++++++++++++++++++++++++ src/lib/cache/index.ts | 1 + src/lib/components/CachedThumbnail.svelte | 38 ++++- src/lib/components/ImagePreview.svelte | 13 ++ 5 files changed, 323 insertions(+), 7 deletions(-) create mode 100644 src/lib/cache/autoCacheService.ts diff --git a/src/App.svelte b/src/App.svelte index bbc0c43..7d99875 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,6 +2,7 @@ import { flashair } from './lib/flashair'; import type { FlashAirFileEntry } from './lib/flashair'; import { imageCache } from './lib/cache'; + import { autoCacheService } from './lib/cache'; import ImageList from './lib/components/ImageList.svelte'; import ImagePreview from './lib/components/ImagePreview.svelte'; @@ -20,11 +21,15 @@ async function loadAllImages() { loading = true; error = undefined; + autoCacheService.stop(); try { images = await flashair.listAllImages('/DCIM'); if (images.length > 0 && selectedFile === undefined) { selectedFile = images[0]; } + if (images.length > 0) { + autoCacheService.start(images); + } } catch (e) { error = e instanceof Error ? e.message : String(e); images = []; @@ -50,9 +55,10 @@ deleting = true; try { await flashair.deleteFile(fileToDelete.path); - // Remove from cache + // Remove from cache and auto-cache queue void imageCache.delete('thumbnail', fileToDelete.path); void imageCache.delete('full', fileToDelete.path); + autoCacheService.removeImage(fileToDelete.path); // Remove from list and select next image const idx = images.findIndex((f) => f.path === fileToDelete.path); images = images.filter((f) => f.path !== fileToDelete.path); @@ -73,6 +79,15 @@ function cancelDelete() { showDeleteConfirm = false; } + + async function clearAllCache() { + autoCacheService.stop(); + await imageCache.clear(); + // Restart auto-caching from scratch + if (images.length > 0) { + autoCacheService.start(images); + } + }
@@ -144,6 +159,12 @@ {/if} + +