MCPcopy Create free account
hub / github.com/epicweb-dev/epic-stack / downloadFile

Function downloadFile

app/utils/misc.tsx:276–290  ·  view source on GitHub ↗
(url: string, retries: number = 0)

Source from the content-addressed store, hash-verified

274}
275
276export async function downloadFile(url: string, retries: number = 0) {
277 const MAX_RETRIES = 3
278 try {
279 const response = await fetch(url)
280 if (!response.ok) {
281 throw new Error(`Failed to fetch image with status ${response.status}`)
282 }
283 const contentType = response.headers.get('content-type') ?? 'image/jpg'
284 const blob = Buffer.from(await response.arrayBuffer())
285 return { contentType, blob }
286 } catch (e) {
287 if (retries > MAX_RETRIES) throw e
288 return downloadFile(url, retries + 1)
289 }
290}

Callers 1

signupWithConnectionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected