push.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class PushController extends Controller {
  4. async index() {
  5. const { ctx } = this;
  6. const { ip, header = {}, request = {} } = ctx;
  7. const {origin, referer} = header;
  8. const userAgent = header['user-agent'];
  9. const {rawBody, body} = request;
  10. if(!rawBody || !userAgent || !referer || !origin || (body && body.length < 1)){
  11. ctx.body = { isOk:false, msg:"请求方式异常" };
  12. return;
  13. }
  14. const { AcData } = ctx.model;
  15. for (let i = 0; i < body.length; i++){
  16. let {t, uuid, acData} = body[i];
  17. let { type } = acData
  18. const acDataIns = new AcData({
  19. uuid: uuid,
  20. ip: ip,
  21. referer: referer,
  22. type: type,
  23. updated: new Date().getTime(),
  24. token: t,
  25. userAgent: userAgent
  26. });
  27. acDataIns._acData = acData;
  28. acDataIns.markModified('_acData');
  29. acDataIns.save();
  30. }
  31. ctx.body = { isOk:true, msg:"上报成功" };
  32. }
  33. }
  34. module.exports = PushController;