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

+36 -15
View File
@@ -25940,6 +25940,7 @@ async function listApprovalRuns(client, params = {}) {
setOptional(searchParams, "startDate", params.startDate);
setOptional(searchParams, "endDate", params.endDate);
setOptional(searchParams, "status", params.status);
setOptional(searchParams, "sourceSystem", params.sourceSystem);
setOptional(searchParams, "taskMode", params.taskMode);
setOptional(searchParams, "search", params.search);
setOptional(searchParams, "sourceDocumentSN", params.sourceDocumentSN);
@@ -28062,7 +28063,7 @@ function pickRuleFields(rule, fields) {
}
function parseDurationMs(duration3) {
const match = duration3.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)?$/i);
if (!match)
if (!match || !match[1])
return 600000;
const val = parseFloat(match[1]);
const unit = (match[2] ?? "s").toLowerCase();
@@ -35413,7 +35414,7 @@ async function handleUpdateCommand(runtime, options = {}) {
mkdirSync6(tmpDir, { recursive: true });
try {
const downloadedFile = join8(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")) {
newBinaryPath = extractTarGz(downloadedFile, tmpDir, platform);
@@ -35471,8 +35472,8 @@ async function fetchGitHubReleases(repo, limit = 20) {
...token ? { Authorization: `Bearer ${token}` } : {}
};
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 url2 of urls) {
try {
@@ -35519,11 +35520,11 @@ async function fetchGitHubRelease(repo, targetVersion) {
...token ? { Authorization: `Bearer ${token}` } : {}
};
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 url2 of urls) {
try {
@@ -35578,26 +35579,46 @@ function matchAssetForPlatform(assets, platform, arch) {
const archive = matched.find((asset) => asset.name.endsWith(".tar.gz") || asset.name.endsWith(".tgz") || asset.name.endsWith(".zip"));
return archive || matched[0];
}
async function downloadFile(url2, destPath) {
const candidates = [url2];
if (url2.includes("github.com")) {
candidates.push(`https://ghfast.top/${url2}`);
async function downloadFile(url2, destPath, tagName, assetName) {
const candidates = [];
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}`);
}
if (url2.startsWith("https://git.ying-qing.cn")) {
candidates.unshift(url2);
} else {
if (url2.includes("github.com")) {
candidates.push(`https://ghfast.top/${url2}`);
candidates.push(`https://ghproxy.net/${url2}`);
candidates.push(`https://gh.ddlc.top/${url2}`);
candidates.push(`https://mirror.ghproxy.com/${url2}`);
}
candidates.push(url2);
}
const uniqueCandidates = Array.from(new Set(candidates));
let lastError;
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)`);
}
writeFileSync7(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 ${url2}: ${lastError?.message}`);
throw new Error(`Failed to download asset from all mirrors: ${lastError?.message}`);
}
function extractTarGz(archivePath, targetDir, platform) {
const result = spawnSync("tar", ["-xzf", archivePath, "-C", targetDir], { stdio: "pipe" });
+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 {