This commit is contained in:
Ubuntu
2026-09-26 23:55:11 +08:00
parent 859d262fe3
commit 7d72d7dd5a
6 changed files with 282 additions and 11 deletions
+10
View File
@@ -15,6 +15,7 @@ const path = require('path');
const PORT = Number(process.env.PORT) || 8080;
const ROOT = __dirname;
const FACEPP_URL = 'https://api-cn.faceplusplus.com/facepp/v1/skinanalyze_pro';
const DATA_DIR = path.join(ROOT, 'data', 'results'); // 每次检测的原始返回落盘(复核用,已在 .gitignore)
/* ─── 密钥加载:环境变量优先,其次 apikey.bash,最后 reference 下的 credentials.env ─── */
function loadCredentials() {
@@ -185,6 +186,15 @@ async function handleAnalyze(req, res) {
return res.end(JSON.stringify({ ok: false, code: 'INTERNAL_ERROR', message: ERR_MSG.INTERNAL_ERROR }));
}
const result = fpJson.result;
// 原始返回完整落盘(含 face_maps base64),供复核/真值比对;写盘失败不影响检测响应
try {
fs.mkdirSync(DATA_DIR, { recursive: true });
const reqId = String(fpJson.request_id || 'noreq').replace(/[^\w,-]/g, '').slice(0, 40);
const stamp = new Date().toISOString().replace(/[:.]/g, '').slice(0, 15);
const fname = `${stamp}-${reqId}.json`;
fs.writeFile(path.join(DATA_DIR, fname), JSON.stringify(fpJson), () => {});
console.log(`[analyze] 原始返回已落盘: data/results/${fname}`);
} catch (e) { console.log(`[analyze] 落盘失败(忽略): ${e.message}`); }
// face_maps 是整幅 base64 叠加图,体积很大:只透传报告页所需图层(REPORT_MAPS),
// 值补 data: URL 前缀供前端 <img> 直接用;未选中的图层直接删除键;
// marks 坐标字段(acne/brown_spot/mole/closed_comedones/wrinkle_mark 等)本就在 result 里,原样透传