Skip to content

Commit e5c1c59

Browse files
authored
Merge pull request #46 from VeliovGroup/2.1.3
v2.1.3 - Attempting to fix #45, thanks to @jankapunkt , @marcoschwartz , and @anjunatic - Adding several fallbacks to get collection by name - Improved error message and details
2 parents 5f5ae02 + 4b79180 commit e5c1c59

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/client/fileUpload.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,32 @@ Template.afFileUpload.onCreated(function () {
2222
};
2323
}
2424

25-
const mongoCollection = Mongo.Collection.get
26-
? Mongo.Collection.get(this.data.atts.collection)
27-
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection]
25+
// primary method: use dburles:mongo-collection-instances
26+
if (Mongo.Collection.get) {
27+
const mongoCollection = Mongo.Collection.get(this.data.atts.collection);
28+
this.collection = mongoCollection && mongoCollection.filesCollection;
29+
}
30+
31+
// 1. fallback using global scope
32+
if (!this.collection) {
33+
this.collection = global[this.data.atts.collection];
34+
}
35+
36+
// 2. fallback using Meteor.connection / local collections
37+
// if the Meteor release is newer than 2016 -> use _stores
38+
// else use older _mongo_livedata_collections
39+
// see https://github.com/meteor/meteor/pull/5845
40+
if (!this.collection) {
41+
const storedCollection = Meteor.connection._stores[this.data.atts.collection];
42+
this.collection = (storedCollection && storedCollection._getCollection)
43+
? storedCollection._getCollection().filesCollection
44+
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
45+
}
2846

29-
this.collection = mongoCollection
30-
? mongoCollection.filesCollection
31-
: global[this.data.atts.collection]
47+
if (!this.collection) {
48+
throw new Meteor.Error(404, `[meteor-autoform-files] No collection found by name "${this.data.atts.collection}"`,
49+
`Collection's name is case-sensetive. Please, make sure you're using right collection name.`);
50+
}
3251

3352
this.uploadTemplate = this.data.atts.uploadTemplate || null;
3453
this.previewTemplate = this.data.atts.previewTemplate || null;
@@ -43,10 +62,6 @@ Template.afFileUpload.onCreated(function () {
4362
this.insertConfig.chunkSize = parseInt(this.insertConfig.chunkSize);
4463
}
4564

46-
if (!this.collection) {
47-
throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"');
48-
}
49-
5065
this.collectionName = function () {
5166
return self.data.atts.collection;
5267
};

package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: 'ostrio:autoform-files',
33
summary: 'File upload for AutoForm using ostrio:files',
44
description: 'File upload for AutoForm using ostrio:files',
5-
version: '2.1.2',
5+
version: '2.1.3',
66
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
77
});
88

@@ -17,7 +17,7 @@ Package.onUse(function(api) {
1717
'reactive-var',
1818
1919
20-
'ostrio:[email protected].1'
20+
'ostrio:[email protected].2'
2121
]);
2222

2323
api.addFiles([

0 commit comments

Comments
 (0)