文件格式检查

This commit is contained in:
2023-10-13 01:40:31 +08:00
parent 1a7e373aa1
commit 7694e79809
1 changed files with 7 additions and 0 deletions

View File

@ -119,6 +119,13 @@ export function UploadMusic(options) {
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
const files = Array.from(event.dataTransfer.files) const files = Array.from(event.dataTransfer.files)
// 检查必须是音乐文件, 移除其它文件
for (let i = 0; i < files.length; i++) {
if (!files[i].type.startsWith('audio/')) {
files.splice(i, 1)
i--
}
}
if (files.length === 0) return console.log('没有文件') if (files.length === 0) return console.log('没有文件')
console.log('files', files) console.log('files', files)
options.onchange(files) options.onchange(files)