fix: error with MdImage & invalid url

This commit is contained in:
Xylight committed 2025-10-28 20:49:22 -07:00
1 parent 537e1c4cea
commit 3942535831
2 files changed
+15 -4

No files matched your search

+12 -1
View File
@@ -31,7 +31,12 @@ export const optimizeImageURL = (
format: 'avif' | 'webp' | null = 'webp',
): string => {
try {
const url = new URL(urlStr)
let url: URL
try {
url = new URL(urlStr)
} catch {
return urlStr
}
if (format) url.searchParams.set('format', format)
@@ -70,6 +75,12 @@ export type IframeType = 'youtube' | 'video' | 'none'
export function mediaType(url?: string): MediaType {
if (!url) return 'none'
try {
new URL(url)
} catch {
return 'none'
}
if (isImage(url)) return 'image'
if (isVideo(url)) return 'iframe'
if (isYoutubeLink(url)) return 'iframe'