* Downloads the raw content of a OneDrive file.
(accessToken: string, fileId: string)
| 70 | * Downloads the raw content of a OneDrive file. |
| 71 | */ |
| 72 | async function downloadFileContent(accessToken: string, fileId: string): Promise<string> { |
| 73 | const url = `${GRAPH_BASE_URL}/me/drive/items/${fileId}/content` |
| 74 | |
| 75 | const response = await fetchWithRetry(url, { |
| 76 | method: 'GET', |
| 77 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 78 | redirect: 'follow', |
| 79 | }) |
| 80 | |
| 81 | if (!response.ok) { |
| 82 | throw new Error(`Failed to download file ${fileId}: ${response.status}`) |
| 83 | } |
| 84 | |
| 85 | const buffer = await readBodyWithLimit(response, MAX_FILE_SIZE) |
| 86 | if (!buffer) { |
| 87 | throw new ConnectorFileTooLargeError(MAX_FILE_SIZE) |
| 88 | } |
| 89 | return buffer.toString('utf8') |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Fetches file content, converting HTML to plain text when applicable. |
no test coverage detected