mirror of
https://github.com/Silentely/eSIM-Tools.git
synced 2026-09-03 06:24:20 +08:00
* ✨ feat: 打包 [email protected] 到本地 ES 模块 * ♻️ refactor(qrcode): 移除 CDN 加载逻辑,改用本地 import 引入 qrcode-generator * 🔧 chore: 移除 CDN preconnect 提示,QR 码库已内联 * 🔧 chore: 清理 CSP 配置,移除不再需要的 CDN 域名 * ✨ feat: 将 QR 码生成迁移到 Edge Function,消除后端冷启动延迟 - 在 Edge Function 中内联 qrcode-generator 库(~20KB),直接生成 QR 码 - 删除废弃的 Netlify Function (qrcode-generate.js) - 更新 server.js 移除对已删除函数的引用 - 更新测试文件适配新的 Edge 内联架构 * ♻️ refactor: 代码质量修复 — 移除死代码、消除变量遮蔽、添加交叉引用注释 * 🔧 chore: 修复非阻塞风险 — 补充 strict 模式、移除废弃 qrcode 依赖 - Edge Function qrcode-lib.js 补充 'use strict' 声明,与浏览器版保持一致 - 移除已废弃的 qrcode npm 依赖(原用于已删除的 Netlify Function) * ♻️ refactor: 消除魔法数字、补充脆耦合和 async 技术债注释 - Edge Function 中 QR margin 魔法数字 8 替换为 QR_MARGIN_MODULES 常量 - generateQRCodeLocal 补充 async 无 await 的技术债说明 - error.message.startsWith 条件补充校验函数耦合关系注释 * 🐛 fix: 修复边界条件 — null JSON body、vendor 字符串异常、CDN preconnect 残留 - Edge Function: null JSON body 解构移到 try/catch 内,添加 null/非对象检查 - qrcode-generator: 库 throw 字符串时统一转换为 Error 对象,避免 .startsWith 崩溃 - index.html: 移除不再需要的 CDN preconnect 提示(jsdelivr/cdnjs) * ♻️ refactor: 修复 CSP 恢复、异常归一化、自定义 Error 类、负面路径测试 - netlify.toml: 恢复 script-src 中 cdn.jsdelivr.net(Bootstrap JS 仍依赖) - Edge Function catch: 归一化非 Error 异常(库可能 throw 字符串) - Edge Function QR margin: createDataURL(cellSize, 2) → createDataURL(cellSize, cellSize * 2) 对齐模块边距 - Edge Function: 补充认证模型和 QR 格式变更注释 - qrcode-generator.js: 引入 QRCodeValidationError 替代 error.message.startsWith 脆耦合 - tests/bff-proxy: 添加 6 个 Edge QR 负面路径测试(无效 JSON、空/超长/非字符串 data、超范围 size) - tests/qrcode-generator: 添加库 throw 字符串异常的测试 - scripts/sync-qrcode-lib.js: 新增库代码同步验证脚本 * 🐛 fix: 修复 server.js CSP 缺少 jsdelivr、同步脚本 CRLF 归一化、fallback 拦截校验错误 - server.js: 恢复 script-src 中 cdn.jsdelivr.net(本地开发 Bootstrap JS 依赖) - sync-qrcode-lib.js: 归一化 CRLF 换行符避免跨平台误报 - qrcode-generator.js: generateQRCodeWithFallback 入口处拦截 QRCodeValidationError,避免无效输入触发无意义的后端降级
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
/**
|
|
* 同步 qrcode-lib.js 浏览器版和 Edge Function Deno 版
|
|
*
|
|
* 两个文件共享相同的 minified 库代码,仅头部注释和导出方式不同。
|
|
* 此脚本确保库代码部分完全一致,防止版本漂移。
|
|
*
|
|
* 用法: node scripts/sync-qrcode-lib.js
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const BROWSER_LIB = path.resolve(__dirname, '../src/js/modules/qrcode-lib.js');
|
|
const EDGE_LIB = path.resolve(__dirname, '../netlify/edge-functions/qrcode-lib.js');
|
|
|
|
function extractLibraryCode(filePath) {
|
|
const content = fs.readFileSync(filePath, 'utf-8').replace(/\r\n/g, '\n');
|
|
// 提取 'use strict'; 和 export 之间的库代码
|
|
const lines = content.split('\n');
|
|
const libLines = lines.filter(line =>
|
|
line !== "'use strict';" &&
|
|
!line.startsWith('// ') &&
|
|
!line.startsWith('/**') &&
|
|
!line.startsWith(' * ') &&
|
|
!line.startsWith(' */') &&
|
|
line !== '' &&
|
|
!line.startsWith('export ')
|
|
);
|
|
return libLines.join('\n');
|
|
}
|
|
|
|
const browserLib = extractLibraryCode(BROWSER_LIB);
|
|
const edgeLib = extractLibraryCode(EDGE_LIB);
|
|
|
|
if (browserLib === edgeLib) {
|
|
console.log('✅ qrcode-lib.js 库代码已同步,无需更新');
|
|
process.exit(0);
|
|
} else {
|
|
console.error('❌ qrcode-lib.js 库代码不一致!');
|
|
console.error(' 浏览器版:', BROWSER_LIB);
|
|
console.error(' Edge 版:', EDGE_LIB);
|
|
console.error(' 请确保两个文件的 minified 库代码完全相同');
|
|
process.exit(1);
|
|
}
|