Skip to content

Commit

Permalink
Merge pull request #468 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.8.2
  • Loading branch information
dr-dimitru authored Jul 30, 2017
2 parents 90cfbc2 + ca71a52 commit c800703
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ npm-mongo@2.2.24
observe-sequence@1.0.16
ordered-dict@1.0.9
ostrio:cookies@2.2.2
ostrio:files@1.8.1
ostrio:files@1.8.2
promise@0.8.9
random@1.0.10
reactive-var@1.0.11
Expand Down
1 change: 1 addition & 0 deletions client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FilesCollection
throw new Meteor.Error 500, "[FilesCollection.#{@collectionName}]: \"downloadRoute\" must be precisely provided on \"public\" collections! Note: \"downloadRoute\" must be equal or be inside of your web/proxy-server (relative) root."

@collection ?= new Mongo.Collection @collectionName
@collection.filesCollection = @
@collectionName ?= @collection._name
check @collectionName, String
@downloadRoute ?= '/cdn/storage'
Expand Down
68 changes: 68 additions & 0 deletions docs/collection-instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## *FilesCollection* Instances and *Mongo.Collection* Instances

While *FilesCollection* has a direct reference to a [`Mongo.Collection`](http://docs.meteor.com/#/full/mongo_collection),
the `Mongo.Collection` has a back-reference to the *FilesCollection* itself.

The reference chain is as the following:

```javascript
const Images = new FilesCollection({collectionName: 'Images'});

// get the underlying Mongo.Collection
const collection = Images.collection;

// get the 'parent' FilesCollection
// of this collection instance
const parent = collection.filesCollection;

// returns true
console.log(parent === Images);
```


### Using dburles:mongo-collection-instances

In Meteor for `Mongo.Collection` instances management, we suggest to use [dburles:mongo-collection-instances](https://github.com/dburles/mongo-collection-instances).
It allows to retrieve `Mongo.Collection` instances by its name in any module or file.

__Note:__ This package comes with no dependency to `dburles:mongo-collection-instances`.
To make use of it, install it to your Meteor project first.

```bash
meteor add dburles:mongo-collection-instances
```

Then initialize *FilesCollection*, which itself will create a new `Mongo.Collection`, that is automatically added to a hidden `Mongo.Collection` instances list.

```javascript
const Images = new FilesCollection({collectionName: 'Images'});
````

To retrieve *FilesCollection* use - `Mongo.Collection.get('collectionName')`:

```javascript
const ImagesCollection = Mongo.Collection.get('Images');
const Images = ImagesCollection.filesCollection;
````
### Using a custom collection instance management
This simplified example shows, how to make use of that technique in your own implementation.
Assume having a map of all `Mongo.Collection` instances:
```javascript
constvar collectionsMap = {};
````

Since you may not want to store the *FilesCollection* instance (*because it is not a* `Mongo.Collection`), you can still reference the underlying Mongo.Collection:

```javascript
var Images = new FilesCollection({collectionName: 'Images'});
collectionsMap['Images'] = Images.collection;
````
Access the *FilesCollection* by reference:
```javascript
var Images = collectionsMap['Images'].filesCollection;
````
3 changes: 2 additions & 1 deletion docs/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Please see our experimental [webrtc-data-channel](https://github.com/VeliovGroup
- [`link()`](https://github.com/VeliovGroup/Meteor-Files/wiki/link) [*Isomorphic*] - Generate downloadable link
- [`collection`](https://github.com/VeliovGroup/Meteor-Files/wiki/collection) [*Isomorphic*] - `Meteor.Collection` instance
- [Template helper `fileURL`](https://github.com/VeliovGroup/Meteor-Files/wiki/Template-Helper) [*Client*] - Generate downloadable link in a template

##### Examples:
- [MUP/Docker Persistent Storage](https://github.com/VeliovGroup/Meteor-Files/wiki/MeteorUp-(MUP)-Usage) - Deploy via MeteorUp to Docker container with persistent `storagePath`
- [Third-party storage (AWS S3, DropBox, GridFS and Google Storage)](https://github.com/VeliovGroup/Meteor-Files/wiki/Third-party-storage)
Expand All @@ -105,6 +105,7 @@ Please see our experimental [webrtc-data-channel](https://github.com/VeliovGroup
- [File subversions](https://github.com/VeliovGroup/Meteor-Files/wiki/Create-and-Manage-Subversions) - Create video file with preview and multiple formats
- [React - Example](https://github.com/VeliovGroup/Meteor-Files/wiki/React-Example) - React with a progress bar and component with links to view, re-name, and delete the files
- [Converting from CollectionFS/CFS](https://github.com/VeliovGroup/Meteor-Files/wiki/Converting-from-CollectionFS) - Live conversion from the depreciated CFS to Meteor-Files (*Amazon S3 specifically, but applies to all*)
- [Get FilesCollection instance](https://github.com/VeliovGroup/Meteor-Files/wiki/Collection-Instances) - Retrieve the *FilesCollection* by it's underlying `Mongo.Collection` instance

##### Related Packages:
- [pyfiles (meteor-python-files))](https://github.com/VeliovGroup/meteor-python-files) Python Client for Meteor-Files package
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.8.1',
version: '1.8.2',
summary: 'File upload via DDP/HTTP to server FS, AWS, GridFS, DropBox, Google Drive or other 3rd party storage',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
Expand Down
1 change: 1 addition & 0 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FilesCollection
throw new Meteor.Error 500, "[FilesCollection.#{@collectionName}]: \"downloadRoute\" must be precisely provided on \"public\" collections! Note: \"downloadRoute\" must be equal or be inside of your web/proxy-server (relative) root."

@collection ?= new Mongo.Collection @collectionName
@collection.filesCollection = @
@collectionName ?= @collection._name
check @collectionName, String
@downloadRoute ?= '/cdn/storage'
Expand Down

0 comments on commit c800703

Please sign in to comment.