mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: documents file handling
This commit is contained in:
@@ -57,12 +57,12 @@
|
||||
{#if document.source?.name}
|
||||
<div class="text-sm dark:text-gray-400">
|
||||
<a
|
||||
href={document?.source?.url
|
||||
? `${document?.source?.url}/content`
|
||||
href={document?.metadata?.file_id
|
||||
? `/api/v1/files/${document?.metadata?.file_id}/content`
|
||||
: document.source.name}
|
||||
target="_blank"
|
||||
>
|
||||
{document.source.name}
|
||||
{document?.metadata?.name ?? document.source.name}
|
||||
</a>
|
||||
</div>
|
||||
{:else}
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
import { createNewDoc, deleteDocByName, getDocs } from '$lib/apis/documents';
|
||||
|
||||
import { SUPPORTED_FILE_TYPE, SUPPORTED_FILE_EXTENSIONS } from '$lib/constants';
|
||||
import { uploadDocToVectorDB } from '$lib/apis/rag';
|
||||
import { transformFileName } from '$lib/utils';
|
||||
import { processDocToVectorDB, uploadDocToVectorDB } from '$lib/apis/rag';
|
||||
import { blobToFile, transformFileName } from '$lib/utils';
|
||||
|
||||
import Checkbox from '$lib/components/common/Checkbox.svelte';
|
||||
|
||||
import EditDocModal from '$lib/components/documents/EditDocModal.svelte';
|
||||
import AddFilesPlaceholder from '$lib/components/AddFilesPlaceholder.svelte';
|
||||
import AddDocModal from '$lib/components/documents/AddDocModal.svelte';
|
||||
import { transcribeAudio } from '$lib/apis/audio';
|
||||
import { uploadFile } from '$lib/apis/files';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
@@ -50,7 +52,28 @@
|
||||
};
|
||||
|
||||
const uploadDoc = async (file) => {
|
||||
const res = await uploadDocToVectorDB(localStorage.token, '', file).catch((error) => {
|
||||
console.log(file);
|
||||
// Check if the file is an audio file and transcribe/convert it to text file
|
||||
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
|
||||
const transcribeRes = await transcribeAudio(localStorage.token, file).catch((error) => {
|
||||
toast.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (transcribeRes) {
|
||||
console.log(transcribeRes);
|
||||
const blob = new Blob([transcribeRes.text], { type: 'text/plain' });
|
||||
file = blobToFile(blob, `${file.name}.txt`);
|
||||
}
|
||||
}
|
||||
|
||||
// Upload the file to the server
|
||||
const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => {
|
||||
toast.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
const res = await processDocToVectorDB(localStorage.token, uploadedFile.id).catch((error) => {
|
||||
toast.error(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user