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

Init implementation of jalik ufs for upload

parent 45a40052
No related branches found
No related tags found
No related merge requests found
...@@ -80,3 +80,5 @@ yasaricli:slugify ...@@ -80,3 +80,5 @@ yasaricli:slugify
yasinuslu:blaze-meta yasinuslu:blaze-meta
rocketchat:colors rocketchat:colors
raix:push@2.6.13-rc.1 raix:push@2.6.13-rc.1
jalik:ufs
jalik:ufs-gridfs
...@@ -51,6 +51,8 @@ html-tools@1.0.4 ...@@ -51,6 +51,8 @@ html-tools@1.0.4
htmljs@1.0.4 htmljs@1.0.4
http@1.1.0 http@1.1.0
id-map@1.0.3 id-map@1.0.3
jalik:ufs@0.2.5
jalik:ufs-gridfs@0.1.0
jparker:crypto-core@0.1.0 jparker:crypto-core@0.1.0
jparker:crypto-md5@0.1.1 jparker:crypto-md5@0.1.1
jparker:gravatar@0.3.1 jparker:gravatar@0.3.1
......
readAsDataURL = (file, callback) ->
reader = new FileReader()
reader.onload = (ev) ->
callback ev.target.result, file
reader.readAsDataURL file
readAsArrayBuffer = (file, callback) ->
reader = new FileReader()
reader.onload = (ev) ->
callback ev.target.result, file
reader.readAsArrayBuffer file
@fileUpload = (files) -> @fileUpload = (files) ->
files = [].concat files files = [].concat files
...@@ -7,10 +22,7 @@ ...@@ -7,10 +22,7 @@
swal.close() swal.close()
return return
reader = new FileReader() readAsDataURL file.file, (fileContent) ->
reader.onload = (event) ->
fileContent = event.target.result
text = '' text = ''
if file.type is 'audio' if file.type is 'audio'
...@@ -44,16 +56,64 @@ ...@@ -44,16 +56,64 @@
if isConfirm isnt true if isConfirm isnt true
return return
newFile = new (FS.File)(file.file) readAsArrayBuffer file.file, (data) ->
if file.name? # // Prepare the file to insert in database, note that we don't provide an URL,
newFile.name(file.name) # // it will be set automatically by the uploader when file transfer is complete.
newFile.rid = Session.get('openedRoom') record =
newFile.recId = Random.id() name: file.name or file.file.name
newFile.userId = Meteor.userId() size: file.file.size
Files.insert newFile, (error, fileObj) -> type: file.file.type
unless error
toastr.success 'Upload succeeded!' # // Create a new Uploader for this file
upload = new UploadFS.Uploader
reader.readAsDataURL(file.file) # // This is where the uploader will save the file
store: Meteor.fileStore
# // The file data
data: data
# // The document to save in the collection
file: record
# // The error callback
onError: (err) ->
console.error(err)
# // The complete callback
onComplete: (file) ->
console.log('transfer complete', arguments)
toastr.success 'Upload succeeded!'
Meteor.call 'sendMessage',
_id: Random.id()
rid: Session.get('openedRoom')
msg: """
File Uploaded: *#{file.name}*
#{file.url}
"""
file:
_id: file._id
# // Reactive method to get upload progress
Tracker.autorun ->
console.log((upload.getProgress() * 100) + '% completed')
# // Reactive method to get upload status
Tracker.autorun ->
console.log('transfer ' + (upload.isUploading() ? 'started' : 'stopped'))
# // Starts the upload
upload.start();
# // Stops the upload
# upload.stop();
# // Abort the upload
# upload.abort();
# newFile = new (FS.File)(file.file)
# if file.name?
# newFile.name(file.name)
# newFile.rid = Session.get('openedRoom')
# newFile.recId = Random.id()
# newFile.userId = Meteor.userId()
# Files.insert newFile, (error, fileObj) ->
# unless error
# toastr.success 'Upload succeeded!'
consume() consume()
\ No newline at end of file
if FS? if UploadFS?
fileCollection = new Mongo.Collection 'files'
@fileStore = new FS.Store.GridFS 'files' fileCollection.allow
insert: (userId, doc) ->
return userId
fileStore.on 'stored', Meteor.bindEnvironment (storeName, fileObj) -> update: (userId, doc) ->
Meteor.runAsUser fileObj.userId, -> return userId is doc.userId
if not ChatMessage.findOne(fileObj.recId)?
Meteor.call 'sendMessage',
_id: fileObj.recId
rid: fileObj.rid
msg: """
File Uploaded: *#{fileObj.original.name}*
#{Meteor.absoluteUrl()}cfs/files/Files/#{fileObj._id}
"""
file:
_id: fileObj._id
, {upsert: true}
@Files = new FS.Collection 'Files', remove: (userId, doc) ->
stores: [fileStore], return userId is doc.userId
filter:
maxSize: 2097152,
allow:
contentTypes: ['image/*', 'audio/*']
onInvalid: (message) ->
if Meteor.isClient
toastr.error message
else
console.log message
return
# Allow rules Meteor.fileStore = new UploadFS.store.GridFS
Files.allow collection: fileCollection
insert: -> name: 'files'
true filter: new UploadFS.Filter
update: -> maxSize: 2097152
false contentTypes: ['image/*', 'audio/*']
download: -> onFinishUpload: ->
true console.log arguments
remove: ->
false
Files.deny
insert: ->
false
update: ->
true
remove: ->
true
download: ->
false
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