Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to all the exposed REST api methods #1

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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