diff options
author | Simon Bartlett <simon@securitycompass.com> | 2015-02-05 17:39:18 -0500 |
---|---|---|
committer | Simon Bartlett <simon@securitycompass.com> | 2015-02-05 17:39:18 -0500 |
commit | bf82a166ca704ca93214d235a8a9fc10a4eb37b4 (patch) | |
tree | 5362a688bb6345100d97dadc523e5e55d91f2d2f /app/core/files.js | |
parent | 5bac04dd0dbba1c1a497fcb9395fb094e4768a62 (diff) | |
download | lets-chat-bf82a166ca704ca93214d235a8a9fc10a4eb37b4.zip lets-chat-bf82a166ca704ca93214d235a8a9fc10a4eb37b4.tar.gz lets-chat-bf82a166ca704ca93214d235a8a9fc10a4eb37b4.tar.bz2 |
API update
Diffstat (limited to 'app/core/files.js')
-rw-r--r-- | app/core/files.js | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/app/core/files.js b/app/core/files.js index 3be62ab..0d28ce3 100644 --- a/app/core/files.js +++ b/app/core/files.js @@ -3,6 +3,7 @@ var fs = require('fs'), _ = require('lodash'), mongoose = require('mongoose'), + helpers = require('./helpers'), settings = require('./../config').files, enabled = settings.enable, provider = _.find([ @@ -69,6 +70,14 @@ FileManager.prototype.create = function(options, cb) { FileManager.prototype.list = function(options, cb) { options = options || {}; + options = helpers.sanitizeQuery(options, { + defaults: { + reverse: true, + take: 500 + }, + maxTake: 5000 + }); + var File = mongoose.model('File'), User = mongoose.model('User'); @@ -86,8 +95,8 @@ FileManager.prototype.list = function(options, cb) { find.where('uploaded').lte(options.to); } - if (options.include && _.isArray(options.include)) { - var includes = options.include.split(','); + if (options.expand && _.isArray(options.include)) { + var includes = options.expand.split(','); if (_.includes(includes, 'owner')) { find.populate('owner', 'id username displayName email avatar'); @@ -98,15 +107,14 @@ FileManager.prototype.list = function(options, cb) { find.skip(options.skip); } - if (options.sort) { - var sort = options.sort.replace(',', ' '); - find.sort(sort); - } else { + if (options.reverse) { find.sort({ 'uploaded': -1 }); + } else { + find.sort({ 'uploaded': 1 }); } find - .limit(options.limit || 500) + .limit(options.limit) .exec(function(err, files) { if (err) { console.error(err); |