Merge pull request #660 from ollama-webui/bulk-upload

feat: bulk document upload
This commit is contained in:
Timothy Jaeryang Baek 2024-02-06 00:59:51 -08:00 committed by GitHub
commit 46d0eff218
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,11 +89,9 @@
const inputFiles = e.dataTransfer?.files; const inputFiles = e.dataTransfer?.files;
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
const file = inputFiles[0]; for (const file of inputFiles) {
console.log(file, file.name.split('.').at(-1)); console.log(file, file.name.split('.').at(-1));
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { if (
reader.readAsDataURL(file);
} else if (
SUPPORTED_FILE_TYPE.includes(file['type']) || SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
) { ) {
@ -104,6 +102,7 @@
); );
uploadDoc(file); uploadDoc(file);
} }
}
} else { } else {
toast.error(`File not found.`); toast.error(`File not found.`);
} }
@ -153,10 +152,12 @@
id="upload-doc-input" id="upload-doc-input"
bind:files={inputFiles} bind:files={inputFiles}
type="file" type="file"
multiple
hidden hidden
on:change={async (e) => { on:change={async (e) => {
if (inputFiles && inputFiles.length > 0) { if (inputFiles && inputFiles.length > 0) {
const file = inputFiles[0]; for (const file of inputFiles) {
console.log(file, file.name.split('.').at(-1));
if ( if (
SUPPORTED_FILE_TYPE.includes(file['type']) || SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
@ -168,6 +169,7 @@
); );
uploadDoc(file); uploadDoc(file);
} }
}
inputFiles = null; inputFiles = null;
e.target.value = ''; e.target.value = '';