Skip to content

Commit

Permalink
Merge pull request #1 from pktippa/master
Browse files Browse the repository at this point in the history
Added options to all the exposed REST api methods
  • Loading branch information
raghav135 authored Sep 1, 2017
2 parents e213aa4 + 51e23dc commit 8694d89
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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({
Expand Down Expand Up @@ -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) {
Expand All @@ -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([
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {});
Expand All @@ -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() {});
Expand Down

0 comments on commit 8694d89

Please sign in to comment.