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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<void> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user