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

Function downloadFileContent

apps/sim/connectors/sharepoint/sharepoint.ts:129–155  ·  view source on GitHub ↗

* Downloads the text content of a drive item.

(
  accessToken: string,
  siteId: string,
  itemId: string,
  fileName: string
)

Source from the content-addressed store, hash-verified

127 * Downloads the text content of a drive item.
128 */
129async function downloadFileContent(
130 accessToken: string,
131 siteId: string,
132 itemId: string,
133 fileName: string
134): Promise<string> {
135 const url = `${GRAPH_BASE}/sites/${siteId}/drive/items/${itemId}/content`
136
137 const response = await fetchWithRetry(url, {
138 method: 'GET',
139 headers: { Authorization: `Bearer ${accessToken}` },
140 redirect: 'follow',
141 })
142
143 if (!response.ok) {
144 throw new Error(`Failed to download file "${fileName}" (${itemId}): ${response.status}`)
145 }
146
147 // Stream with a hard byte cap so a file with missing/under-reported listing
148 // size metadata is never fully buffered into memory. Oversized files are
149 // skipped (returned empty) rather than indexed as truncated partial content.
150 const buffer = await readBodyWithLimit(response, MAX_DOWNLOAD_SIZE)
151 if (!buffer) {
152 throw new ConnectorFileTooLargeError(MAX_DOWNLOAD_SIZE)
153 }
154 return buffer.toString('utf8')
155}
156
157/**
158 * Fetches file content, applying HTML-to-text conversion for .html files.

Callers 1

fetchFileContentFunction · 0.70

Calls 3

fetchWithRetryFunction · 0.90
readBodyWithLimitFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected