Unverified Commit 039c5c54 authored by Timothy Jaeryang Baek's avatar Timothy Jaeryang Baek Committed by GitHub
Browse files

Merge pull request #4225 from Yanyutin753/pref_file_upload

Initialize fileItem first to speed up file display
parents ef36b216 c9ed934d
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
const uploadFileHandler = async (file) => { const uploadFileHandler = async (file) => {
console.log(file); console.log(file);
// Check if the file is an audio file and transcribe/convert it to text file // Check if the file is an audio file and transcribe/convert it to text file
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) { if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
const res = await transcribeAudio(localStorage.token, file).catch((error) => { const res = await transcribeAudio(localStorage.token, file).catch((error) => {
...@@ -112,40 +113,49 @@ ...@@ -112,40 +113,49 @@
} }
} }
// Upload the file to the server const fileItem = {
const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => { type: 'file',
toast.error(error); file: '',
return null; id: null,
}); url: '',
name: file.name,
if (uploadedFile) { collection_name: '',
const fileItem = { status: '',
type: 'file', size: file.size,
file: uploadedFile, error: ''
id: uploadedFile.id, };
url: `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`, files = [...files, fileItem];
name: file.name,
collection_name: '', try {
status: 'uploaded', const uploadedFile = await uploadFile(localStorage.token, file);
error: ''
}; if (uploadedFile) {
files = [...files, fileItem]; fileItem.status = 'uploaded';
fileItem.file = uploadedFile;
// TODO: Check if tools & functions have files support to skip this step to delegate file processing fileItem.id = uploadedFile.id;
// Default Upload to VectorDB fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
if (
SUPPORTED_FILE_TYPE.includes(file['type']) || // TODO: Check if tools & functions have files support to skip this step to delegate file processing
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) // Default Upload to VectorDB
) { if (
processFileItem(fileItem); SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
) {
processFileItem(fileItem);
} else {
toast.error(
$i18n.t(`Unknown file type '{{file_type}}'. Proceeding with the file upload anyway.`, {
file_type: file['type']
})
);
processFileItem(fileItem);
}
} else { } else {
toast.error( files = files.filter((item) => item.status !== null);
$i18n.t(`Unknown file type '{{file_type}}'. Proceeding with the file upload anyway.`, {
file_type: file['type']
})
);
processFileItem(fileItem);
} }
} catch (e) {
toast.error(e);
files = files.filter((item) => item.status !== null);
} }
}; };
...@@ -162,7 +172,6 @@ ...@@ -162,7 +172,6 @@
// Remove the failed doc from the files array // Remove the failed doc from the files array
// files = files.filter((f) => f.id !== fileItem.id); // files = files.filter((f) => f.id !== fileItem.id);
toast.error(e); toast.error(e);
fileItem.status = 'processed'; fileItem.status = 'processed';
files = files; files = files;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment