mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(updater): migrate cloud catalog sync and auto-update URLs to yuhuan-dev
This commit is contained in:
@@ -57,15 +57,19 @@ export const CSRF_TOKEN = process.env.ANTIGRAVITY_CSRF_TOKEN;
|
||||
/**
|
||||
* GitHub 官方云端价格目录与插件发布包地址配置。
|
||||
*/
|
||||
export const OFFICIAL_GITHUB_REPO = 'yuhuan-dev/antigravity-usage-monitor';
|
||||
export const LEGACY_GITHUB_REPOS = Object.freeze([
|
||||
'yuhuan2498281558/antigravity-usage-monitor',
|
||||
]);
|
||||
export const CLOUD_CATALOG_URLS = [
|
||||
'https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json',
|
||||
`https://raw.githubusercontent.com/${OFFICIAL_GITHUB_REPO}/main/pricing-catalog.json`,
|
||||
];
|
||||
export const DEFAULT_RELEASE_URL =
|
||||
'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest';
|
||||
`https://github.com/${OFFICIAL_GITHUB_REPO}/releases/latest`;
|
||||
export const DEFAULT_DOWNLOAD_URL =
|
||||
'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip';
|
||||
`https://github.com/${OFFICIAL_GITHUB_REPO}/releases/latest/download/usage-monitor.zip`;
|
||||
export const DEFAULT_ARCHIVE_FALLBACK_URL =
|
||||
'https://codeload.github.com/yuhuan2498281558/antigravity-usage-monitor/zip/refs/heads/main';
|
||||
`https://codeload.github.com/${OFFICIAL_GITHUB_REPO}/zip/refs/heads/main`;
|
||||
|
||||
/** 云端目录常规自动检查间隔(6 小时)与失败冷却时间(5 分钟)。 */
|
||||
export const CLOUD_SYNC_TTL_MS = 6 * 3600 * 1000;
|
||||
|
||||
@@ -26,7 +26,9 @@ import {
|
||||
DATA_DIR,
|
||||
DEFAULT_ARCHIVE_FALLBACK_URL,
|
||||
DEFAULT_DOWNLOAD_URL,
|
||||
LEGACY_GITHUB_REPOS,
|
||||
LS_ADDR,
|
||||
OFFICIAL_GITHUB_REPO,
|
||||
PLUGIN_ROOT,
|
||||
REMOTE_CATALOG_CACHE_FILE,
|
||||
cloudSyncState,
|
||||
@@ -158,6 +160,31 @@ function pruneExtraneousFiles(targetDir, referenceDir) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 若本地 Git 仓库的 `origin` 仍指向已迁移的旧官方仓库地址,返回同协议的新官方仓库地址;
|
||||
* 对于非旧官方仓库(如已是新地址或用户自建 Fork)返回空字符串,不做改动。
|
||||
*
|
||||
* @param {string} rawUrl
|
||||
* @returns {string}
|
||||
*/
|
||||
export function resolveMigratedGitRemoteUrl(rawUrl) {
|
||||
const trimmed = String(rawUrl || '').trim();
|
||||
if (!trimmed) return '';
|
||||
for (const legacyRepo of LEGACY_GITHUB_REPOS) {
|
||||
const escaped = legacyRepo.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
if (new RegExp(`^https://github\\.com/${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) {
|
||||
return `https://github.com/${OFFICIAL_GITHUB_REPO}.git`;
|
||||
}
|
||||
if (new RegExp(`^git@github\\.com:${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) {
|
||||
return `git@github.com:${OFFICIAL_GITHUB_REPO}.git`;
|
||||
}
|
||||
if (new RegExp(`^ssh://git@github\\.com/${escaped}(?:\\.git)?/?$`, 'i').test(trimmed)) {
|
||||
return `ssh://git@github.com/${OFFICIAL_GITHUB_REPO}.git`;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 在真实运行环境下对目标目录的核心 JS 文件执行 `node --check` 语法预检。
|
||||
*
|
||||
@@ -277,7 +304,31 @@ export async function performPluginUpdate({ isAuto = false } = {}) {
|
||||
const targetBranch = currentBranch || 'main';
|
||||
const remoteRef = `origin/${targetBranch}`;
|
||||
|
||||
// 3. 只读拉取远端分支引用,并严格从 origin/<branch>:plugin.json 读取远端版本号(严禁回退使用缓存版本)
|
||||
// 3. 存量旧仓库远程地址平滑迁移:若 origin 仍指向已更换的旧官方仓库,自动切换至新仓库地址
|
||||
try {
|
||||
const remoteUrlRes = await runExecFile('git', [
|
||||
'-C',
|
||||
PLUGIN_ROOT,
|
||||
'remote',
|
||||
'get-url',
|
||||
'origin',
|
||||
]);
|
||||
const migratedRemoteUrl = resolveMigratedGitRemoteUrl(remoteUrlRes.stdout);
|
||||
if (migratedRemoteUrl) {
|
||||
await runExecFile('git', [
|
||||
'-C',
|
||||
PLUGIN_ROOT,
|
||||
'remote',
|
||||
'set-url',
|
||||
'origin',
|
||||
migratedRemoteUrl,
|
||||
]);
|
||||
}
|
||||
} catch {
|
||||
// 忽略非标准 remote 配置异常,不阻断常规拉取
|
||||
}
|
||||
|
||||
// 4. 只读拉取远端分支引用,并严格从 origin/<branch>:plugin.json 读取远端版本号(严禁回退使用缓存版本)
|
||||
await runExecFile('git', ['-C', PLUGIN_ROOT, 'fetch', 'origin', targetBranch, '--tags']);
|
||||
|
||||
let remoteVersion = '';
|
||||
@@ -298,7 +349,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) {
|
||||
remoteVersion = '';
|
||||
}
|
||||
|
||||
// 4. 强制版本门禁:远端版本无法确认或不高于当前版本时,严禁执行 git pull 降级/覆盖
|
||||
// 5. 强制版本门禁:远端版本无法确认或不高于当前版本时,严禁执行 git pull 降级/覆盖
|
||||
if (!remoteVersion || compareSemver(remoteVersion, previousVersion) <= 0) {
|
||||
const msg = `当前已是最新版本 (v${previousVersion})`;
|
||||
const result = {
|
||||
@@ -317,7 +368,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 5. 提交拓扑预检:确保当前 HEAD 是远端分支的祖先提交(无本地超前或分叉提交)
|
||||
// 6. 提交拓扑预检:确保当前 HEAD 是远端分支的祖先提交(无本地超前或分叉提交)
|
||||
try {
|
||||
await runExecFile('git', [
|
||||
'-C',
|
||||
@@ -343,7 +394,7 @@ export async function performPluginUpdate({ isAuto = false } = {}) {
|
||||
return pluginUpdateState.lastResult;
|
||||
}
|
||||
|
||||
// 6. 确认全部门禁通过后,执行快进合并并校验 JS 语法
|
||||
// 7. 确认全部门禁通过后,执行快进合并并校验 JS 语法
|
||||
await runExecFile('git', ['-C', PLUGIN_ROOT, 'pull', '--ff-only', 'origin', targetBranch]);
|
||||
await verifyPluginJsSyntax(PLUGIN_ROOT);
|
||||
rebuildActiveCatalog();
|
||||
|
||||
@@ -16,7 +16,9 @@ import {
|
||||
DEFAULT_ARCHIVE_FALLBACK_URL,
|
||||
DEFAULT_DOWNLOAD_URL,
|
||||
DEFAULT_RELEASE_URL,
|
||||
LEGACY_GITHUB_REPOS,
|
||||
LOCAL_CATALOG_FILE,
|
||||
OFFICIAL_GITHUB_REPO,
|
||||
PLUGIN_MANIFEST_FILE,
|
||||
PLUGIN_ROOT,
|
||||
REMOTE_CATALOG_CACHE_FILE,
|
||||
@@ -44,7 +46,35 @@ export function isValidSemver(v) {
|
||||
);
|
||||
}
|
||||
|
||||
const OFFICIAL_REPO_PATH_PREFIX = '/yuhuan2498281558/antigravity-usage-monitor';
|
||||
const OFFICIAL_REPO_PATH_PREFIX = `/${OFFICIAL_GITHUB_REPO.toLowerCase()}`;
|
||||
const LEGACY_REPO_PATH_PREFIXES = LEGACY_GITHUB_REPOS.map((repo) => `/${repo.toLowerCase()}`);
|
||||
|
||||
/**
|
||||
* 判断来源 URL 是否属于已迁移的旧官方 GitHub 仓库地址。
|
||||
*
|
||||
* @param {*} rawUrl
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isLegacyGithubRepoUrl(rawUrl) {
|
||||
if (typeof rawUrl !== 'string' || !rawUrl.trim()) return false;
|
||||
try {
|
||||
const parsed = new URL(rawUrl.trim());
|
||||
const host = parsed.hostname.toLowerCase();
|
||||
const pathname = parsed.pathname.toLowerCase();
|
||||
if (
|
||||
host !== 'github.com' &&
|
||||
host !== 'raw.githubusercontent.com' &&
|
||||
host !== 'codeload.github.com'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return LEGACY_REPO_PATH_PREFIXES.some(
|
||||
(prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`)
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验更新/下载链接是否属于可信的 GitHub 官方仓库与 HTTPS 域名白名单。
|
||||
@@ -245,6 +275,8 @@ export function sanitizeCatalogPayload(raw) {
|
||||
const explicitReleaseUrl = sanitizeTrustedGithubUrl(raw.releaseUrl, '');
|
||||
const explicitDownloadUrl = sanitizeTrustedGithubUrl(raw.downloadUrl, '');
|
||||
const explicitArchiveUrl = sanitizeTrustedGithubUrl(raw.archiveFallbackUrl, '');
|
||||
const rawSourceUrl = typeof raw.sourceUrl === 'string' ? raw.sourceUrl.trim() : '';
|
||||
const isLegacySource = isLegacyGithubRepoUrl(rawSourceUrl);
|
||||
|
||||
return {
|
||||
schemaVersion: Number(raw.schemaVersion || 1),
|
||||
@@ -261,8 +293,8 @@ export function sanitizeCatalogPayload(raw) {
|
||||
hasReleaseUrl: Boolean(explicitReleaseUrl),
|
||||
hasDownloadUrl: Boolean(explicitDownloadUrl),
|
||||
hasArchiveFallbackUrl: Boolean(explicitArchiveUrl),
|
||||
fetchedAtMs: Number(raw.fetchedAtMs || 0),
|
||||
sourceUrl: typeof raw.sourceUrl === 'string' ? raw.sourceUrl : '',
|
||||
fetchedAtMs: isLegacySource ? 0 : Number(raw.fetchedAtMs || 0),
|
||||
sourceUrl: isLegacySource ? '' : rawSourceUrl,
|
||||
pricing,
|
||||
placeholders,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user