Skip to content
Snippets Groups Projects
Commit ea9d0083 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Convert file uploads to model style

parent 244f8f02
No related branches found
No related tags found
No related merge requests found
if UploadFS?
@fileCollection = new Mongo.Collection 'rocketchat_uploads'
fileCollection.allow
RocketChat.models.Uploads.model.allow
insert: (userId, doc) ->
return userId
......@@ -38,7 +37,7 @@ if UploadFS?
cookie.send()
Meteor.fileStore = new UploadFS.store.GridFS
collection: fileCollection
collection: RocketChat.models.Uploads.model
name: 'rocketchat_uploads'
collectionName: 'rocketchat_uploads'
filter: new UploadFS.Filter
......
......@@ -17,8 +17,10 @@ Package.onUse(function(api) {
api.use('tracker');
api.use('ddp-rate-limiter');
api.use('underscore');
api.use('mongo');
api.use('underscorestring:underscore.string');
api.use('monbro:mongodb-mapreduce-aggregation@1.0.1');
api.use('matb33:collection-hooks');
api.use('service-configuration');
api.use('check');
api.use('arunoda:streams');
......@@ -48,6 +50,7 @@ Package.onUse(function(api) {
api.addFiles('server/models/Rooms.coffee', 'server');
api.addFiles('server/models/Settings.coffee', 'server');
api.addFiles('server/models/Subscriptions.coffee', 'server');
api.addFiles('server/models/Uploads.coffee', 'server');
api.addFiles('server/models/Users.coffee', 'server');
// SERVER PUBLICATIONS
......
RocketChat.models.Uploads = new class extends RocketChat.models._Base
constructor: ->
@_initModel 'uploads'
@tryEnsureIndex { 'rid': 1 }
@tryEnsureIndex { 'uploadedAt': 1 }
......@@ -5,7 +5,7 @@ RocketChat.models._Base = class
_initModel: (name) ->
check name, String
@model = new Meteor.Collection @_baseName() + name
@model = new Mongo.Collection @_baseName() + name
find: ->
return @model.find.apply @model, arguments
......
......@@ -25,14 +25,14 @@ Meteor.methods
RocketChat.models.Messages.setHiddenById originalMessage._id, true
if originalMessage.file?._id?
fileCollection.update originalMessage.file._id, {$set: {_hidden: true}}
RocketChat.models.Uploads.update originalMessage.file._id, {$set: {_hidden: true}}
else
if not showDeletedStatus
RocketChat.models.Messages.removeById originalMessage._id
if originalMessage.file?._id?
fileCollection.remove originalMessage.file._id
RocketChat.models.Uploads.remove originalMessage.file._id
Meteor.fileStore.delete originalMessage.file._id
if showDeletedStatus
......
......@@ -22,7 +22,7 @@ Meteor.publish 'roomFiles', (rid, limit = 50) ->
type: 1
url: 1
cursorFileListHandle = fileCollection.find(fileQuery, fileOptions).observeChanges
cursorFileListHandle = RocketChat.models.Uploads.find(fileQuery, fileOptions).observeChanges
added: (_id, record) ->
pub.added('room_files', _id, record)
......
......@@ -7,7 +7,7 @@ RocketChat.Migrations.add
oldGridFSCollection = new Meteor.Collection 'cfs_gridfs.files.files'
oldChunkCollection = new Meteor.Collection 'cfs_gridfs.files.chunks'
newFilesCollection = fileCollection
newFilesCollection = RocketChat.models.Uploads
newGridFSCollection = new Meteor.Collection 'rocketchat_uploads.files'
newChunkCollection = new Meteor.Collection 'rocketchat_uploads.chunks'
......
......@@ -20,7 +20,7 @@ RocketChat.Migrations.add
return unless cursorFileMessages.count()
_.each( cursorFileMessages.fetch(), (msg) ->
fileCollection.update({ _id: msg?.file?._id }, { $set: { rid: msg.rid } }, { $multi: true })
RocketChat.models.Uploads.update({ _id: msg?.file?._id }, { $set: { rid: msg.rid } }, { $multi: true })
)
console.log 'Updated rocketchat_uploads documents to include the room Id in which they were sent.'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment