forked from BRETT/BRETT
Initial Commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// Windows/Browser liefern für manche Formate (z. B. .flac, .mp3) keinen
|
||||
// MIME-Type — beim Drag&Drop kommt dann '' oder 'application/octet-stream'.
|
||||
// Daher wird der Dateityp über MIME *oder* Endung geprüft.
|
||||
|
||||
export const MEDIA_FILE_EXT = /\.(avif|bmp|gif|jpe?g|png|svg|webp|m4v|mov|mp4|ogg|ogv|webm|flac|mp3)$/i
|
||||
|
||||
// Für den dataTypes-Check während dragover: dort sind nur die Item-Typen
|
||||
// bekannt, keine Dateinamen — unbekannte Typen durchlassen und beim
|
||||
// eigentlichen Drop per isMediaFile filtern
|
||||
export function isMediaItemType(type: string): boolean {
|
||||
return type === '' || type === 'application/octet-stream'
|
||||
|| type.startsWith('image/') || type.startsWith('video/') || type.startsWith('audio/')
|
||||
}
|
||||
|
||||
export function isMediaFile(file: File): boolean {
|
||||
const t = file.type
|
||||
if (t.startsWith('image/') || t.startsWith('video/') || t.startsWith('audio/')) return true
|
||||
return (!t || t === 'application/octet-stream') && MEDIA_FILE_EXT.test(file.name)
|
||||
}
|
||||
Reference in New Issue
Block a user