Upload file in the order of sorted file name
This commit is contained in:
@@ -77,8 +77,17 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
||||
// Track errors locally to ensure we have the final state
|
||||
const uploadErrors: Record<string, string> = {}
|
||||
|
||||
await Promise.all(
|
||||
filesToUpload.map(async (file) => {
|
||||
// Create a collator that supports Chinese sorting
|
||||
const collator = new Intl.Collator(['zh-CN', 'en'], {
|
||||
sensitivity: 'accent', // consider basic characters, accents, and case
|
||||
numeric: true // enable numeric sorting, e.g., "File 10" will be after "File 2"
|
||||
});
|
||||
const sortedFiles = [...filesToUpload].sort((a, b) =>
|
||||
collator.compare(a.name, b.name)
|
||||
);
|
||||
|
||||
// Upload files in sequence, not parallel
|
||||
for (const file of sortedFiles) {
|
||||
try {
|
||||
// Initialize upload progress
|
||||
setProgresses((pre) => ({
|
||||
@@ -138,8 +147,7 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
||||
[file.name]: errorMsg
|
||||
}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// Check if any files failed to upload using our local tracking
|
||||
const hasErrors = Object.keys(uploadErrors).length > 0
|
||||
|
Reference in New Issue
Block a user