session.js 657 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. // 采集 Cookie 会话(淘宝闪购后台)
  3. const { sendJson, readBody } = require('../util.js');
  4. function register(app, ctx) {
  5. app.get('/api/session', async ({ res }) => {
  6. sendJson(res, 200, {
  7. cookieConfigured: !!ctx.session.cookie,
  8. ksidConfigured: !!ctx.session.getKsid(),
  9. });
  10. });
  11. app.post('/api/session', async ({ req, res }) => {
  12. const body = await readBody(req);
  13. ctx.session.cookie = String((body && body.cookie) || '');
  14. ctx.session.saveSession();
  15. ctx.logs.pushSystemLog('采集 Cookie 已更新', 'success');
  16. sendJson(res, 200, { ok: true });
  17. });
  18. }
  19. module.exports = { register };