mirror of
https://github.com/open-webui/open-webui
synced 2025-04-25 00:39:36 +00:00
Merge pull request #4225 from Yanyutin753/pref_file_upload
⚡Initialize fileItem first to speed up file display
This commit is contained in:
commit
039c5c540b
@ -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 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,
|
||||||
|
collection_name: '',
|
||||||
|
status: '',
|
||||||
|
size: file.size,
|
||||||
|
error: ''
|
||||||
|
};
|
||||||
|
files = [...files, fileItem];
|
||||||
|
|
||||||
if (uploadedFile) {
|
try {
|
||||||
const fileItem = {
|
const uploadedFile = await uploadFile(localStorage.token, file);
|
||||||
type: 'file',
|
|
||||||
file: uploadedFile,
|
|
||||||
id: uploadedFile.id,
|
|
||||||
url: `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`,
|
|
||||||
name: file.name,
|
|
||||||
collection_name: '',
|
|
||||||
status: 'uploaded',
|
|
||||||
error: ''
|
|
||||||
};
|
|
||||||
files = [...files, fileItem];
|
|
||||||
|
|
||||||
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
|
if (uploadedFile) {
|
||||||
// Default Upload to VectorDB
|
fileItem.status = 'uploaded';
|
||||||
if (
|
fileItem.file = uploadedFile;
|
||||||
SUPPORTED_FILE_TYPE.includes(file['type']) ||
|
fileItem.id = uploadedFile.id;
|
||||||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
|
fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
|
||||||
) {
|
|
||||||
processFileItem(fileItem);
|
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
|
||||||
|
// Default Upload to VectorDB
|
||||||
|
if (
|
||||||
|
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 @@
|
|||||||
// 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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user