fix(upload): can only upload a maximum of 100 files in certain old browsers when uploading directories, closes #6027

This commit is contained in:
07akioni 2024-07-20 22:48:01 +08:00
parent f69bcd4807
commit ae41037b54
4 changed files with 28 additions and 11 deletions

View File

@ -9,6 +9,7 @@
- Fix `n-infinite-scroll` bottoming out judgment error, closes [#6133](https://github.com/tusen-ai/naive-ui/issues/6133).
- Fix `n-slider`'s rail may have styling issue in `vertical` mode when global box-sizing is overrided, closes [#6114](https://github.com/tusen-ai/naive-ui/issues/6114).
- Fix `n-tabs` has style issue when using `prefix` slot, `suffix` slot or `addable` prop with vertical placement, closes [#6059](https://github.com/tusen-ai/naive-ui/issues/6059), [#6060](https://github.com/tusen-ai/naive-ui/pull/6060).
- Fix `n-upload` can only upload a maximum of 100 files in certain old browsers when uploading directories, closes [#6027](https://github.com/tusen-ai/naive-ui/issues/6027).
### Features

View File

@ -9,6 +9,7 @@
- 修复 `n-infinite-scroll` 组件触底判断错误,关闭 [#6133](https://github.com/tusen-ai/naive-ui/issues/6133)
- 修复 `n-slider` 在垂直模式下的宽度样式可能会被全局 CSS box-sizing override 影响,关闭[#6114](https://github.com/tusen-ai/naive-ui/issues/6114)
- 修复 `n-tabs` 在垂直模式下使用 `prefix` slot、`suffix` slot 和 `addable` 属性的时候可能出现样式问题,关闭 [#6059](https://github.com/tusen-ai/naive-ui/issues/6059)[#6060](https://github.com/tusen-ai/naive-ui/pull/6060)
- 修复 `n-upload` 在某些老浏览器下目录上传最多只能上传 100 个文件,关闭 [#6027](https://github.com/tusen-ai/naive-ui/issues/6027)
### Features

View File

@ -12,6 +12,10 @@ export function warn(location: string, message: string): void {
console.error(`[naive/${location}]: ${message}`)
}
export function error(location: string, message: string, error: unknown): void {
console.error(`[naive/${location}]: ${message}`, error)
}
export function throwError(location: string, message: string): never {
throw new Error(`[naive/${location}]: ${message}`)
}

View File

@ -1,4 +1,5 @@
import { isBrowser } from '../../_utils'
import { error } from '../../_utils/naive/warn'
import type { FileAndEntry, ShouldUseThumbnailUrl } from './interface'
import type { UploadFileInfo, UploadSettledFileInfo } from './public-types'
@ -71,23 +72,33 @@ export async function getFilesFromEntries(
continue
if (directory && isFileSystemDirectoryEntry(entry)) {
const directoryReader = entry.createReader()
let allEntries = [];
let readEntries;
do {
readEntries = yield new Promise((resolve, reject) => {
directoryReader.readEntries(resolve, reject);
});
allEntries = allEntries.concat(readEntries);
yield _getFilesFromEntries(readEntries);
} while (readEntries.length > 0);
} else if (isFileSystemFileEntry(entry)) {
let allEntries: FileSystemEntry[] = []
let readEntries: readonly FileSystemEntry[]
try {
do {
readEntries = await new Promise<readonly FileSystemEntry[]>(
(resolve, reject) => {
directoryReader.readEntries(resolve, reject)
}
)
allEntries = allEntries.concat(readEntries)
} while (readEntries.length > 0)
}
catch (e) {
error('upload', 'error happens when handling directory upload', e)
}
await _getFilesFromEntries(allEntries)
}
else if (isFileSystemFileEntry(entry)) {
try {
const file = await new Promise<File>((resolve, reject) => {
entry.file(resolve, reject)
})
fileAndEntries.push({ file, entry, source: 'dnd' })
}
catch {}
catch (e) {
error('upload', 'error happens when handling file upload', e)
}
}
}
}