|
2 | 2 |
|
3 | 3 | const job = require('../parts/jobs/job.js'),
|
4 | 4 | log = require('../utils/log.js')('job:ping'),
|
5 |
| - config = require("../../frontend/express/config.js"), |
| 5 | + countlyConfig = require("../../frontend/express/config.js"), |
| 6 | + versionInfo = require('../../frontend/express/version.info'), |
6 | 7 | request = require('request');
|
7 | 8 |
|
8 | 9 | class PingJob extends job.Job {
|
9 | 10 | run (db, done) {
|
10 |
| - if(config.web.track != "none"){ |
11 |
| - db.collection("members").findOne({global_admin:true}, function(err, member){ |
12 |
| - if(!err && member){ |
13 |
| - var date = new Date(); |
14 |
| - request({ |
15 |
| - uri:"https://stats.count.ly/i", |
16 |
| - method:"GET", |
17 |
| - timeout:4E3, |
18 |
| - qs:{ |
19 |
| - device_id:member.email, |
20 |
| - app_key:"386012020c7bf7fcb2f1edf215f1801d6146913f", |
21 |
| - timestamp: Math.floor(date.getTime()/1000), |
22 |
| - hour: date.getHours(), |
23 |
| - dow: date.getDay(), |
24 |
| - events:JSON.stringify([ |
25 |
| - { |
26 |
| - key: "PING", |
27 |
| - count: 1 |
28 |
| - } |
29 |
| - ]) |
30 |
| - } |
31 |
| - }, function(a/*, c, b*/) { |
32 |
| - log.d('Done running ping job: %j', a); |
33 |
| - done(); |
34 |
| - }); |
| 11 | + request("http://localhost/configs", function(err, res, body){log.d(err, body);}); |
| 12 | + var countlyConfigOrig = JSON.parse(JSON.stringify(countlyConfig)); |
| 13 | + var url = "https://count.ly/configurations/ce/tracking"; |
| 14 | + if(versionInfo.type != "777a2bf527a18e0fffe22fb5b3e322e68d9c07a6"){ |
| 15 | + url = "https://count.ly/configurations/ee/tracking"; |
| 16 | + } |
| 17 | + request(url, function (err, response, body) { |
| 18 | + if(typeof body === "string"){ |
| 19 | + try{ |
| 20 | + body = JSON.parse(body); |
35 | 21 | }
|
36 |
| - else{ |
37 |
| - done(); |
| 22 | + catch(ex){body = null;} |
| 23 | + } |
| 24 | + if(body){ |
| 25 | + if(countlyConfigOrig.web.use_intercom && typeof body.intercom !== "undefined"){ |
| 26 | + countlyConfig.web.use_intercom = body.intercom; |
38 | 27 | }
|
39 |
| - }); |
40 |
| - } |
41 |
| - else{ |
42 |
| - done(); |
43 |
| - } |
| 28 | + if(typeof countlyConfigOrig.web.track === "undefined" && typeof body.stats !== "undefined"){ |
| 29 | + if(body.stats){ |
| 30 | + countlyConfig.web.track = null; |
| 31 | + } |
| 32 | + else{ |
| 33 | + countlyConfig.web.track = "none"; |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + log.d(err, body, countlyConfigOrig, countlyConfig); |
| 38 | + if(countlyConfig.web.track != "none"){ |
| 39 | + db.collection("members").findOne({global_admin:true}, function(err, member){ |
| 40 | + if(!err && member){ |
| 41 | + var date = new Date(); |
| 42 | + request({ |
| 43 | + uri:"https://stats.count.ly/i", |
| 44 | + method:"GET", |
| 45 | + timeout:4E3, |
| 46 | + qs:{ |
| 47 | + device_id:member.email, |
| 48 | + app_key:"386012020c7bf7fcb2f1edf215f1801d6146913f", |
| 49 | + timestamp: Math.floor(date.getTime()/1000), |
| 50 | + hour: date.getHours(), |
| 51 | + dow: date.getDay(), |
| 52 | + events:JSON.stringify([ |
| 53 | + { |
| 54 | + key: "PING", |
| 55 | + count: 1 |
| 56 | + } |
| 57 | + ]) |
| 58 | + } |
| 59 | + }, function(a/*, c, b*/) { |
| 60 | + log.d('Done running ping job: %j', a); |
| 61 | + done(); |
| 62 | + }); |
| 63 | + } |
| 64 | + else{ |
| 65 | + done(); |
| 66 | + } |
| 67 | + }); |
| 68 | + } |
| 69 | + else{ |
| 70 | + done(); |
| 71 | + } |
| 72 | + }); |
44 | 73 | }
|
45 | 74 | }
|
46 | 75 |
|
|
0 commit comments