fix: improve error handling for file URL processing

- Enhanced error handling in image reference detection to skip malformed file URLs without crashing.
- Updated media loading logic to throw an error for invalid file URLs, ensuring better feedback for users.
This commit is contained in:
Tyler Yust
2026-01-17 03:29:22 -08:00
committed by Peter Steinberger
parent 8c0e290db1
commit ddcc05f5f4
2 changed files with 11 additions and 3 deletions

View File

@@ -27,7 +27,11 @@ async function loadWebMediaInternal(
const { maxBytes, optimizeImages = true } = options;
// Use fileURLToPath for proper handling of file:// URLs (handles file://localhost/path, etc.)
if (mediaUrl.startsWith("file://")) {
mediaUrl = fileURLToPath(mediaUrl);
try {
mediaUrl = fileURLToPath(mediaUrl);
} catch {
throw new Error(`Invalid file:// URL: ${mediaUrl}`);
}
}
const optimizeAndClampImage = async (buffer: Buffer, cap: number) => {