fix(recommendation): use displayed skin age across reports and admin
This commit is contained in:
+8
-1
@@ -3,6 +3,8 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const net = require('net');
|
||||
const SkinScore = require('../js/skin-score');
|
||||
const ReportUI = require('../js/report-ui');
|
||||
const random = () => crypto.randomBytes(32).toString('hex');
|
||||
const hash = value => crypto.createHash('sha256').update(value).digest('hex');
|
||||
|
||||
@@ -162,7 +164,12 @@ module.exports = function createAccounts(root, env = process.env) {
|
||||
else if (/^R[\w-]+$/.test(id) && user.reports.some(r => r.id === id)) {
|
||||
const file = path.join(snapshots, user.id, id + '.json');
|
||||
if (!fs.existsSync(file)) json(res, 404, { ok: false, message: '报告文件暂不可用' });
|
||||
else json(res, 200, { ok: true, report: JSON.parse(fs.readFileSync(file, 'utf8')) });
|
||||
else {
|
||||
const snapshot=JSON.parse(fs.readFileSync(file,'utf8'));
|
||||
snapshot.vm=SkinScore.withDisplayRecommendation(snapshot.vm,snapshot.payload && snapshot.payload.result);
|
||||
if(snapshot.presentation)snapshot.presentation=Object.assign({},snapshot.presentation,{product:ReportUI.products.find(p=>p.tier===snapshot.vm.recommendation.tier)||null});
|
||||
json(res,200,{ok:true,report:snapshot});
|
||||
}
|
||||
} else json(res, 404, { ok: false, message: '报告不存在' });
|
||||
} else json(res, 404, { ok: false, message: '接口不存在' });
|
||||
} catch (_) { if (!res.headersSent) json(res, 400, { ok: false, message: '请求处理失败,请稍后重试' }); }
|
||||
|
||||
Reference in New Issue
Block a user