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

Function fetchWithTimeout

utils/upload.ts:152–175  ·  view source on GitHub ↗
(url: string, options: RequestInit)

Source from the content-addressed store, hash-verified

150}
151
152async function fetchWithTimeout(url: string, options: RequestInit): Promise<Response> {
153 const controller = new AbortController();
154 activeAbortController = controller;
155 const timeout = setTimeout(() => controller.abort(), getUploadTimeoutMs());
156 const requestUrl = toProxyUrl(url);
157
158 try {
159 return await fetch(requestUrl, {
160 ...options,
161 signal: controller.signal
162 });
163 } catch (error) {
164 if (cancelRequested || controller.signal.aborted) {
165 throw new Error(cancelRequested ? "Upload cancelled by user" : "Upload timed out");
166 }
167
168 throw error;
169 } finally {
170 clearTimeout(timeout);
171 if (activeAbortController === controller) {
172 activeAbortController = null;
173 }
174 }
175}
176
177function getHeaderEntries(headers?: HeadersInit): [string, string][] {
178 if (!headers) return [];

Callers 1

uploadFileFunction · 0.85

Calls 2

getUploadTimeoutMsFunction · 0.85
toProxyUrlFunction · 0.85

Tested by

no test coverage detected