Skip to content

Commit

Permalink
Merge pull request #844 from veliovgroup/dev
Browse files Browse the repository at this point in the history
📦 v2.2.0

__Breaking Changes__

- ⚠️ Changes in `namingFunction`, — now naming function acts the same on the Client and Server, upon insert, load, and write. Test your implementation with changed logic. Output of Server function supersedes Client's function output

__Changes__

- 📔 Merge #843 and fix #820, thanks to @Prinzhorn
- 📔 Documentation refactoring focused on examples and its simplifications
- 👨‍💻 Support nested custom path returned from `namingFunction`
- 👨‍💻 Fix `namingFunction` behavior on Client and Server in upload, load, and write methods, closing #842; Thanks to @chrschae
- 👷‍♂️ Now library exports its helpers `import { FilesCollection, helpers };`
- 👷‍♂️ Add `.meteorignore` to minimize package's footprint
  • Loading branch information
dr-dimitru authored Jun 29, 2022
2 parents 6573b59 + d34b479 commit f5a335e
Show file tree
Hide file tree
Showing 27 changed files with 351 additions and 277 deletions.
21 changes: 21 additions & 0 deletions .meteorignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.github
.gitignore
.npm
.DS_Store
.eslintcache
node_modules
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
HISTORY.md
LICENCE
LICENSE
README.md
docs
demo
demo-simplest-download-button
demo-simplest-streaming
demo-simplest-upload

logo-bw.png
logo.png
4 changes: 2 additions & 2 deletions .versions
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
local-test:ostrio:files@2.1.1
local-test:ostrio:files@2.2.0
[email protected]
[email protected]
[email protected]
Expand All @@ -35,7 +35,7 @@ [email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:files@2.1.1
ostrio:files@2.2.0
[email protected]
[email protected]
[email protected]
Expand Down
121 changes: 67 additions & 54 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const allowedParams = ['debug', 'ddp', 'schema', 'public', 'chunkSize', 'downloa
* @param config.allowQueryStringCookies {Boolean} - Allow passing Cookies in a query string (in URL). Primary should be used only in Cordova environment. Note: this option will be used only on Cordova. Default: `false`
* @summary Create new instance of FilesCollection
*/
export class FilesCollection extends FilesCollectionCore {
class FilesCollection extends FilesCollectionCore {
constructor(config) {
super();
if (config) {
Expand Down Expand Up @@ -307,3 +307,5 @@ Meteor.startup(() => {
});
}
});

export { FilesCollection, helpers };
6 changes: 3 additions & 3 deletions docs/FileCursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ All document's original properties is available directly by name, like: `FileCur
```js
import { FilesCollection } from 'meteor/ostrio:files';

const Images = new FilesCollection();
const cursor = Images.findOne(); // <-- Returns FileCursor Instance
const imagesCollection = new FilesCollection();
const cursor = imagesCollection.findOne(); // <-- Returns FileCursor Instance
```

#### Methods:
Expand All @@ -19,4 +19,4 @@ const cursor = Images.findOne(); // <-- Returns FileCursor Instance
- `link('original', '/')` - {*String*} - Returns __relative__ downloadable URL to File
- `get(property)` - {*Object*|*mix*} - Returns current document as a plain Object, if `property` is specified - returns value of sub-object property
- `fetch()` - {*[Object]*}- Returns current document as plain Object in Array
- `with()` - {*FileCursor*} - Returns reactive version of current FileCursor, useful to use with `{{#with FileCursor#with}}...{{/with}}` block template helper
- `with()` - {*FileCursor*} - Returns reactive version of current FileCursor, useful to use with `{{#with cursor.with}}...{{/with}}` block template helper
6 changes: 3 additions & 3 deletions docs/FilesCursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Implementation of Cursor for FilesCollection. Returned from `FilesCollection#fin
```js
import { FilesCollection } from 'meteor/ostrio:files';

const Images = new FilesCollection();
const cursor = Images.find(); // <-- Returns FilesCursor Instance
const imagesCollection = new FilesCollection();
const cursor = imagesCollection.find(); // <-- Returns FilesCursor Instance
```

#### Methods:
Expand All @@ -24,7 +24,7 @@ const cursor = Images.find(); // <-- Returns FilesCursor Instance
- `forEach(callback, context)` - {*undefined*} - Call `callback` once for each matching document, sequentially and synchronously.
- `callback` - {*Function*} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
- `context` - {*Object*} - An object which will be the value of `this` inside `callback`
- `each()` - {*[FileCursor]*} - Returns an Array of `FileCursor` made for each document on current Cursor. Useful when using in `{{#each FilesCursor#each}}...{{/each}}` block template helper
- `each()` - {*[FileCursor]*} - Returns an Array of `FileCursor` made for each document on current Cursor. Useful when using in `{{#each cursor.each}}...{{/each}}` block template helper
- `map(callback, context)` - {*Array*} - Map `callback` over all matching documents. Returns an Array
- `callback` - {*Function*} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
- `context` - {*Object*} - An object which will be the value of `this` inside `callback`
Expand Down
8 changes: 4 additions & 4 deletions docs/addFile.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### `addFile(path [, opts, callback, proceedAfterUpload])` [*Server*]

*Add local file to FilesCollection from FS.*
Add local file to FilesCollection from FS.

*Note: You can not use this method on* `public` *collections. As they supposed to be served without NodeJS (Meteor) participation. But you always can move file to root of your web-server and then add a record to FilesCollection.*

Expand All @@ -13,15 +13,15 @@
- `opts.userId` {*String*} - UserId, default *null*
- `opts.fileId` {*String*} - _id of inserted file, if not set - Random.id() will be used
- `callback` {*Function*} - Triggered after new record is added to Collection. With `error`, and `fileRef`, where `fileRef` is a new record from DB
- proceedAfterUpload {*Boolean*} - Proceed `onAfterUpload` hook (*if defined*) after local file is added to `FilesCollection`
- `proceedAfterUpload` {*Boolean*} - Proceed `onAfterUpload` hook (*if defined*) after local file is added to `FilesCollection`
- Returns {*FilesCollection*} - Current FilesCollection instance

```js
import { FilesCollection } from 'meteor/ostrio:files';

const Images = new FilesCollection({collectionName: 'Images'});
const imagesCollection = new FilesCollection({collectionName: 'images'});

Images.addFile('/var/www/files/sample.png', {
imagesCollection.addFile('/var/www/files/sample.png', {
fileName: 'sample.png',
type: 'image/png',
fileId: 'abc123AwesomeId',
Expand Down
18 changes: 9 additions & 9 deletions docs/collection-instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ the `Mongo.Collection` has a back-reference to the *FilesCollection* itself.
The reference chain is as the following:

```js
const Images = new FilesCollection({collectionName: 'Images'});
const imagesCollection = new FilesCollection({collectionName: 'images'});

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

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

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

## Using `dburles:mongo-collection-instances`
Expand All @@ -34,14 +34,14 @@ 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.

```js
const Images = new FilesCollection({collectionName: 'Images'});
const imagesCollection = new FilesCollection({collectionName: 'images'});
```

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

```js
const ImagesCollection = Mongo.Collection.get('Images');
const Images = ImagesCollection.filesCollection;
const ImagesCollection = Mongo.Collection.get('images');
const imagesCollection = ImagesCollection.filesCollection;
```

## Using a custom collection instance management
Expand All @@ -56,12 +56,12 @@ const 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:

```js
const Images = new FilesCollection({collectionName: 'Images'});
collectionsMap.Images = Images.collection;
const imagesCollection = new FilesCollection({collectionName: 'images'});
collectionsMap.images = imagesCollection.collection;
```

Access the *FilesCollection* by reference:

```js
const Images = collectionsMap.Images.filesCollection;
const imagesCollection = collectionsMap.images.filesCollection;
```
20 changes: 10 additions & 10 deletions docs/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
*Direct reference to [`Mongo.Collection`](http://docs.meteor.com/#/full/mongo_collection).*

```js
import { Meteor } from 'meteor/meteor';
import { Meteor } from 'meteor/meteor';
import { FilesCollection } from 'meteor/ostrio:files';

const Images = new FilesCollection({collectionName: 'Images'});
const imagesCollection = new FilesCollection({collectionName: 'images'});

if (Meteor.isServer) {
/* Set deny/allow rules:
* Deny all
* @see http://docs.meteor.com/#/full/deny
*/
Images.denyClient();
imagesCollection.denyClient();

/* Allow all
* @see http://docs.meteor.com/#/full/allow
*/
Images.allowClient();
imagesCollection.allowClient();

/* Deny per action
* @see http://docs.meteor.com/#/full/deny
*/
Images.deny({
imagesCollection.deny({
insert: function() {
return false;
},
Expand All @@ -38,7 +38,7 @@ if (Meteor.isServer) {
/* Allow per action
* @see http://docs.meteor.com/#/full/allow
*/
Images.allow({
imagesCollection.allow({
insert: function() {
return true;
},
Expand All @@ -52,8 +52,8 @@ if (Meteor.isServer) {
}

// Example 1:
Images.collection.find({}).forEach(function (fileRef) {
Images.link(fileRef);
imagesCollection.collection.find({}).forEach(function (fileRef) {
imagesCollection.link(fileRef);
});

// Example: Subscribe:
Expand All @@ -64,15 +64,15 @@ if (Meteor.isClient) {
// Example: Publish:
if (Meteor.isServer) {
Meteor.publish('files.images.all', function () {
return Images.collection.find({});
return imagesCollection.collection.find({});
});
}

// Publish only necessary fields:
// See issue #316
if (Meteor.isServer) {
Meteor.publish('files.images.all', function () {
return Images.collection.find({}, {
return imagesCollection.collection.find({}, {
fields: {
extension: 1,
_downloadRoute: 1,
Expand Down
Loading

0 comments on commit f5a335e

Please sign in to comment.