refac/fix: kb image upload handling

This commit is contained in:
Timothy Jaeryang Baek 2025-10-28 00:34:53 -07:00
parent e986488ab5
commit f524a6a8e7
3 changed files with 16 additions and 7 deletions

View file

@ -115,6 +115,10 @@ def process_uploaded_file(request, file, file_path, file_item, file_metadata, us
request.app.state.config.CONTENT_EXTRACTION_ENGINE == "external" request.app.state.config.CONTENT_EXTRACTION_ENGINE == "external"
): ):
process_file(request, ProcessFileForm(file_id=file_item.id), user=user) process_file(request, ProcessFileForm(file_id=file_item.id), user=user)
else:
raise Exception(
f"File type {file.content_type} is not supported for processing"
)
else: else:
log.info( log.info(
f"File type {file.content_type} is not provided, but trying to process anyway" f"File type {file.content_type} is not provided, but trying to process anyway"

View file

@ -63,6 +63,10 @@ export const uploadFile = async (token: string, file: File, metadata?: object |
console.error(data.error); console.error(data.error);
res.error = data.error; res.error = data.error;
} }
if (res?.data) {
res.data = data;
}
} }
} }
} }

View file

@ -184,12 +184,6 @@
if (uploadedFile) { if (uploadedFile) {
console.log(uploadedFile); console.log(uploadedFile);
if (uploadedFile.error) {
console.warn('File upload warning:', uploadedFile.error);
toast.warning(uploadedFile.error);
}
knowledge.files = knowledge.files.map((item) => { knowledge.files = knowledge.files.map((item) => {
if (item.itemId === tempItemId) { if (item.itemId === tempItemId) {
item.id = uploadedFile.id; item.id = uploadedFile.id;
@ -199,7 +193,14 @@
delete item.itemId; delete item.itemId;
return item; return item;
}); });
if (uploadedFile.error) {
console.warn('File upload warning:', uploadedFile.error);
toast.warning(uploadedFile.error);
knowledge.files = knowledge.files.filter((file) => file.id !== uploadedFile.id);
} else {
await addFileHandler(uploadedFile.id); await addFileHandler(uploadedFile.id);
}
} else { } else {
toast.error($i18n.t('Failed to upload file.')); toast.error($i18n.t('Failed to upload file.'));
} }