feat: 增强功能批量入库 - 双色彩引擎/抖动/杂色清理/品牌色板/PDF导出/编辑工具/分享/i18n 等验收代码
This commit is contained in:
1 parent
02762400fb
commit
f846fabfc6
77 files changed
+11372
-226
No files matched your search
@@ -4,6 +4,11 @@
|
||||
* ------------------------------------------------------------
|
||||
* 监控 xylpindou.com 的前端代码变更,通过追踪 Next.js chunk URL 和 build ID 的指纹。
|
||||
*
|
||||
* 双指纹机制 (dual-fingerprint):
|
||||
* - 首页 (/): fingerprint + chunks + buildId (向后兼容原有字段)
|
||||
* - chibi 页 (/chibi): chibiFingerprint + chibiChunks + chibiBuildId
|
||||
* - 任一页面指纹变化 => 告警 + 写入 changes-<timestamp>.log
|
||||
*
|
||||
* 用法:
|
||||
* node monitor.js 单次检查
|
||||
* node monitor.js --watch 3600 每 3600 秒循环检查
|
||||
@@ -21,6 +26,7 @@ const crypto = require('crypto');
|
||||
|
||||
// === 配置 ===
|
||||
const TARGET_URL = 'https://xylpindou.com/';
|
||||
const CHIBI_URL = 'https://xylpindou.com/chibi';
|
||||
const STATE_FILE = path.join(__dirname, 'state.json');
|
||||
const CHUNK_REGEX = /src="(\/_next\/static\/chunks\/[^"]+\.js)"/g;
|
||||
const BUILD_ID_REGEX = /"buildId":"([^"]+)"/;
|
||||
@@ -119,6 +125,28 @@ function computeFingerprint(chunks, buildId) {
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算组合指纹: SHA-256(home指纹 + chibi指纹)
|
||||
*/
|
||||
function computeCombinedFingerprint(homeFingerprint, chibiFingerprint) {
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(homeFingerprint);
|
||||
hash.update('\n');
|
||||
hash.update(chibiFingerprint);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* 对比两页 chunk 列表,返回新增/移除(按文件名比较)
|
||||
*/
|
||||
function diffChunks(oldChunks, newChunks) {
|
||||
const oldFilenames = new Set(oldChunks.map(chunkFilename));
|
||||
const newFilenames = new Set(newChunks.map(chunkFilename));
|
||||
const added = newChunks.filter(c => !oldFilenames.has(chunkFilename(c)));
|
||||
const removed = oldChunks.filter(c => !newFilenames.has(chunkFilename(c)));
|
||||
return { added, removed };
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取之前的状态
|
||||
*/
|
||||
@@ -145,35 +173,50 @@ function writeState(state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入变更日志
|
||||
* 写入变更日志(含首页 + chibi 两页的 chunk 明细)
|
||||
*/
|
||||
function writeChangeLog(oldState, newState) {
|
||||
const oldChunks = oldState ? oldState.chunks : [];
|
||||
const newChunks = newState.chunks;
|
||||
const oldChunks = oldState ? oldState.chunks || [] : [];
|
||||
const newChunks = newState.chunks || [];
|
||||
const oldChibiChunks = oldState ? oldState.chibiChunks || [] : [];
|
||||
const newChibiChunks = newState.chibiChunks || [];
|
||||
|
||||
const oldFilenames = new Set(oldChunks.map(chunkFilename));
|
||||
const newFilenames = new Set(newChunks.map(chunkFilename));
|
||||
|
||||
const added = newChunks.filter(c => !oldFilenames.has(chunkFilename(c)));
|
||||
const removed = oldChunks.filter(c => !newFilenames.has(chunkFilename(c)));
|
||||
const homeDiff = diffChunks(oldChunks, newChunks);
|
||||
const chibiDiff = diffChunks(oldChibiChunks, newChibiChunks);
|
||||
|
||||
const logFile = path.join(__dirname, `changes-${fileTimestamp()}.log`);
|
||||
const lines = [];
|
||||
lines.push(`=== 竞品变更检测报告 ===`);
|
||||
lines.push(`检测时间: ${timestamp()}`);
|
||||
lines.push(`目标网址: ${TARGET_URL}`);
|
||||
lines.push(`目标网址: ${TARGET_URL} (首页) / ${CHIBI_URL} (chibi)`);
|
||||
lines.push('');
|
||||
lines.push(`组合指纹: ${oldState && oldState.combinedFingerprint ? oldState.combinedFingerprint : '无'} -> ${newState.combinedFingerprint}`);
|
||||
lines.push('');
|
||||
lines.push(`--- 首页 ---`);
|
||||
lines.push(`旧 Build ID: ${oldState ? oldState.buildId : '无'}`);
|
||||
lines.push(`新 Build ID: ${newState.buildId}`);
|
||||
lines.push(`旧指纹: ${oldState ? oldState.fingerprint : '无'}`);
|
||||
lines.push(`新指纹: ${newState.fingerprint}`);
|
||||
lines.push('');
|
||||
lines.push(`--- 新增的 chunk (${added.length}) ---`);
|
||||
added.forEach(c => lines.push(` + ${c}`));
|
||||
lines.push(` -- 首页 新增的 chunk (${homeDiff.added.length}) --`);
|
||||
homeDiff.added.forEach(c => lines.push(` + ${c}`));
|
||||
lines.push(` -- 首页 移除的 chunk (${homeDiff.removed.length}) --`);
|
||||
homeDiff.removed.forEach(c => lines.push(` - ${c}`));
|
||||
lines.push(` -- 首页 不变的 chunk (${newChunks.length - homeDiff.added.length}) --`);
|
||||
lines.push(` (首页共 ${newChunks.length} 个 chunk)`);
|
||||
lines.push('');
|
||||
lines.push(`--- 移除的 chunk (${removed.length}) ---`);
|
||||
removed.forEach(c => lines.push(` - ${c}`));
|
||||
lines.push(`--- chibi 页 ---`);
|
||||
lines.push(`旧 Build ID: ${oldState ? oldState.chibiBuildId : '无'}`);
|
||||
lines.push(`新 Build ID: ${newState.chibiBuildId}`);
|
||||
lines.push(`旧指纹: ${oldState && oldState.chibiFingerprint ? oldState.chibiFingerprint : '无'}`);
|
||||
lines.push(`新指纹: ${newState.chibiFingerprint}`);
|
||||
lines.push('');
|
||||
lines.push(`--- 不变的 chunk (${newChunks.length - added.length}) ---`);
|
||||
lines.push(`(共 ${newChunks.length} 个 chunk,其中 ${newChunks.length - added.length} 个未变)`);
|
||||
lines.push(` -- chibi 新增的 chunk (${chibiDiff.added.length}) --`);
|
||||
chibiDiff.added.forEach(c => lines.push(` + ${c}`));
|
||||
lines.push(` -- chibi 移除的 chunk (${chibiDiff.removed.length}) --`);
|
||||
chibiDiff.removed.forEach(c => lines.push(` - ${c}`));
|
||||
lines.push(` -- chibi 不变的 chunk (${newChibiChunks.length - chibiDiff.added.length}) --`);
|
||||
lines.push(` (chibi 共 ${newChibiChunks.length} 个 chunk)`);
|
||||
|
||||
fs.writeFileSync(logFile, lines.join('\n'), 'utf-8');
|
||||
return logFile;
|
||||
@@ -183,37 +226,57 @@ function writeChangeLog(oldState, newState) {
|
||||
* 单次检查逻辑
|
||||
*/
|
||||
async function runCheck() {
|
||||
console.log(`[${timestamp()}] 正在检查 ${TARGET_URL} ...`);
|
||||
console.log(`[${timestamp()}] 正在检查 ${TARGET_URL} 和 ${CHIBI_URL} ...`);
|
||||
|
||||
let html;
|
||||
try {
|
||||
html = await fetchHTML(TARGET_URL);
|
||||
} catch (err) {
|
||||
console.error(`[${timestamp()}] 获取页面失败: ${err.message}`);
|
||||
// 网络失败时,保持旧状态,退出码 0
|
||||
// 并行抓取两页(每轮检查最多 2 次请求)
|
||||
const [homeResult, chibiResult] = await Promise.all([
|
||||
fetchHTML(TARGET_URL).then(html => ({ ok: true, html })).catch(err => ({ ok: false, err })),
|
||||
fetchHTML(CHIBI_URL).then(html => ({ ok: true, html })).catch(err => ({ ok: false, err })),
|
||||
]);
|
||||
|
||||
if (!homeResult.ok || !chibiResult.ok) {
|
||||
if (!homeResult.ok) {
|
||||
console.error(`[${timestamp()}] 获取首页失败: ${homeResult.err.message}`);
|
||||
}
|
||||
if (!chibiResult.ok) {
|
||||
console.error(`[${timestamp()}] 获取 chibi 页失败: ${chibiResult.err.message}`);
|
||||
}
|
||||
// 网络失败时,保持旧状态,不告警、不覆盖
|
||||
const oldState = readState();
|
||||
if (oldState) {
|
||||
console.log(`[${timestamp()}] 保留上次检测状态 (指纹: ${oldState.fingerprint})`);
|
||||
console.log(`[${timestamp()}] 保留上次检测状态 (首页指纹: ${oldState.fingerprint})`);
|
||||
} else {
|
||||
console.log(`[${timestamp()}] 尚无历史状态,跳过`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const chunks = extractChunks(html);
|
||||
const buildId = extractBuildId(html);
|
||||
const homeChunks = extractChunks(homeResult.html);
|
||||
const homeBuildId = extractBuildId(homeResult.html);
|
||||
const homeFingerprint = computeFingerprint(homeChunks, homeBuildId);
|
||||
|
||||
if (chunks.length === 0) {
|
||||
console.error(`[${timestamp()}] 警告: 未找到任何 Next.js chunk URL,页面结构可能已变更`);
|
||||
const chibiChunks = extractChunks(chibiResult.html);
|
||||
const chibiBuildId = extractBuildId(chibiResult.html);
|
||||
const chibiFingerprint = computeFingerprint(chibiChunks, chibiBuildId);
|
||||
|
||||
if (homeChunks.length === 0) {
|
||||
console.error(`[${timestamp()}] 警告: 首页未找到任何 Next.js chunk URL,页面结构可能已变更`);
|
||||
}
|
||||
if (chibiChunks.length === 0) {
|
||||
console.error(`[${timestamp()}] 警告: chibi 页未找到任何 Next.js chunk URL,页面结构可能已变更`);
|
||||
}
|
||||
|
||||
const fingerprint = computeFingerprint(chunks, buildId);
|
||||
const combinedFingerprint = computeCombinedFingerprint(homeFingerprint, chibiFingerprint);
|
||||
const oldState = readState();
|
||||
|
||||
const newState = {
|
||||
fingerprint,
|
||||
chunks,
|
||||
buildId: buildId || 'unknown',
|
||||
fingerprint: homeFingerprint,
|
||||
chunks: homeChunks,
|
||||
buildId: homeBuildId || 'unknown',
|
||||
chibiFingerprint,
|
||||
chibiChunks,
|
||||
chibiBuildId: chibiBuildId || 'unknown',
|
||||
combinedFingerprint,
|
||||
lastChecked: new Date().toISOString(),
|
||||
};
|
||||
|
||||
@@ -221,14 +284,27 @@ async function runCheck() {
|
||||
// 首次运行:记录状态
|
||||
writeState(newState);
|
||||
console.log(`[${timestamp()}] 首次检测完成,已记录初始状态`);
|
||||
console.log(` Build ID: ${buildId || '未找到'}`);
|
||||
console.log(` Chunk 数量: ${chunks.length}`);
|
||||
console.log(` 指纹: ${fingerprint}`);
|
||||
console.log(` 首页 Build ID: ${homeBuildId || '未找到'}`);
|
||||
console.log(` 首页 Chunk 数量: ${homeChunks.length}`);
|
||||
console.log(` 首页指纹: ${homeFingerprint}`);
|
||||
console.log(` chibi Build ID: ${chibiBuildId || '未找到'}`);
|
||||
console.log(` chibi Chunk 数量: ${chibiChunks.length}`);
|
||||
console.log(` chibi指纹: ${chibiFingerprint}`);
|
||||
console.log(` 组合指纹: ${combinedFingerprint}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldState.fingerprint === fingerprint) {
|
||||
console.log(`[${timestamp()}] 无变更 (指纹: ${fingerprint})`);
|
||||
// 向后兼容:旧状态只有首页指纹(无 chibi 字段)时,chibi 属于首次初始化,不视为变更
|
||||
const isChibiMigration = !oldState.chibiFingerprint;
|
||||
|
||||
const homeChanged = oldState.fingerprint !== homeFingerprint;
|
||||
const chibiChanged = !isChibiMigration && oldState.chibiFingerprint !== chibiFingerprint;
|
||||
|
||||
if (!homeChanged && !chibiChanged) {
|
||||
console.log(`[${timestamp()}] 无变更 (首页指纹: ${homeFingerprint})`);
|
||||
if (isChibiMigration) {
|
||||
console.log(` chibi 页指纹已初始化 (${chibiFingerprint})`);
|
||||
}
|
||||
// 更新 lastChecked 但不改变指纹
|
||||
writeState(newState);
|
||||
return;
|
||||
@@ -236,11 +312,17 @@ async function runCheck() {
|
||||
|
||||
// 指纹变更!
|
||||
console.log(`[${timestamp()}] ⚠ 检测到变更!`);
|
||||
console.log(` 旧指纹: ${oldState.fingerprint}`);
|
||||
console.log(` 新指纹: ${fingerprint}`);
|
||||
console.log(` 旧 Build ID: ${oldState.buildId}`);
|
||||
console.log(` 新 Build ID: ${buildId || '未找到'}`);
|
||||
console.log(` 旧 Chunk 数: ${oldState.chunks.length} → 新 Chunk 数: ${chunks.length}`);
|
||||
console.log(` 首页指纹: ${oldState.fingerprint} -> ${homeFingerprint}`);
|
||||
console.log(` chibi指纹: ${isChibiMigration ? '(初始化)' : `${oldState.chibiFingerprint} -> ${chibiFingerprint}`}`);
|
||||
console.log(` 组合指纹: ${oldState.combinedFingerprint || '无'} -> ${combinedFingerprint}`);
|
||||
if (homeChanged) {
|
||||
console.log(` 首页 Build ID: ${oldState.buildId} -> ${homeBuildId || '未找到'}`);
|
||||
console.log(` 首页 Chunk 数: ${oldState.chunks.length} -> ${homeChunks.length}`);
|
||||
}
|
||||
if (chibiChanged) {
|
||||
console.log(` chibi Build ID: ${oldState.chibiBuildId || '无'} -> ${chibiBuildId || '未找到'}`);
|
||||
console.log(` chibi Chunk 数: ${(oldState.chibiChunks || []).length} -> ${chibiChunks.length}`);
|
||||
}
|
||||
|
||||
const logFile = writeChangeLog(oldState, newState);
|
||||
writeState(newState);
|
||||
@@ -284,4 +366,4 @@ async function main() {
|
||||
main().catch((err) => {
|
||||
console.error(`[${timestamp()}] 致命错误: ${err.message}`);
|
||||
process.exit(0); // 即使出错也退出码 0
|
||||
});
|
||||
});
|
||||
@@ -12,5 +12,19 @@
|
||||
"/_next/static/chunks/turbopack-0uj0wxl2dgb09.js"
|
||||
],
|
||||
"buildId": "unknown",
|
||||
"lastChecked": "2026-08-13T13:36:13.542Z"
|
||||
"chibiFingerprint": "f0544edda0cbc8f7bb17f191a2bffb430fb0bb5ceaad3d37f641b4eb3f8f0f1e",
|
||||
"chibiChunks": [
|
||||
"/_next/static/chunks/01xlw8hd842-c.js",
|
||||
"/_next/static/chunks/02g3221oh~3le.js",
|
||||
"/_next/static/chunks/03~yq9q893hmn.js",
|
||||
"/_next/static/chunks/045g~0~zva_mv.js",
|
||||
"/_next/static/chunks/0d3shmwh5_nmn.js",
|
||||
"/_next/static/chunks/0dgq26a5_oy.a.js",
|
||||
"/_next/static/chunks/10u3y4bw1ayzs.js",
|
||||
"/_next/static/chunks/148vkvkqm_lqh.js",
|
||||
"/_next/static/chunks/turbopack-0uj0wxl2dgb09.js"
|
||||
],
|
||||
"chibiBuildId": "unknown",
|
||||
"combinedFingerprint": "9185c52395d78fdb6c5053927337f08f76bc7ee19b788fde2340bfcb6e445bc6",
|
||||
"lastChecked": "2026-08-13T14:01:39.359Z"
|
||||
}
|
||||
Reference in new issue
Block a user