From 0ee875bee45a8d4cb10d7e855f78788225076aec Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Thu, 18 Sep 2025 20:25:20 +0530 Subject: [PATCH] (fix:gdrive) missing appId in picker --- frontend/src/components/GoogleDrivePicker.tsx | 215 ++++++++++-------- frontend/src/upload/types/ingestor.ts | 3 +- 2 files changed, 121 insertions(+), 97 deletions(-) diff --git a/frontend/src/components/GoogleDrivePicker.tsx b/frontend/src/components/GoogleDrivePicker.tsx index 9bda9798..c47794a0 100644 --- a/frontend/src/components/GoogleDrivePicker.tsx +++ b/frontend/src/components/GoogleDrivePicker.tsx @@ -59,7 +59,7 @@ const GoogleDrivePicker: React.FC = ({ if (!validateResponse.ok) { setIsConnected(false); setAuthError('Session expired. Please reconnect to Google Drive.'); - return; + return false; } const validateData = await validateResponse.json(); @@ -68,14 +68,17 @@ const GoogleDrivePicker: React.FC = ({ setIsConnected(true); setAuthError(''); setAccessToken(validateData.access_token || null); + return true; } else { setIsConnected(false); setAuthError(validateData.error || 'Session expired. Please reconnect your account.'); + return false; } } catch (error) { console.error('Error validating session:', error); setAuthError('Failed to validate session. Please reconnect.'); setIsConnected(false); + return false; } }; @@ -97,24 +100,40 @@ const GoogleDrivePicker: React.FC = ({ } try { + const clientId = import.meta.env.VITE_GOOGLE_CLIENT_ID; + const developerKey = import.meta.env.VITE_GOOGLE_API_KEY; + const appId = import.meta.env.VITE_GOOGLE_DRIVE_APP_ID; + + if (!clientId || !developerKey || !appId) { + console.error('Missing Google Drive configuration:', { + clientId: !!clientId, + developerKey: !!developerKey, + appId: !!appId + }); + setAuthError('Google Drive configuration is incomplete. Please check your environment variables.'); + setIsLoading(false); + return; + } + openPicker({ - clientId: import.meta.env.VITE_GOOGLE_CLIENT_ID, - developerKey: import.meta.env.VITE_GOOGLE_API_KEY, - viewId: "DOCS_IMAGES_AND_VIDEOS", + clientId: clientId, + developerKey: developerKey, + appId: appId, + viewId: "DOCS", showUploadView: false, showUploadFolders: false, - supportDrives: true, + supportDrives: false, multiselect: true, token: accessToken, - viewMimeTypes: 'application/vnd.google-apps.folder,application/vnd.google-apps.document,application/pdf', + viewMimeTypes: 'application/vnd.google-apps.folder,application/vnd.google-apps.document,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.ms-powerpoint,application/vnd.ms-excel,text/plain,text/csv,text/html,application/rtf,image/jpeg,image/jpg,image/png', callbackFunction: (data:any) => { setIsLoading(false); if (data.action === 'picked') { const docs = data.docs; - - const files: PickerFile[] = []; - const folders: PickerFile[] = []; - + + const newFiles: PickerFile[] = []; + const newFolders: PickerFile[] = []; + docs.forEach((doc: any) => { const item = { id: doc.id, @@ -124,24 +143,29 @@ const GoogleDrivePicker: React.FC = ({ description: doc.description, sizeBytes: doc.sizeBytes }; - + if (doc.mimeType === 'application/vnd.google-apps.folder') { - folders.push(item); + newFolders.push(item); } else { - files.push(item); + newFiles.push(item); } }); - - setSelectedFiles(files); - setSelectedFolders(folders); - - const fileIds = files.map(file => file.id); - const folderIds = folders.map(folder => folder.id); - - console.log('Selected file IDs:', fileIds); - console.log('Selected folder IDs:', folderIds); - - onSelectionChange(fileIds, folderIds); + + setSelectedFiles(prevFiles => { + const existingFileIds = new Set(prevFiles.map(file => file.id)); + const uniqueNewFiles = newFiles.filter(file => !existingFileIds.has(file.id)); + return [...prevFiles, ...uniqueNewFiles]; + }); + + setSelectedFolders(prevFolders => { + const existingFolderIds = new Set(prevFolders.map(folder => folder.id)); + const uniqueNewFolders = newFolders.filter(folder => !existingFolderIds.has(folder.id)); + return [...prevFolders, ...uniqueNewFolders]; + }); + onSelectionChange( + [...selectedFiles, ...newFiles].map(file => file.id), + [...selectedFolders, ...newFolders].map(folder => folder.id) + ); } }, }); @@ -179,7 +203,7 @@ const GoogleDrivePicker: React.FC = ({ if (!isConnected) { return ( -
+
{authError && (
{authError}
)} @@ -192,6 +216,7 @@ const GoogleDrivePicker: React.FC = ({ if (data.session_token) { setSessionToken('google_drive', data.session_token); + validateSession(data.session_token); } }} onError={(error) => { @@ -204,8 +229,8 @@ const GoogleDrivePicker: React.FC = ({ } return ( -
-
+
+
@@ -222,75 +247,75 @@ const GoogleDrivePicker: React.FC = ({
-
-
-

Selected Files

- -
- - {selectedFiles.length === 0 && selectedFolders.length === 0 ? ( -

No files or folders selected

- ) : ( -
- {/* Display folders */} - {selectedFolders.length > 0 && ( -
-

Folders

- {selectedFolders.map((folder) => ( -
- Folder - {folder.name} - -
- ))} -
- )} - - {/* Display files */} - {selectedFiles.length > 0 && ( -
-

Files

- {selectedFiles.map((file) => ( -
- File - {file.name} - -
- ))} -
- )} +
+
+
+

Selected Files

+
- )} + + {selectedFiles.length === 0 && selectedFolders.length === 0 ? ( +

No files or folders selected

+ ) : ( +
+ {selectedFolders.length > 0 && ( +
+

Folders

+ {selectedFolders.map((folder) => ( +
+ Folder + {folder.name} + +
+ ))} +
+ )} + + {selectedFiles.length > 0 && ( +
+

Files

+ {selectedFiles.map((file) => ( +
+ File + {file.name} + +
+ ))} +
+ )} +
+ )} +
); diff --git a/frontend/src/upload/types/ingestor.ts b/frontend/src/upload/types/ingestor.ts index 08686796..f35b300a 100644 --- a/frontend/src/upload/types/ingestor.ts +++ b/frontend/src/upload/types/ingestor.ts @@ -41,8 +41,7 @@ export const IngestorFormSchemas: Record = { label: 'Select Files from Google Drive', type: 'google_drive_picker', required: true, - }, - { name: 'recursive', label: 'Include subfolders', type: 'boolean', required: false }, + } ], local_file: [ { name: 'files', label: 'Select files', type: 'local_file_picker', required: true },