11import { createLogger } from '@sim/logger'
22import { GoogleDriveIcon } from '@/components/icons'
3+ import { fetchWithRetry , VALIDATE_RETRY_OPTIONS } from '@/lib/knowledge/documents/utils'
34import type { ConnectorConfig , ExternalDocument , ExternalDocumentList } from '@/connectors/types'
45
56const logger = createLogger ( 'GoogleDriveConnector' )
@@ -61,7 +62,7 @@ async function exportGoogleWorkspaceFile(
6162
6263 const url = `https://www.googleapis.com/drive/v3/files/${ fileId } /export?mimeType=${ encodeURIComponent ( exportMimeType ) } `
6364
64- const response = await fetch ( url , {
65+ const response = await fetchWithRetry ( url , {
6566 method : 'GET' ,
6667 headers : { Authorization : `Bearer ${ accessToken } ` } ,
6768 } )
@@ -76,7 +77,7 @@ async function exportGoogleWorkspaceFile(
7677async function downloadTextFile ( accessToken : string , fileId : string ) : Promise < string > {
7778 const url = `https://www.googleapis.com/drive/v3/files/${ fileId } ?alt=media`
7879
79- const response = await fetch ( url , {
80+ const response = await fetchWithRetry ( url , {
8081 method : 'GET' ,
8182 headers : { Authorization : `Bearer ${ accessToken } ` } ,
8283 } )
@@ -266,7 +267,7 @@ export const googleDriveConnector: ConnectorConfig = {
266267
267268 logger . info ( 'Listing Google Drive files' , { query, cursor : cursor ?? 'initial' } )
268269
269- const response = await fetch ( url , {
270+ const response = await fetchWithRetry ( url , {
270271 method : 'GET' ,
271272 headers : {
272273 Authorization : `Bearer ${ accessToken } ` ,
@@ -310,7 +311,7 @@ export const googleDriveConnector: ConnectorConfig = {
310311 'id,name,mimeType,modifiedTime,createdTime,webViewLink,parents,owners,size,starred,trashed'
311312 const url = `https://www.googleapis.com/drive/v3/files/${ externalId } ?fields=${ encodeURIComponent ( fields ) } &supportsAllDrives=true`
312313
313- const response = await fetch ( url , {
314+ const response = await fetchWithRetry ( url , {
314315 method : 'GET' ,
315316 headers : {
316317 Authorization : `Bearer ${ accessToken } ` ,
@@ -346,13 +347,17 @@ export const googleDriveConnector: ConnectorConfig = {
346347 if ( folderId ?. trim ( ) ) {
347348 // Verify the folder exists and is accessible
348349 const url = `https://www.googleapis.com/drive/v3/files/${ folderId . trim ( ) } ?fields=id,name,mimeType&supportsAllDrives=true`
349- const response = await fetch ( url , {
350- method : 'GET' ,
351- headers : {
352- Authorization : `Bearer ${ accessToken } ` ,
353- Accept : 'application/json' ,
350+ const response = await fetchWithRetry (
351+ url ,
352+ {
353+ method : 'GET' ,
354+ headers : {
355+ Authorization : `Bearer ${ accessToken } ` ,
356+ Accept : 'application/json' ,
357+ } ,
354358 } ,
355- } )
359+ VALIDATE_RETRY_OPTIONS
360+ )
356361
357362 if ( ! response . ok ) {
358363 if ( response . status === 404 ) {
@@ -368,13 +373,17 @@ export const googleDriveConnector: ConnectorConfig = {
368373 } else {
369374 // Verify basic Drive access by listing one file
370375 const url = 'https://www.googleapis.com/drive/v3/files?pageSize=1&fields=files(id)'
371- const response = await fetch ( url , {
372- method : 'GET' ,
373- headers : {
374- Authorization : `Bearer ${ accessToken } ` ,
375- Accept : 'application/json' ,
376+ const response = await fetchWithRetry (
377+ url ,
378+ {
379+ method : 'GET' ,
380+ headers : {
381+ Authorization : `Bearer ${ accessToken } ` ,
382+ Accept : 'application/json' ,
383+ } ,
376384 } ,
377- } )
385+ VALIDATE_RETRY_OPTIONS
386+ )
378387
379388 if ( ! response . ok ) {
380389 return { valid : false , error : `Failed to access Google Drive: ${ response . status } ` }
0 commit comments