diff options
author | Simon Bartlett <simon@securitycompass.com> | 2015-05-20 16:24:33 -0400 |
---|---|---|
committer | Simon Bartlett <simon@securitycompass.com> | 2015-05-20 16:24:33 -0400 |
commit | c4aea913411c92014ac45020edf7405db4b79e44 (patch) | |
tree | a8385bc98ded448f8ba428cd7a6f2782cb9fb00c /app/core/files.js | |
parent | 57ff33ef23a1a015baf48e40bc3542c15560aee2 (diff) | |
download | lets-chat-c4aea913411c92014ac45020edf7405db4b79e44.zip lets-chat-c4aea913411c92014ac45020edf7405db4b79e44.tar.gz lets-chat-c4aea913411c92014ac45020edf7405db4b79e44.tar.bz2 |
eslint
Diffstat (limited to 'app/core/files.js')
-rw-r--r-- | app/core/files.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/app/core/files.js b/app/core/files.js index f9ef61d..a51d859 100644 --- a/app/core/files.js +++ b/app/core/files.js @@ -1,12 +1,12 @@ 'use strict'; -var fs = require('fs'), - _ = require('lodash'), +var _ = require('lodash'), mongoose = require('mongoose'), helpers = require('./helpers'), plugins = require('./../plugins'), - settings = require('./../config').files, - enabled = settings.enable; + settings = require('./../config').files; + +var enabled = settings.enable; function FileManager(options) { this.core = options.core; @@ -32,8 +32,8 @@ FileManager.prototype.create = function(options, cb) { } var File = mongoose.model('File'), - Room = mongoose.model('Room'), - User = mongoose.model('User'); + Room = mongoose.model('Room'), + User = mongoose.model('User'); if (settings.restrictTypes && settings.allowedTypes && @@ -63,11 +63,16 @@ FileManager.prototype.create = function(options, cb) { size: options.file.size, room: options.room }).save(function(err, savedFile) { + if (err) { + return cb(err); + } + this.provider.save({file: options.file, doc: savedFile}, function(err) { if (err) { savedFile.remove(); return cb(err); } + // Temporary workaround for _id until populate can do aliasing User.findOne(options.owner, function(err, user) { if (err) { @@ -111,8 +116,7 @@ FileManager.prototype.list = function(options, cb) { maxTake: 5000 }); - var File = mongoose.model('File'), - User = mongoose.model('User'); + var File = mongoose.model('File'); var find = File.find({ room: options.room |