@@ -33,7 +33,7 @@ import {
|
33 | 33 | readImageMetadataFromHeader, |
34 | 34 | readImageProbeFromHeader, |
35 | 35 | } from "./media-services.js"; |
36 | | -import { extractOriginalFilename } from "./store.js"; |
| 36 | +import { extractOriginalFilename, getMediaDir } from "./store.js"; |
37 | 37 | |
38 | 38 | export { getDefaultLocalRoots, LocalMediaAccessError }; |
39 | 39 | export type { LocalMediaAccessErrorCode }; |
@@ -285,6 +285,13 @@ function isPathInsideRoot(filePath: string | undefined, root: string): boolean {
|
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
| 288 | +function resolveLocalMediaFileName(filePath: string): string | undefined { |
| 289 | +const fileName = basenameFromAnyPath(filePath) || undefined; |
| 290 | +return fileName && isPathInsideRoot(filePath, getMediaDir()) |
| 291 | + ? extractOriginalFilename(fileName) |
| 292 | + : fileName; |
| 293 | +} |
| 294 | + |
288 | 295 | function hasHtmlDocumentShape(text: string): boolean { |
289 | 296 | const sample = text.trimStart().slice(0, 8192); |
290 | 297 | return /^(?:<!doctype\s+html\b|<html\b)/iu.test(sample) || /<\/(?:html|body)>/iu.test(sample); |
@@ -1075,10 +1082,7 @@ async function loadWebMediaInternal(
|
1075 | 1082 | trustedGeneratedHtmlPath, |
1076 | 1083 | }); |
1077 | 1084 | } |
1078 | | -let fileName = basenameFromAnyPath(mediaUrl) || undefined; |
1079 | | -if (fileName) { |
1080 | | -fileName = extractOriginalFilename(fileName); |
1081 | | -} |
| 1085 | +let fileName = resolveLocalMediaFileName(mediaUrl); |
1082 | 1086 | if (fileName && !extnameFromAnyPath(fileName) && mime) { |
1083 | 1087 | const ext = extensionForMime(mime); |
1084 | 1088 | if (ext) { |
|