MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / fetchFile

Function fetchFile

native.ts:527–551  ·  view source on GitHub ↗
(
    _: IpcMainInvokeEvent,
    url: string,
    timeoutMs: number = 300000
)

Source from the content-addressed store, hash-verified

525}
526
527export async function fetchFile(
528 _: IpcMainInvokeEvent,
529 url: string,
530 timeoutMs: number = 300000
531): Promise<{ success: boolean; data?: ArrayBuffer; contentType?: string; error?: string; }> {
532 if (!isValidHttpsUrl(url)) {
533 return { success: false, error: "Refusing to fetch a non-HTTPS URL" };
534 }
535
536 const controller = new AbortController();
537 const timeout = setTimeout(() => controller.abort(), timeoutMs);
538 try {
539 const response = await fetch(url, { signal: controller.signal });
540 if (!response.ok) {
541 return { success: false, error: `Fetch failed: ${response.status} ${response.statusText}` };
542 }
543 const data = await response.arrayBuffer();
544 const contentType = response.headers.get("content-type") || "";
545 return { success: true, data, contentType };
546 } catch (e) {
547 return { success: false, error: e instanceof Error ? e.message : "Unknown error" };
548 } finally {
549 clearTimeout(timeout);
550 }
551}

Callers

nothing calls this directly

Calls 1

isValidHttpsUrlFunction · 0.85

Tested by

no test coverage detected