(accessToken: string, fileId: string)
| 82 | } |
| 83 | |
| 84 | async 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 | |
| 106 | async function fetchFileContent( |
| 107 | accessToken: string, |
no test coverage detected