Skip to content

Commit

Permalink
Merge pull request #46 from VeliovGroup/2.1.3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dr-dimitru authored Aug 25, 2018
2 parents 5f5ae02 + 4b79180 commit e5c1c59
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 25 additions & 10 deletions lib/client/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ Template.afFileUpload.onCreated(function () {
};
}

const mongoCollection = Mongo.Collection.get
? Mongo.Collection.get(this.data.atts.collection)
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection]
// primary method: use dburles:mongo-collection-instances
if (Mongo.Collection.get) {
const mongoCollection = Mongo.Collection.get(this.data.atts.collection);
this.collection = mongoCollection && mongoCollection.filesCollection;
}

// 1. fallback using global scope
if (!this.collection) {
this.collection = global[this.data.atts.collection];
}

// 2. fallback using Meteor.connection / local collections
// if the Meteor release is newer than 2016 -> use _stores
// else use older _mongo_livedata_collections
// see https://github.com/meteor/meteor/pull/5845
if (!this.collection) {
const storedCollection = Meteor.connection._stores[this.data.atts.collection];
this.collection = (storedCollection && storedCollection._getCollection)
? storedCollection._getCollection().filesCollection
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
}

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

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

if (!this.collection) {
throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"');
}

this.collectionName = function () {
return self.data.atts.collection;
};
Expand Down
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package.describe({
name: 'ostrio:autoform-files',
summary: 'File upload for AutoForm using ostrio:files',
description: 'File upload for AutoForm using ostrio:files',
version: '2.1.2',
version: '2.1.3',
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
});

Expand All @@ -17,7 +17,7 @@ Package.onUse(function(api) {
'reactive-var',
'[email protected]',
'aldeed:[email protected]',
'ostrio:[email protected].1'
'ostrio:[email protected].2'
]);

api.addFiles([
Expand Down

0 comments on commit e5c1c59

Please sign in to comment.