Browse Source

feat: Improve Google Drive file download handling

Taylor Wilsdon (aider) 4 months ago
parent
commit
64c8bbc16a

+ 3 - 1
src/lib/components/chat/MessageInput.svelte

@@ -501,12 +501,14 @@
 											try {
 												const fileData = await createPicker();
 												if (fileData) {
+													// Pass the OAuth token along with the file data
 													dispatch('upload', { 
 														type: 'google-drive', 
 														data: {
 															name: fileData.name,
 															url: fileData.url,
-															id: fileData.id
+															id: fileData.id,
+															token: await getAuthToken() // Include OAuth token for download
 														}
 													});
 												}

+ 3 - 1
src/lib/utils/google-drive-picker.ts

@@ -111,10 +111,12 @@ export const createPicker = () => {
                         const fileName = doc[google.picker.Document.NAME];
                         const fileUrl = doc[google.picker.Document.URL];
                         
+                        // Get the downloadUrl using the alt=media parameter
+                        const downloadUrl = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
                         resolve({
                             id: fileId,
                             name: fileName,
-                            url: fileUrl
+                            url: downloadUrl
                         });
                     } else if (data[google.picker.Response.ACTION] === google.picker.Action.CANCEL) {
                         resolve(null);