Files
goodbuddy/build/verify-site-release.cjs
T
mesalogo dc8f86ff3e feat: add trusted mirror update source
Version checks and downloads previously depended on GitHub Release. About & Updates now offers GitHub or a validated mirror source, keeps the selector beneath the startup-check switch, and disables it when startup checks are off.

The website resolves platform downloads from a bounded OSS release index with a GitHub fallback. Tagged releases publish and verify immutable OSS assets through OIDC before switching the latest-version index; deployment requires the configured Alibaba Cloud environment variables and role.

Release note: “关于与更新”新增 GitHub 与镜像节点选择,启动检查、手动检查和下载页使用同一可信来源;官网下载也可按系统、架构和安装包类型直接选择。
2026-08-17 17:20:24 +08:00

64 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')
function parseArguments(argv) {
if (argv.length !== 2 || argv[0] !== '--manifest' || !argv[1]) {
throw new Error('必须指定 --manifest')
}
return { manifest: resolve(argv[1]) }
}
async function verifySiteRelease(manifest, request = fetch) {
const files = Object.values(manifest?.targets ?? {}).flatMap(
(target) => Object.values(target?.files ?? {})
)
if (files.length !== 12) {
throw new Error(`官网发布文件数量错误:${files.length}`)
}
const urls = new Set()
for (const file of files) {
if (
typeof file?.url !== 'string' ||
!Number.isSafeInteger(file.size) ||
file.size < 1 ||
urls.has(file.url)
) {
throw new Error('官网发布文件元数据无效')
}
urls.add(file.url)
const response = await request(file.url, {
method: 'HEAD',
redirect: 'error'
})
if (!response.ok) {
throw new Error(`OSS 文件不可访问:${file.url}${response.status}`)
}
const contentLength = Number(response.headers.get('content-length'))
if (contentLength !== file.size) {
throw new Error(
`OSS 文件大小不匹配:${file.url},期望 ${file.size},实际 ${contentLength}`
)
}
}
return files.length
}
async function main(argv = process.argv.slice(2)) {
const options = parseArguments(argv)
const manifest = JSON.parse(readFileSync(options.manifest, 'utf8'))
const count = await verifySiteRelease(manifest)
console.log(`OSS 发布文件验证通过:${count} 个`)
}
module.exports = {
parseArguments,
verifySiteRelease
}
if (require.main === module) {
main().catch((error) => {
console.error(error)
process.exitCode = 1
})
}