@@ -121,6 +121,7 @@ countlyFs.gridfs = {};
121
121
* });
122
122
*/
123
123
ob . getId = function ( category , filename , callback ) {
124
+ log . d ( "getId" , category , filename ) ;
124
125
db . collection ( category + ".files" ) . findOne ( { filename : filename } , { _id : 1 } , function ( err , res ) {
125
126
if ( callback ) {
126
127
callback ( err , ( res && res . _id ) ? res . _id : false ) ;
@@ -149,6 +150,7 @@ countlyFs.gridfs = {};
149
150
if ( ! options ) {
150
151
options = { } ;
151
152
}
153
+ log . d ( "exists" , category , dest , options ) ;
152
154
var query = { } ;
153
155
if ( options . id ) {
154
156
query . _id = options . id ;
@@ -189,7 +191,7 @@ countlyFs.gridfs = {};
189
191
if ( ! options ) {
190
192
options = { } ;
191
193
}
192
-
194
+ log . d ( "saveFile" , category , dest , source , options ) ;
193
195
var filename = dest . split ( path . sep ) . pop ( ) ;
194
196
beforeSave ( category , filename , options , callback , function ( ) {
195
197
save ( category , filename , fs . createReadStream ( source ) , options , callback ) ;
@@ -223,6 +225,7 @@ countlyFs.gridfs = {};
223
225
if ( ! options ) {
224
226
options = { } ;
225
227
}
228
+ log . d ( "saveData" , category , dest , typeof data , options ) ;
226
229
beforeSave ( category , filename , options , callback , function ( ) {
227
230
var readStream = new Readable ;
228
231
readStream . push ( data ) ;
@@ -258,6 +261,7 @@ countlyFs.gridfs = {};
258
261
if ( ! options ) {
259
262
options = { } ;
260
263
}
264
+ log . d ( "saveStream" , category , dest , typeof readStream , options ) ;
261
265
beforeSave ( category , filename , options , callback , function ( ) {
262
266
save ( category , filename , readStream , options , callback ) ;
263
267
} ) ;
@@ -286,7 +290,7 @@ countlyFs.gridfs = {};
286
290
if ( ! options ) {
287
291
options = { } ;
288
292
}
289
-
293
+ log . d ( "rename" , category , dest , source , options ) ;
290
294
if ( options . id ) {
291
295
let bucket = new GridFSBucket ( db , { bucketName : category } ) ;
292
296
let errHandle = null ;
@@ -352,7 +356,7 @@ countlyFs.gridfs = {};
352
356
if ( ! options ) {
353
357
options = { } ;
354
358
}
355
-
359
+ log . d ( "deleteFile" , category , dest , options ) ;
356
360
if ( options . id ) {
357
361
ob . deleteFileById ( category , options . id , callback ) ;
358
362
}
@@ -388,6 +392,7 @@ countlyFs.gridfs = {};
388
392
* });
389
393
*/
390
394
ob . deleteAll = async function ( category , dest , callback ) {
395
+ log . d ( "deleteAll" , category , dest ) ;
391
396
var bucket = new GridFSBucket ( db , { bucketName : category } ) ;
392
397
let errHandle = null ;
393
398
try {
@@ -423,7 +428,7 @@ countlyFs.gridfs = {};
423
428
if ( ! options ) {
424
429
options = { } ;
425
430
}
426
-
431
+ log . d ( "getStream" , category , dest , options ) ;
427
432
if ( callback ) {
428
433
if ( options . id ) {
429
434
ob . getStreamById ( category , options . id , callback ) ;
@@ -456,7 +461,7 @@ countlyFs.gridfs = {};
456
461
if ( ! options ) {
457
462
options = { } ;
458
463
}
459
-
464
+ log . d ( "getData" , category , dest , options ) ;
460
465
if ( options . id ) {
461
466
ob . getDataById ( category , options . id , callback ) ;
462
467
}
@@ -502,7 +507,7 @@ countlyFs.gridfs = {};
502
507
if ( ! options ) {
503
508
options = { } ;
504
509
}
505
-
510
+ log . d ( "getSize" , category , dest , options ) ;
506
511
var query = { } ;
507
512
if ( options . id ) {
508
513
query . _id = options . id ;
@@ -537,7 +542,7 @@ countlyFs.gridfs = {};
537
542
if ( ! options ) {
538
543
options = { } ;
539
544
}
540
-
545
+ log . d ( "getStats" , category , dest , options ) ;
541
546
var query = { } ;
542
547
if ( options . id ) {
543
548
query . _id = options . id ;
@@ -574,6 +579,7 @@ countlyFs.gridfs = {};
574
579
* });
575
580
*/
576
581
ob . getDataById = function ( category , id , callback ) {
582
+ log . d ( "getDataById" , category , id ) ;
577
583
var bucket = new GridFSBucket ( db , { bucketName : category } ) ;
578
584
var downloadStream = bucket . openDownloadStream ( id ) ;
579
585
downloadStream . on ( 'error' , function ( error ) {
@@ -605,6 +611,7 @@ countlyFs.gridfs = {};
605
611
* });
606
612
*/
607
613
ob . getStreamById = function ( category , id , callback ) {
614
+ log . d ( "getStreamById" , category , id ) ;
608
615
if ( callback ) {
609
616
var bucket = new GridFSBucket ( db , { bucketName : category } ) ;
610
617
callback ( null , bucket . openDownloadStream ( id ) ) ;
@@ -622,6 +629,7 @@ countlyFs.gridfs = {};
622
629
* });
623
630
*/
624
631
ob . deleteFileById = async function ( category , id , callback ) {
632
+ log . d ( "deleteFileById" , category , id ) ;
625
633
var bucket = new GridFSBucket ( db , { bucketName : category } ) ;
626
634
let errHandle = null ;
627
635
try {
@@ -646,6 +654,7 @@ countlyFs.gridfs = {};
646
654
* });
647
655
*/
648
656
ob . clearFile = function ( category , filename , callback ) {
657
+ log . d ( "clearFile" , category , filename ) ;
649
658
db . collection ( category + ".files" ) . deleteMany ( { filename : filename } , function ( err1 , res1 ) {
650
659
log . d ( "deleting files" , category , { filename : filename } , err1 , res1 && res1 . result ) ;
651
660
db . collection ( category + ".chunks" ) . deleteMany ( { files_id : filename } , function ( err2 , res2 ) {
@@ -662,6 +671,7 @@ countlyFs.gridfs = {};
662
671
* @param {function } callback - function called when files found or query errored, providing error object as first param and a list of filename, creation date and size as secondas second
663
672
*/
664
673
ob . listFiles = function ( category , callback ) {
674
+ log . d ( "listFiles" , category ) ;
665
675
const bucket = new GridFSBucket ( db , { bucketName : category } ) ;
666
676
bucket . find ( ) . toArray ( )
667
677
. then ( ( records ) => callback (
0 commit comments