feat(h5): allow guest access without login and retain history only for WeChat
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// Test-only persisted WeChat sessions. Never import from production code.
|
||||
'use strict';
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const crypto = require('node:crypto');
|
||||
module.exports = function seedWechat(root, count = 1) {
|
||||
const file = path.join(root, 'identities.json');
|
||||
if (fs.existsSync(file)) throw Error('Wechat fixture requires an empty test store');
|
||||
const db = { users: [], sessions: {}, states: {} }, entries = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const user = { id: 'fixture-wechat-' + i, kind: 'wechat', identity: 'fixture-' + i, reports: [] };
|
||||
const token = crypto.randomBytes(32).toString('hex');
|
||||
db.users.push(user);
|
||||
db.sessions[crypto.createHash('sha256').update(token).digest('hex')] = { user: user.id, expires: Date.now() + 86400000 };
|
||||
entries.push({ user, token, cookie: 'juzi_session=' + token });
|
||||
}
|
||||
fs.mkdirSync(root, { recursive: true });
|
||||
fs.writeFileSync(file, JSON.stringify(db));
|
||||
return entries;
|
||||
};
|
||||
Reference in New Issue
Block a user