export enum MetaType { image = 'image', video = 'video', other = 'other' } export const metaTypeExtnames = { [MetaType.image]: ['bmp', 'jpg', 'png', 'tif', 'gif', 'pcx', 'tga', 'exif', 'fpx', 'svg', 'psd', 'cdr', 'pcd', 'dxf', 'ufo', 'eps', 'ai', 'raw', 'WMF', 'webp', 'avif', 'apng'], [MetaType.video]: ['wmv', 'asf', 'asx', 'rm', 'rmvb', 'mp4', '3gp', 'mov', 'm4v', 'avi', 'dat', 'mkv', 'flv', 'vob'] } export const getExtname = (url: string) => { const index = url.lastIndexOf('.') if (~index) { return url.substring(index + 1) } else { return null } } export const getUrlType = (url: string) => { const extname = getExtname(url)?.toLowerCase() if (extname) { for (const [type, extnames] of Object.entries(metaTypeExtnames)) { if (extnames.includes(extname)) { return type as MetaType } } } else { return MetaType.other } }