feat(update): block gitea in CI and support SEAL_USE_MIRROR routing
This commit is contained in:
1 parent
b6fbd0669f
commit
df8c8c8280
3 files changed
+160
-87
No files matched your search
+82
-38
@@ -307,6 +307,13 @@ type GitHubRelease = {
|
||||
assets: GitHubAsset[];
|
||||
};
|
||||
|
||||
export function getMirrorMode(): "auto" | "github" | "gitea" {
|
||||
const env = (process.env.SEAL_USE_MIRROR || process.env.SEAL_HOME_MIRROR)?.trim().toLowerCase();
|
||||
if (env === "github" || env === "gitea") return env;
|
||||
if (process.env.CI) return "github";
|
||||
return "auto";
|
||||
}
|
||||
|
||||
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
|
||||
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||
const headers: Record<string, string> = {
|
||||
@@ -315,13 +322,23 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRele
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {})
|
||||
};
|
||||
|
||||
const urls = [
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/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}`
|
||||
];
|
||||
if (repo !== LEGACY_GITHUB_REPO) {
|
||||
urls.push(`https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases?per_page=${limit}`);
|
||||
const mirrorMode = getMirrorMode();
|
||||
const urls: string[] = [];
|
||||
|
||||
// 1. Gitea releases (bypassed in CI / GitHub-only mode)
|
||||
if (mirrorMode !== "github") {
|
||||
urls.push(
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/releases?per_page=${limit}`,
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases?per_page=${limit}`
|
||||
);
|
||||
}
|
||||
|
||||
// 2. GitHub releases (bypassed in Gitea-only mode)
|
||||
if (mirrorMode !== "gitea") {
|
||||
urls.push(`https://api.github.com/repos/${repo}/releases?per_page=${limit}`);
|
||||
if (repo !== LEGACY_GITHUB_REPO) {
|
||||
urls.push(`https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases?per_page=${limit}`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const url of urls) {
|
||||
@@ -379,19 +396,36 @@ async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {})
|
||||
};
|
||||
|
||||
const urls = tag
|
||||
? [
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/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}`,
|
||||
...(repo !== LEGACY_GITHUB_REPO ? [`https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases/tags/${tag}`] : [])
|
||||
]
|
||||
: [
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/releases/latest`,
|
||||
`https://git.ying-qing.cn/api/v1/repos/gitea/seal-home/releases/latest`,
|
||||
`https://api.github.com/repos/${repo}/releases/latest`,
|
||||
...(repo !== LEGACY_GITHUB_REPO ? [`https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases/latest`] : [])
|
||||
];
|
||||
const mirrorMode = getMirrorMode();
|
||||
const urls: string[] = [];
|
||||
|
||||
// 1. Gitea releases (bypassed in CI / GitHub-only mode)
|
||||
if (mirrorMode !== "github") {
|
||||
urls.push(
|
||||
tag
|
||||
? `https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/releases/tags/${tag}`
|
||||
: `https://git.ying-qing.cn/api/v1/repos/gitea/seal-use/releases/latest`,
|
||||
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/latest`
|
||||
);
|
||||
}
|
||||
|
||||
// 2. GitHub releases (bypassed in Gitea-only mode)
|
||||
if (mirrorMode !== "gitea") {
|
||||
urls.push(
|
||||
tag
|
||||
? `https://api.github.com/repos/${repo}/releases/tags/${tag}`
|
||||
: `https://api.github.com/repos/${repo}/releases/latest`
|
||||
);
|
||||
if (repo !== LEGACY_GITHUB_REPO) {
|
||||
urls.push(
|
||||
tag
|
||||
? `https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases/tags/${tag}`
|
||||
: `https://api.github.com/repos/${LEGACY_GITHUB_REPO}/releases/latest`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let fallbackRelease: GitHubRelease | undefined;
|
||||
|
||||
@@ -494,30 +528,40 @@ function logProgress(msg: string) {
|
||||
}
|
||||
|
||||
async function downloadFile(url: string, destPath: string, tagName?: string, assetName?: string) {
|
||||
const mirrorMode = getMirrorMode();
|
||||
const candidates: string[] = [];
|
||||
const tag = tagName ? (tagName.startsWith("v") ? tagName : `v${tagName}`) : undefined;
|
||||
const fileName = assetName || url.split("/").pop() || "";
|
||||
|
||||
// 1. High-speed Gitea direct mirror first
|
||||
if (tag && fileName) {
|
||||
candidates.push(`https://git.ying-qing.cn/gitea/seal-home/releases/download/${tag}/${fileName}`);
|
||||
}
|
||||
if (url.startsWith("https://git.ying-qing.cn")) {
|
||||
candidates.push(url);
|
||||
// 1. High-speed Gitea direct mirror (bypassed in CI / GitHub-only mode)
|
||||
if (mirrorMode !== "github") {
|
||||
if (tag && fileName) {
|
||||
candidates.push(
|
||||
`https://git.ying-qing.cn/gitea/seal-use/releases/download/${tag}/${fileName}`,
|
||||
`https://git.ying-qing.cn/gitea/seal-home/releases/download/${tag}/${fileName}`
|
||||
);
|
||||
}
|
||||
if (url.startsWith("https://git.ying-qing.cn")) {
|
||||
candidates.push(url);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fast GitHub CDN proxies and direct GitHub fallback
|
||||
if (tag && fileName) {
|
||||
const ghDirectUrl = `https://github.com/${DEFAULT_GITHUB_REPO}/releases/download/${tag}/${fileName}`;
|
||||
candidates.push(`https://ghfast.top/${ghDirectUrl}`);
|
||||
candidates.push(`https://gh.ddlc.top/${ghDirectUrl}`);
|
||||
candidates.push(ghDirectUrl);
|
||||
} else if (url.includes("github.com")) {
|
||||
candidates.push(`https://ghfast.top/${url}`);
|
||||
candidates.push(`https://gh.ddlc.top/${url}`);
|
||||
candidates.push(url);
|
||||
} else {
|
||||
candidates.push(url);
|
||||
// 2. Fast GitHub CDN proxies and direct GitHub fallback (bypassed in Gitea-only mode)
|
||||
if (mirrorMode !== "gitea") {
|
||||
if (tag && fileName) {
|
||||
const ghDirectUrl = `https://github.com/${DEFAULT_GITHUB_REPO}/releases/download/${tag}/${fileName}`;
|
||||
if (!process.env.CI) {
|
||||
candidates.push(`https://ghfast.top/${ghDirectUrl}`, `https://gh.ddlc.top/${ghDirectUrl}`);
|
||||
}
|
||||
candidates.push(ghDirectUrl);
|
||||
} else if (url.includes("github.com")) {
|
||||
if (!process.env.CI) {
|
||||
candidates.push(`https://ghfast.top/${url}`, `https://gh.ddlc.top/${url}`);
|
||||
}
|
||||
candidates.push(url);
|
||||
} else {
|
||||
candidates.push(url);
|
||||
}
|
||||
}
|
||||
|
||||
// Deduplicate candidates
|
||||
|
||||
Reference in new issue
Block a user