feat: 完善淘宝小程序拍照、报告与登录流程
接入本地实时识别和自动三连拍,调整报告裁切、商品跳转、分享标题及居中页眉;完善游客会话、后台渠道隔离、部署脚本与回归测试。
This commit is contained in:
+16
-1
@@ -33,6 +33,7 @@ module.exports = function createAccounts(root, env = process.env) {
|
||||
if (base) { base.pathname = prefix; base.search = ''; base.hash = ''; }
|
||||
const secure = !!(base && base.protocol === 'https:');
|
||||
const guestSessions = new Map(); // No guest identities/sessions are written to disk.
|
||||
const taobaoGuests = new Map(); // Separate, temporary Bearer sessions; never written to db.
|
||||
const appId = env.WECHAT_APP_ID || '';
|
||||
const secret = env.WECHAT_APP_SECRET || '';
|
||||
const available = !rednote && !!(appId && secret && secure && !/^(localhost|127\.|192\.168\.|10\.|172\.(1[6-9]|2\d|3[01])\.)/.test(base.hostname));
|
||||
@@ -226,13 +227,27 @@ module.exports = function createAccounts(root, env = process.env) {
|
||||
save();
|
||||
return { token, expires_in: 30 * 86400, user: publicUser(user) };
|
||||
}
|
||||
function loginTaobaoGuest() {
|
||||
for (const [key, value] of taobaoGuests) if (value.expires <= Date.now()) taobaoGuests.delete(key);
|
||||
if (taobaoGuests.size >= 1000) return null;
|
||||
const token = random(), user = { id: crypto.randomUUID(), kind: 'taobao_guest' };
|
||||
taobaoGuests.set(hash(token), { user, expires: Date.now() + 8 * 3600000 });
|
||||
return { token, expires_in: 8 * 3600, user: publicUser(user) };
|
||||
}
|
||||
function taobaoSession(req) {
|
||||
const match = /^Bearer ([a-f0-9]{64})$/.exec(req.headers.authorization || '');
|
||||
const key = match && hash(match[1]), guest = key && taobaoGuests.get(key);
|
||||
if (guest) {
|
||||
if (guest.expires > Date.now()) return guest.user;
|
||||
taobaoGuests.delete(key);
|
||||
return null;
|
||||
}
|
||||
const row = match && db.sessions[hash(match[1])];
|
||||
return row && row.expires > Date.now() ? db.users.find(u => u.id === row.user && u.kind === 'taobao') : null;
|
||||
}
|
||||
function taobaoLogout(req) {
|
||||
const match = /^Bearer ([a-f0-9]{64})$/.exec(req.headers.authorization || '');
|
||||
if (match && taobaoGuests.delete(hash(match[1]))) return;
|
||||
if (match && taobaoSession(req)) { delete db.sessions[hash(match[1])]; save(); }
|
||||
}
|
||||
function reports(owner) {
|
||||
@@ -247,5 +262,5 @@ module.exports = function createAccounts(root, env = process.env) {
|
||||
return snapshot;
|
||||
}
|
||||
return { route, session, storeReport, reportPresentation, reportSnapshot, updateWrinkleViews, sameOrigin, wechatAvailable: available,
|
||||
loginTaobao, taobaoSession, taobaoLogout, reports, ownedReport };
|
||||
loginTaobao, loginTaobaoGuest, taobaoSession, taobaoLogout, reports, ownedReport };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user