|
|
|
|
@ -31,6 +31,12 @@ if UploadFS? |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
initFileStore = -> |
|
|
|
|
cookie = new Cookies() |
|
|
|
|
if Meteor.isClient |
|
|
|
|
cookie.set 'rc_uid', Meteor.userId(); |
|
|
|
|
cookie.set 'rc_token', Meteor._localStorage.getItem('Meteor.loginToken') |
|
|
|
|
cookie.send() |
|
|
|
|
|
|
|
|
|
Meteor.fileStore = new UploadFS.store.GridFS |
|
|
|
|
collection: fileCollection |
|
|
|
|
name: 'rocketchat_uploads' |
|
|
|
|
@ -41,12 +47,21 @@ if UploadFS? |
|
|
|
|
onFinishUpload: -> |
|
|
|
|
console.log arguments |
|
|
|
|
onRead: (fileId, file, req, res) -> |
|
|
|
|
if RocketChat.settings.get 'FileUpload_ProtectFiles' |
|
|
|
|
rawCookies = req.headers.cookie if req?.headers?.cookie? |
|
|
|
|
uid = cookie.get('rc_uid', rawCookies) if rawCookies? |
|
|
|
|
token = cookie.get('rc_token', rawCookies) if rawCookies? |
|
|
|
|
|
|
|
|
|
unless uid and token and RocketChat.models.Users.findOneByIdAndLoginToken(uid, token) |
|
|
|
|
throw new Meteor.Error 403, 'Not Allowed' |
|
|
|
|
|
|
|
|
|
res.setHeader 'content-disposition', "attachment; filename=\"#{ encodeURIComponent(file.name) }\"" |
|
|
|
|
|
|
|
|
|
Meteor.startup -> |
|
|
|
|
if Meteor.isServer |
|
|
|
|
initFileStore() |
|
|
|
|
else |
|
|
|
|
Tracker.autorun (c) -> |
|
|
|
|
if RocketChat.settings.subscription.ready() |
|
|
|
|
if Meteor.userId() and RocketChat.settings.subscription.ready() |
|
|
|
|
initFileStore() |
|
|
|
|
c.stop() |
|
|
|
|
|