MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / estimateZipSize

Function estimateZipSize

website/src/lib/repo-provider.ts:377–410  ·  view source on GitHub ↗
(
  ref: RepoRef,
  branchesToTry: string[]
)

Source from the content-addressed store, hash-verified

375}
376
377export async function estimateZipSize(
378 ref: RepoRef,
379 branchesToTry: string[]
380): Promise<{ estimatedZipSize: number; isEstimateReliable: boolean }> {
381 let estimatedZipSize = 4 * 1024 * 1024;
382 let isEstimateReliable = false;
383
384 if (ref.provider !== "github") {
385 return { estimatedZipSize, isEstimateReliable };
386 }
387
388 for (const branch of branchesToTry) {
389 const jsdelivrMetaUrl = getJsdelivrMetaUrl(ref, branch);
390 if (!jsdelivrMetaUrl) continue;
391 try {
392 const metaRes = await fetch(jsdelivrMetaUrl);
393 if (metaRes.ok) {
394 const metaData = await metaRes.json();
395 if (metaData?.files && Array.isArray(metaData.files)) {
396 const uncompressedSize = getJsdelivrTotalSize(metaData.files);
397 if (uncompressedSize > 0) {
398 estimatedZipSize = Math.max(500 * 1024, uncompressedSize * 0.22);
399 isEstimateReliable = true;
400 }
401 break;
402 }
403 }
404 } catch (err) {
405 console.warn(`[Explore] Failed jsDelivr metadata fetch for branch ${branch}:`, err);
406 }
407 }
408
409 return { estimatedZipSize, isEstimateReliable };
410}

Callers 1

fetchRepositoryFilesFunction · 0.90

Calls 3

getJsdelivrMetaUrlFunction · 0.85
getJsdelivrTotalSizeFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected