mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-12-01 09:33:14 +00:00
multiple-file missing task ingest
restore upload to pack all file together instead one by one
This commit is contained in:
@@ -243,59 +243,26 @@ function Upload({
|
||||
const doNothing = () => undefined;
|
||||
|
||||
const uploadFile = () => {
|
||||
if (files.length === 0) {
|
||||
console.error('No files to upload.');
|
||||
return;
|
||||
}
|
||||
|
||||
const apiHost = import.meta.env.VITE_API_HOST;
|
||||
|
||||
const uploadNextFile = (index: number) => {
|
||||
if (index >= files.length) {
|
||||
console.log('All files have been uploaded.');
|
||||
return;
|
||||
}
|
||||
|
||||
const file = files[index];
|
||||
const formData = new FormData();
|
||||
const formData = new FormData();
|
||||
files.forEach((file) => {
|
||||
formData.append('file', file);
|
||||
formData.append('name', docName);
|
||||
formData.append('user', 'local');
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.upload.addEventListener('progress', (event) => {
|
||||
const progress = +((event.loaded / event.total) * 100).toFixed(2);
|
||||
console.log(`File ${index + 1}/${files.length} progress: ${progress}%`);
|
||||
setProgress({ type: 'UPLOAD', percentage: progress });
|
||||
});
|
||||
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
const { task_id } = JSON.parse(xhr.responseText);
|
||||
console.log(`
|
||||
File ${index + 1}/${files.length} uploaded successfully. Task ID: ${task_id}`);
|
||||
setTimeoutRef.current = setTimeout(() => {
|
||||
setProgress({ type: 'TRAINING', percentage: 0, taskId: task_id });
|
||||
}, 3000);
|
||||
uploadNextFile(index + 1);
|
||||
} else {
|
||||
console.error(
|
||||
`
|
||||
File ${index + 1}/${files.length} upload failed with status ${xhr.status}. Response:`,
|
||||
xhr.responseText,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = () => {
|
||||
console.error(`
|
||||
File ${index + 1}/${files.length} upload encountered an error.`);
|
||||
};
|
||||
|
||||
xhr.open('POST', `${apiHost + '/api/upload'}`);
|
||||
xhr.send(formData);
|
||||
});
|
||||
formData.append('name', docName);
|
||||
formData.append('user', 'local');
|
||||
const apiHost = import.meta.env.VITE_API_HOST;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.upload.addEventListener('progress', (event) => {
|
||||
const progress = +((event.loaded / event.total) * 100).toFixed(2);
|
||||
setProgress({ type: 'UPLOAD', percentage: progress });
|
||||
});
|
||||
xhr.onload = () => {
|
||||
const { task_id } = JSON.parse(xhr.responseText);
|
||||
setTimeoutRef.current = setTimeout(() => {
|
||||
setProgress({ type: 'TRAINING', percentage: 0, taskId: task_id });
|
||||
}, 3000);
|
||||
};
|
||||
uploadNextFile(0);
|
||||
xhr.open('POST', `${apiHost + '/api/upload'}`);
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
const uploadRemote = () => {
|
||||
|
||||
Reference in New Issue
Block a user