Refine simulation batch timestamps and update source messaging

This commit is contained in:
gitea committed 2026-10-23 17:01:21 +08:00
1 parent d00fa1b960
commit d77c0505d8
5 files changed
+69 -9

No files matched your search

+29 -5
View File
@@ -160,18 +160,32 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
// `.old.<timestamp>` backup (undeletable while its image was executing).
pruneUpdateLeftovers(process.execPath);
const releases = await fetchGitHubReleases(repo, 30);
const { releases, source } = await fetchReleasesWithSource(repo, 30);
const release = targetVersion
? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ??
await fetchGitHubRelease(repo, targetVersion))
: (releases[0] ?? await fetchGitHubRelease(repo));
if (!release) {
const mirrorMode = getMirrorMode();
const newest = releases[0]?.version;
const wanted = targetVersion ? `v${targetVersion.replace(/^v/, "")}` : "最新版本";
const sourcesTried = mirrorMode === "auto"
? ["Gitea 国内镜像", "GitHub"]
: mirrorMode === "gitea" ? ["Gitea 国内镜像"] : ["GitHub"];
const message = targetVersion && newest
? `${source === "gitea" ? "国内镜像(Gitea)" : "GitHub"} 尚未提供 ${wanted}(该源当前最新 v${newest})。已尝试的更新源:${sourcesTried.join("、")};镜像同步存在时间差,请稍后重试。`
: `无法访问更新源(已尝试:${sourcesTried.join("、")})。请检查网络后重试。`;
printJson({
updated: false,
currentVersion: VERSION,
mode: "binary",
message: `Failed to query releases from repository '${repo}'`
mirrorMode,
sourcesTried,
releaseSource: source,
sourceLatestVersion: newest ?? null,
message
});
return;
}
@@ -445,7 +459,10 @@ export function getMirrorMode(): "auto" | "github" | "gitea" {
return "auto";
}
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
async function fetchReleasesWithSource(
repo: string,
limit = 20
): Promise<{ releases: GitHubRelease[]; source: "gitea" | "github" | null }> {
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
const headers: Record<string, string> = {
"User-Agent": `seal-use/${VERSION}`,
@@ -509,13 +526,20 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRele
assets
});
}
if (list.length > 0) return list;
if (list.length > 0) {
return { releases: list, source: url.includes("git.ying-qing.cn") ? "gitea" : "github" };
}
} catch {
// try next source
}
}
return [];
return { releases: [], source: null };
}
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
const { releases } = await fetchReleasesWithSource(repo, limit);
return releases;
}
async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise<GitHubRelease | undefined> {