Skip to content

Commit fe95fd3

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/cookie-parser-1.4.7
2 parents 1149bbb + 6a44326 commit fe95fd3

File tree

8 files changed

+207
-209
lines changed

8 files changed

+207
-209
lines changed

api/parts/mgmt/app_users.js

+62-46
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ usersApi.merge = function(app_id, newAppUser, new_id, old_id, new_device_id, old
764764
var deleteMyExport = function(exportID) { //tries to delete packed file, exported folder and saved export in gridfs
765765
//normally there should be only export in gridfs. Cleaning all to be sure.
766766
//rejects only if there stays any saved data for export
767+
log.d("deleteMyExport:" + exportID);
767768
return new Promise(function(resolve, reject) {
768769
//remove archive
769770
var errors = [];
@@ -775,7 +776,6 @@ var deleteMyExport = function(exportID) { //tries to delete packed file, exporte
775776
errors.push(err);
776777
}
777778
}
778-
779779
countlyFs.gridfs.deleteFile("appUsers", path.resolve(__dirname, './../../../export/AppUser/' + exportID + '.tar.gz'), {id: exportID + '.tar.gz'}, function(error) {
780780
if (error && error.message && error.message.substring(0, 12) !== "FileNotFound" && error.message.substring(0, 14) !== 'File not found') {
781781
log.e(error.message.substring(0, 14));
@@ -806,6 +806,18 @@ var deleteMyExport = function(exportID) { //tries to delete packed file, exporte
806806
}
807807
});
808808

809+
810+
}).then(function() {
811+
return new Promise(function(resolve, reject) {
812+
common.db.collection("exports").remove({"_eid": exportID}, function(err0) {
813+
if (err0) {
814+
reject(err0);
815+
}
816+
else {
817+
resolve();
818+
}
819+
});
820+
});
809821
});
810822
};
811823

@@ -822,46 +834,42 @@ usersApi.deleteExport = function(filename, params, callback) {
822834
//remove archive
823835
deleteMyExport(base_name[0]).then(
824836
function() {
825-
common.db.collection("exports").remove({"_eid": base_name[0]}, function(err0) {
826-
if (err0) {
827-
log.e(err0);
828-
}
829-
if (name_parts.length === 3 && name_parts[2] !== 'HASH') {
830-
//update user info
831-
common.db.collection('app_users' + name_parts[1]).update({"uid": name_parts[2]}, {$unset: {"appUserExport": ""}}, {upsert: false, multi: true}, function(err) {
832-
if (err) {
833-
callback(err, "");
834-
}
835-
else {
836-
plugins.dispatch("/systemlogs", {
837-
params: params,
838-
action: "export_app_user_deleted",
839-
data: {
840-
result: "ok",
841-
uids: name_parts[2],
842-
id: base_name[0],
843-
app_id: name_parts[1],
844-
info: "Exported data deleted"
845-
}
846-
});
847-
callback(null, "Export deleted");
848-
}
849-
});
850-
}
851-
else {
852-
plugins.dispatch("/systemlogs", {
853-
params: params,
854-
action: "export_app_user_deleted",
855-
data: {
856-
result: "ok",
857-
id: base_name[0],
858-
app_id: name_parts[1],
859-
info: "Exported data deleted"
860-
}
861-
});
862-
callback(null, "Export deleted");
863-
}
864-
});
837+
if (name_parts.length === 3 && name_parts[2] !== 'HASH') {
838+
//update user info
839+
common.db.collection('app_users' + name_parts[1]).update({"uid": name_parts[2]}, {$unset: {"appUserExport": ""}}, {upsert: false, multi: true}, function(err) {
840+
if (err) {
841+
callback(err, "");
842+
}
843+
else {
844+
plugins.dispatch("/systemlogs", {
845+
params: params,
846+
action: "export_app_user_deleted",
847+
data: {
848+
result: "ok",
849+
uids: name_parts[2],
850+
id: base_name[0],
851+
app_id: name_parts[1],
852+
info: "Exported data deleted"
853+
}
854+
});
855+
callback(null, "Export deleted");
856+
}
857+
});
858+
}
859+
else {
860+
plugins.dispatch("/systemlogs", {
861+
params: params,
862+
action: "export_app_user_deleted",
863+
data: {
864+
result: "ok",
865+
id: base_name[0],
866+
app_id: name_parts[1],
867+
info: "Exported data deleted"
868+
}
869+
});
870+
callback(null, "Export deleted");
871+
}
872+
865873
},
866874
function(err) {
867875
console.log(err);
@@ -1073,12 +1081,20 @@ usersApi.export = function(app_id, query, params, callback) {
10731081
// else {
10741082
// resolve();
10751083
// }
1076-
new Promise(function(resolve) {
1077-
log.d("collection marked");
1078-
//export data from metric_changes
10791084

1080-
export_safely({projection: {"appUserExport": 0}, export_id: export_id, app_id: app_id, args: [...dbargs, "--collection", "metric_changes" + app_id, "-q", '{"uid":{"$in": ["' + res[0].uid.join('","') + '"]}}', "--out", export_folder + "/metric_changes" + app_id + ".json"]}).finally(function() {
1081-
resolve();
1085+
//try deleting old export
1086+
deleteMyExport(export_id).then(function(err) {
1087+
if (err) {
1088+
log.e(err);
1089+
}
1090+
log.d("old export deleted");
1091+
return new Promise(function(resolve) {
1092+
log.d("collection marked");
1093+
//export data from metric_changes
1094+
1095+
export_safely({projection: {"appUserExport": 0}, export_id: export_id, app_id: app_id, args: [...dbargs, "--collection", "metric_changes" + app_id, "-q", '{"uid":{"$in": ["' + res[0].uid.join('","') + '"]}}', "--out", export_folder + "/metric_changes" + app_id + ".json"]}).finally(function() {
1096+
resolve();
1097+
});
10821098
});
10831099
}).then(function() {
10841100
log.d("metric_changes exported");

api/utils/countlyFs.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,19 @@ countlyFs.gridfs = {};
601601
* console.log("Finished", err);
602602
* });
603603
*/
604-
ob.deleteFileById = function(category, id, callback) {
604+
ob.deleteFileById = async function(category, id, callback) {
605605
var bucket = new GridFSBucket(db, { bucketName: category });
606-
bucket.delete(id, function(error) {
606+
try {
607+
await bucket.delete(id);
607608
if (callback) {
608-
callback(error);
609+
callback(null);
609610
}
610-
});
611+
}
612+
catch (ee) {
613+
if (callback) {
614+
callback(ee);
615+
}
616+
}
611617
};
612618

613619
/**

plugins/push/api/send/platforms/a.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const key = 'a';
1818
* - has its own compilation part;
1919
* - has its own sending part;
2020
* - has no distinct representation in UI, therefore it's virtual.
21-
*
21+
*
2222
* Huawei push is only available on select Android devices, therefore it doesn't deserve a separate checkbox in UI from users perspective.
2323
* Yet notification payload, provider communication and a few other things are different, therefore it's a virtual platform. You can send to huawei directly using
2424
* API, but whenever you send to Android you'll also send to huawei if Huawei credentials are set.
@@ -27,20 +27,20 @@ const virtuals = ['h'];
2727

2828
/**
2929
* Extract token & field from token_session request
30-
*
30+
*
3131
* @param {object} qstring request params
3232
* @returns {string[]|undefined} array of [platform, field, token] if qstring has platform-specific token data, undefined otherwise
3333
*/
3434
function extractor(qstring) {
3535
if (qstring.android_token !== undefined && (!qstring.token_provider || qstring.token_provider === 'FCM')) {
3636
const token = qstring.android_token === 'BLACKLISTED' ? '' : qstring.android_token;
37-
return [key, FIELDS['0'], token, util.hashInt(token)];
37+
return [key, FIELDS['0'], token, util.hash(token)];
3838
}
3939
}
4040

4141
/**
4242
* Make an estimated guess about request platform
43-
*
43+
*
4444
* @param {string} userAgent user-agent header
4545
* @returns {string} platform key if it looks like request made by this platform
4646
*/
@@ -56,7 +56,7 @@ class FCM extends Splitter {
5656
* Standard constructor
5757
* @param {string} log logger name
5858
* @param {string} type type of connection: ap, at, id, ia, ip, ht, hp
59-
* @param {Credentials} creds FCM credentials
59+
* @param {Credentials} creds FCM credentials
6060
* @param {Object[]} messages initial array of messages to send
6161
* @param {Object} options standard stream options
6262
* @param {number} options.pool.pushes number of notifications which can be processed concurrently, this parameter is strictly set to 500
@@ -90,8 +90,8 @@ class FCM extends Splitter {
9090
}
9191

9292
/**
93-
* Compile & send messages
94-
*
93+
* Compile & send messages
94+
*
9595
* @param {Object[]} data pushes to send, no more than 500 per function call as enforced by stream writableHighWaterMark
9696
* @param {integer} length number of bytes in data
9797
* @returns {Promise} sending promise
@@ -217,7 +217,7 @@ class FCM extends Splitter {
217217

218218
/**
219219
* Create new empty payload for the note object given
220-
*
220+
*
221221
* @param {Message} msg NMessageote object
222222
* @returns {object} empty payload object
223223
*/
@@ -227,7 +227,7 @@ function empty(msg) {
227227

228228
/**
229229
* Finish data object after setting all the properties
230-
*
230+
*
231231
* @param {object} data platform-specific data to finalize
232232
* @return {object} resulting object
233233
*/
@@ -256,7 +256,7 @@ const fields = [
256256
*/
257257
const map = {
258258
/**
259-
* Sends sound
259+
* Sends sound
260260
* @param {Template} t template
261261
* @param {string} sound sound string
262262
*/
@@ -267,7 +267,7 @@ const map = {
267267
},
268268

269269
/**
270-
* Sends badge
270+
* Sends badge
271271
* @param {Template} t template
272272
* @param {number} badge badge (0..N)
273273
*/
@@ -278,7 +278,7 @@ const map = {
278278
/**
279279
* Sends buttons
280280
* !NOTE! buttons & messagePerLocale are inter-dependent as buttons urls/titles are locale-specific
281-
*
281+
*
282282
* @param {Template} t template
283283
* @param {number} buttons buttons (1..2)
284284
*/
@@ -290,7 +290,7 @@ const map = {
290290

291291
/**
292292
* Set title string
293-
*
293+
*
294294
* @param {Template} t template
295295
* @param {String} title title string
296296
*/
@@ -300,7 +300,7 @@ const map = {
300300

301301
/**
302302
* Set message string
303-
*
303+
*
304304
* @param {Template} t template
305305
* @param {String} message message string
306306
*/
@@ -310,7 +310,7 @@ const map = {
310310

311311
/**
312312
* Send collapse_key.
313-
*
313+
*
314314
* @param {Template} template template
315315
* @param {boolean} ck collapseKey of the Content
316316
*/
@@ -322,7 +322,7 @@ const map = {
322322

323323
/**
324324
* Send timeToLive.
325-
*
325+
*
326326
* @param {Template} template template
327327
* @param {boolean} ttl timeToLive of the Content
328328
*/
@@ -334,7 +334,7 @@ const map = {
334334

335335
/**
336336
* Send notification-tap url
337-
*
337+
*
338338
* @param {Template} template template
339339
* @param {string} url on-tap url
340340
*/
@@ -345,7 +345,7 @@ const map = {
345345
/**
346346
* Send media (picture, video, gif, etc) along with the message.
347347
* Sets mutable-content in order for iOS extension to be run.
348-
*
348+
*
349349
* @param {Template} template template
350350
* @param {string} media attached media url
351351
*/
@@ -355,7 +355,7 @@ const map = {
355355

356356
/**
357357
* Sends custom data along with the message
358-
*
358+
*
359359
* @param {Template} template template
360360
* @param {Object} data data to be sent
361361
*/
@@ -365,7 +365,7 @@ const map = {
365365

366366
/**
367367
* Sends user props along with the message
368-
*
368+
*
369369
* @param {Template} template template
370370
* @param {[string]} extras extra user props to be sent
371371
* @param {Object} data personalization
@@ -381,7 +381,7 @@ const map = {
381381

382382
/**
383383
* Sends platform specific fields
384-
*
384+
*
385385
* @param {Template} template template
386386
* @param {object} specific platform specific props to be sent
387387
*/
@@ -417,7 +417,7 @@ const CREDS = {
417417
'fcm': class FCMCreds extends Creds {
418418
/**
419419
* Validation scheme of this class
420-
*
420+
*
421421
* @returns {object} validateArgs scheme
422422
*/
423423
static get scheme() {
@@ -429,7 +429,7 @@ const CREDS = {
429429

430430
/**
431431
* Check credentials for correctness, throw PushError otherwise
432-
*
432+
*
433433
* @throws PushError in case the check fails
434434
* @returns {undefined}
435435
*/
@@ -469,7 +469,7 @@ const CREDS = {
469469

470470
/**
471471
* "View" json, that is some truncated/simplified version of credentials that is "ok" to display
472-
*
472+
*
473473
* @returns {object} json without sensitive information
474474
*/
475475
get view() {

0 commit comments

Comments
 (0)