You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
845 B
37 lines
845 B
/** |
|
* Check if URL is likely an image (extension or known image host). |
|
*/ |
|
export function isImageUrl(url: string): boolean { |
|
const imageExtensions = /\.(jpg|jpeg|png|gif|webp|svg|bmp|tiff|ico)(\?.*)?$/i |
|
const imageDomains = [ |
|
'i.nostr.build', |
|
'image.nostr.build', |
|
'nostr.build', |
|
'imgur.com', |
|
'imgur.io', |
|
'i.imgur.com', |
|
'cdn.discordapp.com', |
|
'media.discordapp.net', |
|
'pbs.twimg.com', |
|
'abs.twimg.com', |
|
'images.unsplash.com', |
|
'source.unsplash.com', |
|
'picsum.photos', |
|
'via.placeholder.com', |
|
'placehold.co', |
|
'placehold.it' |
|
] |
|
|
|
if (imageExtensions.test(url)) { |
|
return true |
|
} |
|
|
|
try { |
|
const urlObj = new URL(url) |
|
return imageDomains.some( |
|
(domain) => urlObj.hostname === domain || urlObj.hostname.endsWith('.' + domain) |
|
) |
|
} catch { |
|
return false |
|
} |
|
}
|
|
|