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

Function pollNativeUploadProgress

utils/upload.ts:1346–1370  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1344}
1345
1346function pollNativeUploadProgress(): () => void {
1347 const native = Native;
1348 if (!native) return () => { };
1349 const stallMs = getUploadTimeoutMs();
1350 let lastLoaded = -1;
1351 let lastProgressAt = Date.now();
1352 let aborted = false;
1353 const interval = setInterval(async () => {
1354 try {
1355 const p = await native.getUploadProgress();
1356 if (!p || p.total <= 0 || cancelRequested || aborted) return;
1357
1358 if (p.loaded !== lastLoaded) {
1359 lastLoaded = p.loaded;
1360 lastProgressAt = Date.now();
1361 const percent = Math.round(Math.max(0, Math.min(100, p.loaded / p.total * 100)));
1362 setUploadState({ percent, transferredBytes: p.loaded, totalBytes: p.total });
1363 } else if (Date.now() - lastProgressAt > stallMs) {
1364 aborted = true;
1365 void native.cancelUpload();
1366 }
1367 } catch { /* ignore transient poll errors */ }
1368 }, 150);
1369 return () => clearInterval(interval);
1370}
1371
1372async function uploadWithFallbacks(fileBlob: Blob, filename: string, primary: ServiceType): Promise<string> {
1373 const uploadOrder = buildUploadOrder(primary, filename);

Callers 1

uploadWithFallbacksFunction · 0.85

Calls 2

getUploadTimeoutMsFunction · 0.85
setUploadStateFunction · 0.85

Tested by

no test coverage detected