refactor: url parser

This commit is contained in:
codytseng 2025-08-24 15:54:13 +08:00
parent c53429fa6c
commit d6a5a82cf8
6 changed files with 77 additions and 49 deletions

View file

@ -117,10 +117,22 @@ export function isImage(url: string) {
}
}
export function isVideo(url: string) {
export function isMedia(url: string) {
try {
const videoExtensions = ['.mp4', '.webm', '.ogg', '.mov']
return videoExtensions.some((ext) => new URL(url).pathname.toLowerCase().endsWith(ext))
const mediaExtensions = [
'.mp4',
'.webm',
'.ogg',
'.mov',
'.mp3',
'.wav',
'.flac',
'.aac',
'.m4a',
'.opus',
'.wma'
]
return mediaExtensions.some((ext) => new URL(url).pathname.toLowerCase().endsWith(ext))
} catch {
return false
}