common.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. var fs=require('fs');
  3. var F = require('../common/function');
  4. var C = require('../config');
  5. function commonMgr(app) {
  6. var mgr_path = __dirname;
  7. this.mgr_map = {};
  8. var that = this;
  9. console.log(mgr_path);
  10. this.init = function (app){
  11. try{
  12. if(!fs.existsSync(mgr_path)) {
  13. F.throwErr("commonMgr path err");
  14. }
  15. var files = fs.readdirSync(mgr_path);
  16. console.log(files);
  17. files.forEach(function(file, index) {
  18. try {
  19. if (file != 'common.js' && file != 'model.js') {
  20. var class_name = file.substr(0, file.length - 3);
  21. var mgr_obj = require('./' + class_name);
  22. that.mgr_map[class_name] = new mgr_obj(app, that);
  23. }
  24. } catch(e) {
  25. console.log(e.stack);
  26. }
  27. });
  28. }catch(e) {
  29. console.log(e.stack);
  30. }
  31. }
  32. this.init(app);
  33. /* 返回json字符替换规则
  34. */
  35. this.pregReplaceResJson = function* (res, uniid, ctx) {
  36. // var ip = yield that.mgr_map.redis.getImagePrefix(uniid);
  37. // var is_https = yield that.mgr_map.redis.getHttpProtoc(uniid);
  38. // var image_prefix = F.getImagePrefixByReqHost(ip,is_https);
  39. // var request_prefix = F.getShareHostIm(ip,is_https);
  40. // res = F.replaceRtmpHost(ip,res,ctx.is_mobile,ctx.is_msite);
  41. // res = F.replaceResJson(res, [C.pic_prefix,C.request_prefix], [image_prefix,request_prefix]);
  42. // res = F.replaceCreditStr(res, ctx.credit_type);
  43. // res = F.replaceCreditUnitStr(res, ctx.credit_type);
  44. return res;
  45. }
  46. // 滚动日志
  47. this.addDebugLogs = function (data) {
  48. that.mgr_map.logs.addLogs("debug/debug",data); //TODO 太多地方用到,先改成err 不遗漏
  49. };
  50. this.addLogs = function (data) {
  51. that.mgr_map.logs.addLogs("debug/debug",data); //TODO 太多地方用到,先改成err 不遗漏
  52. };
  53. this.addErrLogs = function (data) {
  54. that.mgr_map.logs.addLogs("err/err",data);
  55. };
  56. }
  57. module.exports = commonMgr;