From 6d46a70b7ac76388a52609bcabb7cc97f3da5184 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 27 Jan 2026 19:30:54 +0200 Subject: [PATCH] Fix native draft media filename encoding The previous approach replaced both / and : with _, but the reverse transformation couldn't distinguish between them. This caused cache misses for paths containing both characters. Use encodeURIComponent/decodeURIComponent for a proper reversible encoding. Co-Authored-By: Claude Opus 4.5 --- src/view/com/composer/drafts/state/storage.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/view/com/composer/drafts/state/storage.ts b/src/view/com/composer/drafts/state/storage.ts index 95fcea6b66..557e51fa6c 100644 --- a/src/view/com/composer/drafts/state/storage.ts +++ b/src/view/com/composer/drafts/state/storage.ts @@ -13,8 +13,8 @@ function getMediaDirectory(): Directory { } function getMediaFile(localRefPath: string): File { - // Use localRefPath as filename (replace unsafe chars) - const safeFilename = localRefPath.replace(/[/:]/g, '_') + // Use localRefPath as filename (URL-encoded for filesystem safety) + const safeFilename = encodeURIComponent(localRefPath) return new File(getMediaDirectory(), safeFilename) } @@ -123,8 +123,8 @@ function populateCacheInternal(): Promise { if (dir.exists) { const items = dir.list() for (const item of items) { - // Reverse the safe filename transformation - const localRefPath = item.name.replace(/_/g, ':').replace(/_/g, '/') + // Reverse the URL encoding to get the original localRefPath + const localRefPath = decodeURIComponent(item.name) mediaExistsCache.set(localRefPath, true) } }