Skip to content

Commit 6f94319

Browse files
authored
Merge pull request veliovgroup#257 from panter/master
Template is now a weak depencency
2 parents dd59d88 + 6346a3d commit 6f94319

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

files.coffee

+19-19
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ class FilesCollection
585585
sp = storagePath
586586
else if _.isFunction storagePath
587587
sp = storagePath.call self, "assets#{nodePath.sep}app#{nodePath.sep}uploads#{nodePath.sep}#{self.collectionName}"
588-
588+
589589
unless _.isString sp
590590
throw new Meteor.Error 400, "[FilesCollection.#{self.collectionName}] \"storagePath\" function must return a String!"
591591

@@ -673,7 +673,7 @@ class FilesCollection
673673
userId:
674674
type: String
675675
optional: true
676-
updatedAt:
676+
updatedAt:
677677
type: Date
678678
optional: true
679679
versions:
@@ -813,7 +813,7 @@ class FilesCollection
813813

814814
uris = uri.split '/'
815815
if uris.length is 3
816-
params =
816+
params =
817817
query: if request._parsedUrl.query then JSON.parse('{"' + decodeURI(request._parsedUrl.query).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}') else {}
818818
_id: uris[0]
819819
version: uris[1]
@@ -840,7 +840,7 @@ class FilesCollection
840840
version = 'original'
841841
_file = _file.split('?')[0]
842842

843-
params =
843+
params =
844844
query: if request._parsedUrl.query then JSON.parse('{"' + decodeURI(request._parsedUrl.query).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}') else {}
845845
file: _file
846846
_id: _file.split('.')[0]
@@ -862,7 +862,7 @@ class FilesCollection
862862
_methods[self._methodNames._Remove] = (selector) ->
863863
check selector, Match.OneOf String, Object
864864
console.info "[FilesCollection] [Unlink Method] [.remove(#{selector})]" if self.debug
865-
865+
866866
if self.allowClientCode
867867
if self.onBeforeRemove and _.isFunction self.onBeforeRemove
868868
user = false
@@ -882,7 +882,7 @@ class FilesCollection
882882

883883

884884
# Method used to receive "first byte" of upload
885-
# and all file's meta-data, so
885+
# and all file's meta-data, so
886886
# it won't be transferred with every chunk
887887
# Basically it prepares everything
888888
# So user can pause/disconnect and
@@ -1087,7 +1087,7 @@ class FilesCollection
10871087
{mime, ext} = fileType buf
10881088
catch error
10891089
if not mime or not _.isString mime
1090-
mime = 'application/octet-stream'
1090+
mime = 'application/octet-stream'
10911091
return mime
10921092

10931093
###
@@ -1113,16 +1113,16 @@ class FilesCollection
11131113
@returns {Object}
11141114
###
11151115
_getUser: (http) ->
1116-
result =
1116+
result =
11171117
user: -> return null
11181118
userId: null
1119-
1119+
11201120
if Meteor.isServer
11211121
if http
11221122
mtok = null
11231123
if http.request.headers['x-mtok']
11241124
mtok = http.request.headers['x-mtok']
1125-
else
1125+
else
11261126
cookie = http.request.Cookies
11271127
if cookie.has 'x_mtok'
11281128
mtok = cookie.get 'x_mtok'
@@ -1298,7 +1298,7 @@ class FilesCollection
12981298
FSName = if @namingFunction then @namingFunction() else fileId
12991299
pathParts = url.split('/')
13001300
fileName = if (opts.name or opts.fileName) then (opts.name or opts.fileName) else pathParts[pathParts.length - 1] or FSName
1301-
1301+
13021302
{extension, extensionWithDot} = @_getExt fileName
13031303
opts.meta ?= {}
13041304
opts.path = "#{@storagePath}#{nodePath.sep}#{FSName}#{extensionWithDot}"
@@ -1776,7 +1776,7 @@ class FilesCollection
17761776

17771777
else if FileReaderSync
17781778
fileReader = new FileReaderSync
1779-
1779+
17801780
self.emitEvent 'sendChunk', [{
17811781
data: {
17821782
bin: fileReader.readAsDataURL(chunk).split(',')[1]
@@ -1787,7 +1787,7 @@ class FilesCollection
17871787
self.emitEvent 'end', ['File API is not supported in this Browser!']
17881788
return
17891789

1790-
upload: ->
1790+
upload: ->
17911791
if @result.onPause.get()
17921792
return
17931793

@@ -1870,13 +1870,13 @@ class FilesCollection
18701870
opts.file.meta = fixJSONStringify opts.file.meta if opts.file?.meta
18711871
HTTP.call 'POST', "#{@collection.downloadRoute}/#{@collection.collectionName}/__upload", {
18721872
data: opts
1873-
headers:
1873+
headers:
18741874
'x-start': '1'
18751875
'x-mtok': Meteor.connection?._lastSessionId or null
18761876
}, handleStart
18771877
return
18781878

1879-
pipe: (func) ->
1879+
pipe: (func) ->
18801880
@pipes.push func
18811881
return @
18821882

@@ -2028,7 +2028,7 @@ class FilesCollection
20282028
files.forEach (file) ->
20292029
self.unlink file
20302030
return
2031-
2031+
20322032
if @onAfterRemove
20332033
self = @
20342034
docs = files.fetch()
@@ -2310,7 +2310,7 @@ class FilesCollection
23102310
http.response.setHeader 'Content-Range', "bytes #{reqRange.start}-#{reqRange.end}/#{vRef.size}"
23112311
stream = readableStream or fs.createReadStream vRef.path, {start: reqRange.start, end: reqRange.end}
23122312
http.response.writeHead 206 if readableStream
2313-
stream.on('open', ->
2313+
stream.on('open', ->
23142314
http.response.writeHead 206
23152315
return
23162316
).on('error', streamErrorHandler
@@ -2364,7 +2364,7 @@ formatFleURL = (fileRef, version = 'original') ->
23642364
else
23652365
return root + "#{fileRef._downloadRoute}/#{fileRef._collectionName}/#{fileRef._id}/#{version}/#{fileRef._id}#{ext}"
23662366

2367-
if Meteor.isClient
2367+
if Meteor.isClient and Template?
23682368
###
23692369
@locus Client
23702370
@TemplateHelper
@@ -2387,4 +2387,4 @@ if Meteor.isClient
23872387
Export the FilesCollection class
23882388
###
23892389
Meteor.Files = FilesCollection
2390-
`export { FilesCollection }`
2390+
`export { FilesCollection }`

package.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Package.describe({
99
Package.onUse(function(api) {
1010
api.versionsFrom('1.4');
1111
api.use('webapp', 'server');
12-
api.use(['templating', 'reactive-var', 'tracker', 'http'], 'client');
12+
api.use(['templating'], 'client', {weak: true});
13+
api.use(['reactive-var', 'tracker', 'http'], 'client');
1314
api.use(['mongo','underscore', 'check', 'random', 'coffeescript', 'ecmascript', 'ostrio:cookies@2.0.5'], ['client', 'server']);
1415
api.addFiles('event-emitter.jsx', 'client');
1516
api.addAssets('worker.min.js', 'client');
@@ -22,4 +23,4 @@ Npm.depends({
2223
'request': '2.74.0',
2324
'throttle': '1.0.3',
2425
'file-type': '3.8.0'
25-
});
26+
});

0 commit comments

Comments
 (0)