Skip to content

Commit

Permalink
Merge pull request #741 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
📦v1.14.1
  • Loading branch information
dr-dimitru authored Apr 23, 2020
2 parents 7ffb4f6 + 46e4f00 commit 2035b63
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
18 changes: 9 additions & 9 deletions .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions .versions
5 changes: 4 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import FilesCollectionCore from './core.js';
import { formatFleURL, helpers } from './lib.js';

const NOOP = () => { };
const allowedParams = ['debug', 'ddp', 'schema', 'public', 'chunkSize', 'downloadRoute', 'collection', 'collectionName', 'namingFunction', 'onBeforeUpload', 'allowClientCode', 'onbeforeunloadMessage', 'disableUpload'];
const allowedParams = ['debug', 'ddp', 'schema', 'public', 'chunkSize', 'downloadRoute', 'collection', 'collectionName', 'namingFunction', 'onBeforeUpload', 'allowClientCode', 'onbeforeunloadMessage', 'disableUpload', 'allowQueryStringCookies'];

/*
* @locus Anywhere
Expand Down Expand Up @@ -110,6 +110,9 @@ export class FilesCollection extends FilesCollectionCore {
const setTokenCookie = () => {
if (Meteor.connection._lastSessionId) {
cookie.set('x_mtok', Meteor.connection._lastSessionId, { path: '/' });
if (Meteor.isCordova && this.allowQueryStringCookies) {
cookie.send();
}
}
};

Expand Down
41 changes: 19 additions & 22 deletions docs/gridfs-migration.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
### Migrating files from GridFS between applications
# Migrating files from GridFS between applications

You can share/migrate files between Meteor applications via DDP on a server/database level **without the need for complex setups**.
This is due to the circumstance, that GridFS makes use of a normal Mongo.Collection to store metadata and chunks.

This topic can be of relevance for Services or Microservices, that don't share a database but have to share their data.

##### Use Case
## Use Case

Consider two Meteor applications **C (Consumer)** and **P (Provider)** where C wants to synchronize all files from P.
The sync will happen without clients (browsers/devices) being involved and the files and documents won't be mutated.


##### Step 1 Provide access to the files
### Step 1 Provide access to the files

First create three Methods in P that each share one of the three crucial Parts of a `FilesCollection`:

* Sharing the `FilesCollection`'s documents
* Sharing the `fs.files`* metadata for the files' respective subversions
* Sharing the `fs.chunks`* (the actual data) of all stored files and their subversions
- Sharing the `FilesCollection`'s documents
- Sharing the `fs.files`* metadata for the files' respective subversions
- Sharing the `fs.chunks`* (the actual data) of all stored files and their subversions

*This assumes the [default configuration of your GridFS](https://github.com/VeliovGroup/Meteor-Files/wiki/GridFS-Integration) whichs by default using the `db.fs.files` and `db.fs.chunks` collections.
For custom configuration you may consult the JS Mongo Driver documentation on [GridFSBucket](http://mongodb.github.io/node-mongodb-native/3.2/api/GridFSBucket.html).
*This assumes the [default configuration of your GridFS](https://github.com/VeliovGroup/Meteor-Files/wiki/GridFS-Integration) which is by default using the `db.fs.files` and `db.fs.chunks` collections.*

*P/server/sync.js*
*For custom configuration you may consult the JS Mongo Native Driver documentation on [GridFSBucket](http://mongodb.github.io/node-mongodb-native/3.2/api/GridFSBucket.html).*

```javascript
#### P/server/sync.js

```js
import { Meteor } from 'meteor/meteor'
import { Mongo } from 'meteor/mongo'
import { FilesCollection } from 'meteor/ostrio:files'
Expand All @@ -49,11 +49,11 @@ function getFilesChunks () {
Meteor.methods({getFilesDocuments, getFilesMetadata, getFilesChunks})
```

##### Step 2 Create collections and sync method in C
### Step 2 Create collections and sync method in C

*C/server/sync.js*
#### C/server/sync.js

```javascript
```js
import { Meteor } from 'meteor/meteor'
import { Mongo } from 'meteor/mongo'
import { DDP } from 'meteor/ddp-client'
Expand Down Expand Up @@ -109,30 +109,27 @@ function synchronize (trackerComputation) {
// ... code continues in the next step
```


##### Step 3 Create a remote DDP connection and run the sync
### Step 3 Create a remote DDP connection and run the sync

In your Consumer application C you can now connect to the remote app on the server-side.


*C/server/sync.js (continued)*
#### C/server/sync.js (continued)

```javascript
Meteor.startup(() => {
const url = 'p.domain.tld' // get url of P, for example via process.env or Meteor.settings
remoteConnection = DDP.connect(url)

// use Tracker to run the sync when the remoteConnection is "connected"
const synchronizeTracker = Meteor.bindEnvironment(synchronize)
Tracker.autorun(synchronizeTracker)
})

```


##### Further considerations
### Further considerations

You may require authentication for the remote connection, which can be added using [`ongoworks:ddp-login`](https://github.com/reactioncommerce/meteor-ddp-login).
A good pattern is to create a user that is only permitted to run the sync methods in P and login with that user from C. The credentials for login can be passed using `process.env` or `Meteor.settings`.

From this point you can configure your methods to sync only a subset of documents or manipulate them before/after sync or remove them after sync.
From this point you can configure your methods to sync only a subset of documents or manipulate them before/after sync or remove them after sync.
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:files',
version: '1.14.0',
version: '1.14.1',
summary: 'Upload files to Meteor application, with 3rd party storage support: AWS:S3, GridFS and other',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
Expand All @@ -9,7 +9,7 @@ Package.describe({
Npm.depends({
'fs-extra': '8.1.0',
request: '2.88.2',
'file-type': '14.1.3',
'file-type': '14.2.0',
eventemitter3: '4.0.0'
});

Expand Down

0 comments on commit 2035b63

Please sign in to comment.