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
|
// Track errors locally to ensure we have the final state
|
||||||
const uploadErrors: Record<string, string> = {}
|
const uploadErrors: Record<string, string> = {}
|
||||||
|
|
||||||
await Promise.all(
|
// Create a collator that supports Chinese sorting
|
||||||
filesToUpload.map(async (file) => {
|
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 {
|
try {
|
||||||
// Initialize upload progress
|
// Initialize upload progress
|
||||||
setProgresses((pre) => ({
|
setProgresses((pre) => ({
|
||||||
@@ -138,8 +147,7 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
|||||||
[file.name]: errorMsg
|
[file.name]: errorMsg
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// Check if any files failed to upload using our local tracking
|
// Check if any files failed to upload using our local tracking
|
||||||
const hasErrors = Object.keys(uploadErrors).length > 0
|
const hasErrors = Object.keys(uploadErrors).length > 0
|
||||||
|
Reference in New Issue
Block a user