MCPcopy Index your code
hub / github.com/simstudioai/sim / downloadTextFile

Function downloadTextFile

apps/sim/connectors/google-drive/google-drive.ts:84–104  ·  view source on GitHub ↗
(accessToken: string, fileId: string)

Source from the content-addressed store, hash-verified

82}
83
84async function downloadTextFile(accessToken: string, fileId: string): Promise<string> {
85 const url = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`
86
87 const response = await fetchWithRetry(url, {
88 method: 'GET',
89 headers: { Authorization: `Bearer ${accessToken}` },
90 })
91
92 if (!response.ok) {
93 throw new Error(`Failed to download file ${fileId}: ${response.status}`)
94 }
95
96 // Stream with a hard byte cap so a file with missing/under-reported listing
97 // size metadata is never fully buffered into memory. Oversized files raise
98 // DriveFileTooLargeError so getDocument can surface them as skipped (failed) rows.
99 const buffer = await readBodyWithLimit(response, CONNECTOR_MAX_FILE_BYTES)
100 if (!buffer) {
101 throw new ConnectorFileTooLargeError(CONNECTOR_MAX_FILE_BYTES)
102 }
103 return buffer.toString('utf8')
104}
105
106async function fetchFileContent(
107 accessToken: string,

Callers 1

fetchFileContentFunction · 0.85

Calls 3

fetchWithRetryFunction · 0.90
readBodyWithLimitFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected