Browse Source

fix: Update Google Drive Picker to show files and improve file upload process

Taylor Wilsdon (aider) 4 months ago
parent
commit
9faa5856f5
2 changed files with 18 additions and 9 deletions
  1. 15 7
      src/lib/components/chat/Chat.svelte
  2. 3 2
      src/lib/utils/google-drive-picker.ts

+ 15 - 7
src/lib/components/chat/Chat.svelte

@@ -364,16 +364,21 @@
 		try {
 			files = [...files, fileItem];
 			console.log('Processing web file with URL:', fileData.url);
+			
+			// Create headers with the Authorization token
+			const headers = {
+				'Authorization': fileData.headers.Authorization,
+				'Accept': 'application/json'
+			};
+
 			const res = await processWeb(
 				localStorage.token,
 				'',
 				fileData.url,
-				{
-					'Authorization': fileData.headers.Authorization
-				}
+				headers
 			);
 
-			if (res) {
+			if (res && res.collection_name) {
 				console.log('File processed successfully:', res);
 				fileItem.status = 'uploaded';
 				fileItem.collection_name = res.collection_name;
@@ -382,14 +387,17 @@
 					...fileItem.file
 				};
 				files = files;
+				toast.success($i18n.t('File uploaded successfully'));
 			} else {
-				console.error('No response from processWeb');
-				throw new Error('Failed to process file');
+				console.error('Invalid response from processWeb:', res);
+				throw new Error('Failed to process file: Invalid server response');
 			}
 		} catch (e) {
 			console.error('Error uploading file:', e);
 			files = files.filter((f) => f.itemId !== fileItem.itemId);
-			toast.error(e.toString());
+			toast.error($i18n.t('Error uploading file: {{error}}', {
+				error: e.message || 'Unknown error'
+			}));
 		}
 	};
 

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

@@ -102,8 +102,9 @@ export const createPicker = () => {
                 .enableFeature(google.picker.Feature.NAV_HIDDEN)
                 .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
                 .addView(new google.picker.DocsView()
-                    .setIncludeFolders(true)
-                    .setSelectFolderEnabled(true))
+                    .setIncludeFolders(false)
+                    .setSelectFolderEnabled(false)
+                    .setMimeTypes('application/pdf,text/plain,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.google-apps.document'))
                 .setOAuthToken(token)
                 .setDeveloperKey(API_KEY)
                 // Remove app ID setting as it's not needed and can cause 404 errors