From 0682a4a361311a8b13f79a168d88afdf26bb6b32 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 6 Feb 2024 00:59:26 -0800 Subject: [PATCH] feat: bulk document upload --- src/routes/(app)/documents/+page.svelte | 52 +++++++++++++------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/routes/(app)/documents/+page.svelte b/src/routes/(app)/documents/+page.svelte index 5152385ad..3b73832f4 100644 --- a/src/routes/(app)/documents/+page.svelte +++ b/src/routes/(app)/documents/+page.svelte @@ -89,20 +89,19 @@ const inputFiles = e.dataTransfer?.files; if (inputFiles && inputFiles.length > 0) { - const file = inputFiles[0]; - console.log(file, file.name.split('.').at(-1)); - if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { - reader.readAsDataURL(file); - } else if ( - SUPPORTED_FILE_TYPE.includes(file['type']) || - SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) - ) { - uploadDoc(file); - } else { - toast.error( - `Unknown File Type '${file['type']}', but accepting and treating as plain text` - ); - uploadDoc(file); + for (const file of inputFiles) { + console.log(file, file.name.split('.').at(-1)); + if ( + SUPPORTED_FILE_TYPE.includes(file['type']) || + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) + ) { + uploadDoc(file); + } else { + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); + uploadDoc(file); + } } } else { toast.error(`File not found.`); @@ -153,20 +152,23 @@ id="upload-doc-input" bind:files={inputFiles} type="file" + multiple hidden on:change={async (e) => { if (inputFiles && inputFiles.length > 0) { - const file = inputFiles[0]; - if ( - SUPPORTED_FILE_TYPE.includes(file['type']) || - SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) - ) { - uploadDoc(file); - } else { - toast.error( - `Unknown File Type '${file['type']}', but accepting and treating as plain text` - ); - uploadDoc(file); + for (const file of inputFiles) { + console.log(file, file.name.split('.').at(-1)); + if ( + SUPPORTED_FILE_TYPE.includes(file['type']) || + SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1)) + ) { + uploadDoc(file); + } else { + toast.error( + `Unknown File Type '${file['type']}', but accepting and treating as plain text` + ); + uploadDoc(file); + } } inputFiles = null;