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