From 51e23dccb21bb2359877c8a7e7422421e61b6be7 Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Tippa Date: Fri, 1 Sep 2017 17:03:58 +0530 Subject: [PATCH] Added options to all the exposed REST api methods --- lib/index.js | 60 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index cefce38..5d53f5f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -62,7 +62,11 @@ MongoStorage = (function() { } }; - MongoStorage.prototype.getContainers = function(callback) { + MongoStorage.prototype.getContainers = function(options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } return this.db.collection('fs.files').find({ 'metadata.mongo-storage': true }).toArray(function(err, files) { @@ -79,7 +83,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.getContainer = function(name, callback) { + MongoStorage.prototype.getContainer = function(name, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } return this.db.collection('fs.files').find({ 'metadata.mongo-storage': true, 'metadata.container': name @@ -94,7 +102,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.destroyContainer = function(name, callback) { + MongoStorage.prototype.destroyContainer = function(name, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var self; self = this; return self.getFiles(name, function(err, files) { @@ -107,7 +119,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.upload = function(container, req, res, callback) { + MongoStorage.prototype.upload = function(container, req, res, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var busboy, promises, self; self = this; busboy = new Busboy({ @@ -158,14 +174,22 @@ MongoStorage = (function() { return file.pipe(stream); }; - MongoStorage.prototype.getFiles = function(container, callback) { + MongoStorage.prototype.getFiles = function(container, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } return this.db.collection('fs.files').find({ 'metadata.mongo-storage': true, 'metadata.container': container }).toArray(callback); }; - MongoStorage.prototype.removeFile = function(container, filename, callback) { + MongoStorage.prototype.removeFile = function(container, filename, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var self; self = this; return self.getFile(container, filename, function(err, file) { @@ -176,7 +200,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.removeFileById = function(id, callback) { + MongoStorage.prototype.removeFileById = function(id, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var self; self = this; return async.parallel([ @@ -206,7 +234,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.getFile = function(container, filename, callback) { + MongoStorage.prototype.getFile = function(container, filename, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } return this.__getFile({ 'metadata.mongo-storage': true, 'metadata.container': container, @@ -235,7 +267,11 @@ MongoStorage = (function() { return read.pipe(res); }; - MongoStorage.prototype.downloadById = function(id, res, callback) { + MongoStorage.prototype.downloadById = function(id, res, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var self; if (callback == null) { callback = (function() {}); @@ -249,7 +285,11 @@ MongoStorage = (function() { }); }; - MongoStorage.prototype.download = function(container, filename, res, callback) { + MongoStorage.prototype.download = function(container, filename, res, options, callback) { + if (callback === undefined && typeof options === 'function') { + callback = options; + options = undefined; + } var self; if (callback == null) { callback = (function() {});