Refine update command with high-speed Gitea and multi-mirror fallback
Binaries / Build & Release Binaries (push) Has been cancelled

This commit is contained in:
gitea committed 2026-08-25 18:12:26 +08:00
1 parent 7441e0a9a8
commit b3792ac3ff
2 files changed
+78 -29

No files matched your search

+42 -14
View File
@@ -219,7 +219,7 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
try {
const downloadedFile = join(tmpDir, asset.name);
await downloadFile(asset.downloadUrl, downloadedFile);
await downloadFile(asset.downloadUrl, downloadedFile, release.tagName, asset.name);
let newBinaryPath = downloadedFile;
if (asset.name.endsWith(".tar.gz") || asset.name.endsWith(".tgz")) {
@@ -310,8 +310,8 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRele
};
const urls = [
`https://api.github.com/repos/${repo}/releases?per_page=${limit}`,
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases?per_page=${limit}`
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases?per_page=${limit}`,
`https://api.github.com/repos/${repo}/releases?per_page=${limit}`
];
for (const url of urls) {
@@ -371,12 +371,12 @@ async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise
const urls = tag
? [
`https://api.github.com/repos/${repo}/releases/tags/${tag}`,
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases/tags/${tag}`
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases/tags/${tag}`,
`https://api.github.com/repos/${repo}/releases/tags/${tag}`
]
: [
`https://api.github.com/repos/${repo}/releases/latest`,
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases/latest`
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases/latest`,
`https://api.github.com/repos/${repo}/releases/latest`
];
for (const url of urls) {
@@ -459,28 +459,56 @@ function matchAssetForPlatform(
return archive || matched[0];
}
async function downloadFile(url: string, destPath: string) {
const candidates = [url];
if (url.includes("github.com")) {
candidates.push(`https://ghfast.top/${url}`);
async function downloadFile(url: string, destPath: string, tagName?: string, assetName?: string) {
const candidates: string[] = [];
// 1. High-speed Gitea direct mirror first
if (tagName && assetName) {
const tag = tagName.startsWith("v") ? tagName : `v${tagName}`;
candidates.push(`https://git.ying-qing.cn/gitea/seal-home/releases/download/${tag}/${assetName}`);
candidates.push(`https://git.ying-qing.cn/gitea/seal-home/releases/download/latest/${assetName}`);
}
// 2. Direct url if it's not already Gitea
if (url.startsWith("https://git.ying-qing.cn")) {
candidates.unshift(url);
} else {
// 3. Fast GitHub CDN proxies
if (url.includes("github.com")) {
candidates.push(`https://ghfast.top/${url}`);
candidates.push(`https://ghproxy.net/${url}`);
candidates.push(`https://gh.ddlc.top/${url}`);
candidates.push(`https://mirror.ghproxy.com/${url}`);
}
// 4. Direct GitHub fallback
candidates.push(url);
}
// Deduplicate candidates
const uniqueCandidates = Array.from(new Set(candidates));
let lastError: Error | undefined;
for (const candidate of candidates) {
for (const candidate of uniqueCandidates) {
try {
const res = await fetch(candidate, { signal: AbortSignal.timeout(15000) });
console.error(`==> Trying download mirror: ${candidate}`);
const res = await fetch(candidate, { signal: AbortSignal.timeout(30000) });
if (!res.ok) {
throw new Error(`HTTP ${res.status} ${res.statusText}`);
}
const buffer = Buffer.from(await res.arrayBuffer());
if (buffer.length < 1000) {
throw new Error(`Downloaded content is suspiciously small (${buffer.length} bytes)`);
}
writeFileSync(destPath, buffer);
console.error(`✓ Download succeeded from: ${candidate} (${buffer.length} bytes)`);
return;
} catch (err) {
lastError = err instanceof Error ? err : new Error(String(err));
console.error(` ↳ Mirror failed: ${lastError.message}`);
}
}
throw new Error(`Failed to download asset from ${url}: ${lastError?.message}`);
throw new Error(`Failed to download asset from all mirrors: ${lastError?.message}`);
}
function extractTarGz(archivePath: string, targetDir: string, platform: string): string {