( ref: RepoRef, branchesToTry: string[] )
| 375 | } |
| 376 | |
| 377 | export 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 | } |
no test coverage detected