export type FileType = 'image' | 'video' | 'audio'

export function isImage(url: string) {
    return /\.(png|jpe?g|webp|tif?f|avif|gif|svg)(\?.*)?$/i.test(url)
}

export function isVideo(url: string) {
    return /\.(mp4|flv|mov|mkv|mpeg|mpg|wmv|m3u8)(\?.*)?$/i.test(url)
}

export function isAudio(url: string) {
    return /\.(mp3|wav|ogg|aac|flac)(\?.*)?$/i.test(url)
}

export function getPoster(url: string) {
    if (!isVideo(url)) {
        return url
    }

    return `${url}.jpg`
}
