api.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. const CoreClass = require("../core.js");
  2. const async = require("async");
  3. const crypto = require("crypto");
  4. class APIModule extends CoreClass {
  5. constructor() {
  6. super("api");
  7. }
  8. initialize() {
  9. return new Promise((resolve, reject) => {
  10. this.app = this.moduleManager.modules["app"];
  11. this.stations = this.moduleManager.modules["stations"];
  12. this.db = this.moduleManager.modules["db"];
  13. this.cache = this.moduleManager.modules["cache"];
  14. this.notifications = this.moduleManager.modules["notifications"];
  15. const actions = require("./actions");
  16. this.app.runJob("GET_APP", {})
  17. .then((response) => {
  18. response.app.get("/", (req, res) => {
  19. res.json({
  20. status: "success",
  21. message: "Coming Soon",
  22. });
  23. });
  24. // response.app.get("/debug_station", async (req, res) => {
  25. // const responseObject = {};
  26. // const stationModel = await this.db.runJob(
  27. // "GET_MODEL",
  28. // {
  29. // modelName: "station",
  30. // }
  31. // );
  32. // async.waterfall([
  33. // next => {
  34. // stationModel.find({}, next);
  35. // },
  36. // (stations, next) => {
  37. // responseObject.mongo = {
  38. // stations
  39. // };
  40. // next();
  41. // },
  42. // next => {
  43. // this.cache
  44. // .runJob("HGETALL", { table: "stations" })
  45. // .then(stations => {
  46. // next(null, stations);
  47. // })
  48. // .catch(next);
  49. // },
  50. // (stations, next) => {
  51. // responseObject.redis = {
  52. // stations
  53. // };
  54. // next();
  55. // },
  56. // next => {
  57. // responseObject.cryptoExamples = {};
  58. // responseObject.mongo.stations.forEach(station => {
  59. // const payloadName = `stations.nextSong?id=${station._id}`;
  60. // responseObject.cryptoExamples[station._id] = crypto
  61. // .createHash("md5")
  62. // .update(`_notification:${payloadName}_`)
  63. // .digest("hex")
  64. // });
  65. // next();
  66. // },
  67. // next => {
  68. // this.notifications.pub.keys("*", next);
  69. // },
  70. // (redisKeys, next) => {
  71. // responseObject.redis = {
  72. // ...redisKeys,
  73. // ttl: {}
  74. // };
  75. // async.eachLimit(redisKeys, 1, (redisKey, next) => {
  76. // this.notifications.pub.ttl(redisKey, (err, ttl) => {
  77. // responseObject.redis.ttl[redisKey] = ttl;
  78. // next(err);
  79. // })
  80. // }, next);
  81. // },
  82. // next => {
  83. // responseObject.debugLogs = this.moduleManager.debugLogs.stationIssue;
  84. // next();
  85. // },
  86. // next => {
  87. // responseObject.debugJobs = this.moduleManager.debugJobs;
  88. // next();
  89. // }
  90. // ], (err, response) => {
  91. // if (err) {
  92. // console.log(err);
  93. // return res.json({
  94. // error: err,
  95. // objectSoFar: responseObject
  96. // });
  97. // }
  98. // res.json(responseObject);
  99. // });
  100. // });
  101. // Object.keys(actions).forEach(namespace => {
  102. // Object.keys(actions[namespace]).forEach(action => {
  103. // let name = `/${namespace}/${action}`;
  104. // response.app.get(name, (req, res) => {
  105. // actions[namespace][action](null, result => {
  106. // if (typeof cb === "function")
  107. // return res.json(result);
  108. // });
  109. // });
  110. // });
  111. // });
  112. resolve();
  113. })
  114. .catch((err) => {
  115. reject(err);
  116. });
  117. });
  118. }
  119. }
  120. module.exports = new APIModule();