MCPcopy Index your code
hub / github.com/ScattrdBlade/bigFileUpload / uploadRequestWithTimeout

Function uploadRequestWithTimeout

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

Source from the content-addressed store, hash-verified

241}
242
243async function uploadRequestWithTimeout(url: string, options: RequestInit): Promise<XhrResponse> {
244 const requestUrl = toProxyUrl(url);
245
246 return new Promise((resolve, reject) => {
247 const xhr = new XMLHttpRequest();
248 activeXhr = xhr;
249 const stallMs = getUploadTimeoutMs();
250 let timeout = setTimeout(() => xhr.abort(), stallMs);
251 const resetStallTimeout = () => {
252 clearTimeout(timeout);
253 timeout = setTimeout(() => xhr.abort(), stallMs);
254 };
255
256 xhr.open(options.method || "GET", requestUrl);
257
258 for (const [key, value] of getHeaderEntries(options.headers)) {
259 xhr.setRequestHeader(key, value);
260 }
261
262 xhr.upload.onprogress = event => {
263 resetStallTimeout();
264 setXhrUploadProgress(event);
265 };
266 xhr.onload = () => resolve(new XhrResponse(xhr));
267 xhr.onerror = () => reject(new Error("Upload failed"));
268 xhr.onabort = () => reject(new Error(cancelRequested ? "Upload cancelled by user" : "Upload timed out"));
269 xhr.onloadend = () => {
270 clearTimeout(timeout);
271 xhr.upload.onprogress = null;
272 if (activeXhr === xhr) {
273 activeXhr = null;
274 }
275 };
276
277 const { body } = options;
278 xhr.send(body instanceof ReadableStream ? null : body as XMLHttpRequestBodyInit | null);
279 });
280}
281
282function resolveShareXRequestValue(value: string | number | boolean, filename: string): string {
283 return String(value)

Callers 15

uploadToShareXFunction · 0.85
uploadToZiplineFunction · 0.85
uploadToNestFunction · 0.85
uploadToEncryptingHostFunction · 0.85
uploadToEzHostFunction · 0.85
uploadToCatboxFunction · 0.85
uploadToLitterboxFunction · 0.85
uploadToGofileFunction · 0.85
uploadToTmpfilesFunction · 0.85
uploadToBuzzheavierFunction · 0.85
uploadToTempShFunction · 0.85
uploadToFilebinFunction · 0.85

Calls 5

toProxyUrlFunction · 0.85
getUploadTimeoutMsFunction · 0.85
getHeaderEntriesFunction · 0.85
resetStallTimeoutFunction · 0.85
setXhrUploadProgressFunction · 0.85

Tested by

no test coverage detected