Skip to content

Commit

Permalink
Merge pull request #334 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.7.8
  • Loading branch information
dr-dimitru authored Jan 24, 2017
2 parents bf651c6 + d113e11 commit bb22a88
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ [email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:[email protected].7
ostrio:[email protected].8
[email protected]
[email protected]
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Demo application:

Related Packages:
========
- [pyfiles (meteor-python-files))](https://github.com/VeliovGroup/meteor-python-files) Python Client for Meteor-Files package
- [pyfiles (meteor-python-files)](https://github.com/VeliovGroup/meteor-python-files) Python Client for Meteor-Files package
- [meteor-autoform-file](https://github.com/VeliovGroup/meteor-autoform-file) - Upload and manage files with [autoForm](https://github.com/aldeed/meteor-autoform)


Expand Down
69 changes: 34 additions & 35 deletions files.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ class FilesCollection
setTokenCookie = ->
Meteor.setTimeout ->
if (not cookie.has('x_mtok') and Meteor.connection._lastSessionId) or (cookie.has('x_mtok') and (cookie.get('x_mtok') isnt Meteor.connection._lastSessionId))
cookie.set 'x_mtok', Meteor.connection._lastSessionId
cookie.set 'x_mtok', Meteor.connection._lastSessionId, path: '/'
return
, 25
return

unsetTokenCookie = ->
cookie.remove 'x_mtok' if cookie.has 'x_mtok'
cookie.remove('x_mtok', '/') if cookie.has 'x_mtok'
return

if Accounts?
Expand Down Expand Up @@ -641,21 +641,31 @@ class FilesCollection

@_preCollection = new Mongo.Collection '__pre_' + @collectionName
@_preCollection._ensureIndex {createdAt: 1}, {expireAfterSeconds: @continueUploadTTL, background: true}
_preCollectionCursor = @_preCollection.find {}
_preCollectionCursor.observe removed: (doc) ->
# Free memory after upload is done
# Or if upload is unfinished
console.info "[FilesCollection] [_preCollectionCursor.observe] [removed]: #{doc._id}" if self.debug
if self._currentUploads?[doc._id]
self._currentUploads[doc._id].stop()
self._currentUploads[doc._id].end()

unless doc.isFinished
console.info "[FilesCollection] [_preCollectionCursor.observe] [removeUnfinishedUpload]: #{doc.file.path}" if self.debug
self._currentUploads[doc._id].abort()

delete self._currentUploads[doc._id]
return
_preCollectionCursor = @_preCollection.find {}, {
fields:
_id: 1
isFinished: 1
}
_preCollectionCursor.observe
changed: (doc) ->
if doc.isFinished
console.info "[FilesCollection] [_preCollectionCursor.observe] [changed]: #{doc._id}" if self.debug
self._preCollection.remove {_id: doc._id}, NOOP
return
removed: (doc) ->
# Free memory after upload is done
# Or if upload is unfinished
console.info "[FilesCollection] [_preCollectionCursor.observe] [removed]: #{doc._id}" if self.debug
if self._currentUploads?[doc._id]
self._currentUploads[doc._id].stop()
self._currentUploads[doc._id].end()

unless doc.isFinished
console.info "[FilesCollection] [_preCollectionCursor.observe] [removeUnfinishedUpload]: #{doc.file.path}" if self.debug
self._currentUploads[doc._id].abort()

delete self._currentUploads[doc._id]
return

@_createStream = (_id, path, opts) ->
return self._currentUploads[_id] = new writeStream path, opts.fileLength, opts, self.permissions
Expand Down Expand Up @@ -1076,24 +1086,13 @@ class FilesCollection
console.error '[FilesCollection] [Upload] [_finishUpload] Error:', error if self.debug
else
self._preCollection.update {_id: opts.fileId}, {$set: {isFinished: true}}
# we delay the remove to resolve timing issues (details see #324)
Meteor.setTimeout ->
self._preCollection.remove {_id: opts.fileId}, (error) ->
if error
cb and cb error
console.error '[FilesCollection] [Upload] [_finishUpload] Error:', error if self.debug
else
result._id = _id
console.info "[FilesCollection] [Upload] [finish(ed)Upload] -> #{result.path}" if self.debug
self.onAfterUpload and self.onAfterUpload.call self, result
self.emit 'afterUpload', result
cb and cb null, result
return # .remove
return # .setTimeout
, 25

return # .insert
return # .isServer
result._id = _id
console.info "[FilesCollection] [Upload] [finish(ed)Upload] -> #{result.path}" if self.debug
self.onAfterUpload and self.onAfterUpload.call self, result
self.emit 'afterUpload', result
cb and cb null, result
return
return
else undefined

###
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:files',
version: '1.7.7',
version: '1.7.8',
summary: 'Upload files via DDP, HTTP and WebRTC/DC. To server FS, AWS, GridFS, DropBox or Google Drive.',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
Expand Down

0 comments on commit bb22a88

Please sign in to comment.