api3management_check.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. /**
  3. *
  4. * @author LanJianRong
  5. * @date 2021-12-27
  6. * @version
  7. */
  8. const maintainConst = require('../const/maintain');
  9. const sign = require('../const/sign');
  10. const jwt = require('jsonwebtoken');
  11. module.exports = options => {
  12. return function* api3managementCheck(next) {
  13. try {
  14. // 获取系统维护信息
  15. const maintainData = yield this.service.maintain.getDataById(1);
  16. if (maintainData.status === maintainConst.status.ongoing) {
  17. throw '系统维护中~';
  18. }
  19. const token = this.query.auth;
  20. if (!token) {
  21. throw '参数有误';
  22. }
  23. try {
  24. const decoded = jwt.verify(token, sign.managementApiSecretKey);
  25. if (!decoded.data) throw '参数有误';
  26. this.data = decoded.data;
  27. } catch (error) {
  28. throw error;
  29. }
  30. // const data = yield this.service.project.getProjectByCode(code.toString().trim());
  31. // if (data === null) {
  32. // throw '不存在项目数据';
  33. // }
  34. // if (data.custom === 0) {
  35. // throw '无法通过接口登录本系统';
  36. // }
  37. // if (data.custom === 1 && data.can_api === 0) {
  38. // throw '接口已关闭,无法使用';
  39. // }
  40. // const encryptSign = crypto.createHash('md5').update(data.code + data.secret + time.toString()).digest('hex').toString();
  41. // if (encryptSign !== sign) {
  42. // throw '参数验证失败';
  43. // }
  44. // this.projectData = data;
  45. yield next;
  46. } catch (err) {
  47. this.body = {
  48. code: -1,
  49. msg: err.toString(),
  50. data: null,
  51. };
  52. return;
  53. }
  54. };
  55. };