From b57f7251a5ed2bed2e0afe6816be300b65fc20c2 Mon Sep 17 00:00:00 2001 From: "Taylor Wilsdon (aider)" Date: Sun, 15 Dec 2024 19:06:38 -0500 Subject: [PATCH] feat: Improve Google Drive file upload handling with better logging and error management --- src/lib/components/chat/Chat.svelte | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 431fd30b6..2cd60c8b9 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -350,33 +350,46 @@ // File upload functions const uploadGoogleDriveFile = async (fileData) => { + console.log('Uploading Google Drive file:', fileData); const fileItem = { type: 'doc', name: fileData.name, collection_name: '', status: 'uploading', url: fileData.url, - headers: fileData.headers, - error: '' + error: '', + itemId: uuidv4() }; try { files = [...files, fileItem]; - const res = await processWeb(localStorage.token, '', fileData.url, fileData.headers); + console.log('Processing web file with URL:', fileData.url); + const res = await processWeb( + localStorage.token, + '', + fileData.url, + { + 'Authorization': fileData.headers.Authorization + } + ); if (res) { + console.log('File processed successfully:', res); fileItem.status = 'uploaded'; fileItem.collection_name = res.collection_name; fileItem.file = { ...res.file, ...fileItem.file }; - files = files; + } else { + console.error('No response from processWeb'); + throw new Error('Failed to process file'); } } catch (e) { - files = files.filter((f) => f.name !== fileData.name); - toast.error(JSON.stringify(e)); + console.error('Error uploading file:', e); + files = files.filter((f) => f.itemId !== fileItem.itemId); + toast.error(e.toString()); } };