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:
committed by
Peter Steinberger
parent
8c0e290db1
commit
ddcc05f5f4
@@ -128,8 +128,12 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
|
|||||||
if (seen.has(raw.toLowerCase())) continue;
|
if (seen.has(raw.toLowerCase())) continue;
|
||||||
seen.add(raw.toLowerCase());
|
seen.add(raw.toLowerCase());
|
||||||
// Use fileURLToPath for proper handling (e.g., file://localhost/path)
|
// Use fileURLToPath for proper handling (e.g., file://localhost/path)
|
||||||
const resolved = fileURLToPath(raw);
|
try {
|
||||||
refs.push({ raw, type: "path", resolved });
|
const resolved = fileURLToPath(raw);
|
||||||
|
refs.push({ raw, type: "path", resolved });
|
||||||
|
} catch {
|
||||||
|
// Skip malformed file:// URLs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pattern for file paths (absolute, relative, or home)
|
// Pattern for file paths (absolute, relative, or home)
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ async function loadWebMediaInternal(
|
|||||||
const { maxBytes, optimizeImages = true } = options;
|
const { maxBytes, optimizeImages = true } = options;
|
||||||
// Use fileURLToPath for proper handling of file:// URLs (handles file://localhost/path, etc.)
|
// Use fileURLToPath for proper handling of file:// URLs (handles file://localhost/path, etc.)
|
||||||
if (mediaUrl.startsWith("file://")) {
|
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) => {
|
const optimizeAndClampImage = async (buffer: Buffer, cap: number) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user