From a39e2501b81c1e52437839e018bd5bf07b46616c Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 9 Apr 2026 19:40:01 +0900 Subject: add image deletion --- src/App.svelte | 67 ++++++++++++++++++++++++++++++++++ src/lib/components/ImagePreview.svelte | 10 ++--- src/lib/flashair/client.ts | 22 +++++++++++ 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index a9a2506..bbc0c43 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,6 +1,7 @@
@@ -94,6 +134,16 @@ {/if} + +
+ + +{#if showDeleteConfirm && selectedFile !== undefined} + + + + +{/if} diff --git a/src/lib/components/ImagePreview.svelte b/src/lib/components/ImagePreview.svelte index 4a59d13..f5032a6 100644 --- a/src/lib/components/ImagePreview.svelte +++ b/src/lib/components/ImagePreview.svelte @@ -322,11 +322,7 @@ const abort = new AbortController(); currentAbort = abort; - downloading = true; - progress = 0; - loadError = undefined; - - // Try cache first + // Try cache first — before setting downloading=true to avoid flicker const cached = await imageCache.get('full', entry.path); if (cached !== undefined && !abort.signal.aborted) { const objectUrl = URL.createObjectURL(cached.blob); @@ -337,6 +333,10 @@ return; } + downloading = true; + progress = 0; + loadError = undefined; + const url = flashair.fileUrl(entry.path); const totalBytes = entry.size; diff --git a/src/lib/flashair/client.ts b/src/lib/flashair/client.ts index 978eb60..63ed6fb 100644 --- a/src/lib/flashair/client.ts +++ b/src/lib/flashair/client.ts @@ -196,6 +196,28 @@ export const flashair = { return { blob, meta }; }, + /** + * Delete a file from the FlashAir card. + * Requires UPLOAD=1 in the CONFIG file. + * @param path - Absolute path on the card, e.g. "/DCIM/100__TSB/DSC_0001.JPG" + */ + async deleteFile(path: string): Promise { + const base = getBaseUrl(); + const res = await fetch(`${base}/upload.cgi?DEL=${path}`); + if (!res.ok) { + if (res.status === 404) { + throw new Error( + 'File deletion is not enabled. Add UPLOAD=1 to /SD_WLAN/CONFIG on the SD card and restart the FlashAir.' + ); + } + throw new Error(`deleteFile failed: ${res.status} ${res.statusText}`); + } + const text = await res.text(); + if (text.trim() !== 'SUCCESS') { + throw new Error(`deleteFile failed: card returned ${text.trim()}`); + } + }, + /** * Recursively list all image files on the card starting from a root directory. * Returns files sorted by date, newest first. -- cgit v1.2.3