Skip to content

Commit

Permalink
📔 Documentation refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-dimitru committed Jun 29, 2022
1 parent a4d7b8f commit 5992438
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 137 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ For more expressive example see [Download demo](https://github.com/veliovgroup/M

## Get Support:

- [Ask a question via Gitter chat](https://gitter.im/veliovgroup/Meteor-Files)
- [Ask a question or submit an issue](https://github.com/veliovgroup/Meteor-Files/issues)
- [Releases / Changelog / History](https://github.com/veliovgroup/Meteor-Files/releases)
- For more docs and examples [read wiki](https://github.com/veliovgroup/Meteor-Files/blob/master/docs/readme.md)
Expand Down
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
6 changes: 3 additions & 3 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 @@ -19,9 +19,9 @@
```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
60 changes: 30 additions & 30 deletions docs/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,10 @@

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
storagePath: 'assets/app/uploads/Images',
const imagesCollection = new FilesCollection({
storagePath: 'assets/app/uploads/images',
downloadRoute: '/files/images',
collectionName: 'Images',
collectionName: 'images',
permissions: 0o755,
allowClientCode: false,
cacheControl: 'public, max-age=31536000',
Expand All @@ -978,7 +978,7 @@ const Images = new FilesCollection({
downloadCallback(fileObj) {
if (this.params.query.download == 'true') {
// Increment downloads counter
Images.update(fileObj._id, {$inc: {'meta.downloads': 1}});
imagesCollection.update(fileObj._id, {$inc: {'meta.downloads': 1}});
}
// Must return true to continue download
return true;
Expand All @@ -993,7 +993,7 @@ const Images = new FilesCollection({
});

// Export FilesCollection instance, so it can be imported in other files
export default Images;
export default imagesCollection;
```

### Add extra security:
Expand All @@ -1004,8 +1004,8 @@ export default Images;

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({/* ... */});
Images.collection.attachSchema(new SimpleSchema(Images.schema));
const imagesCollection = new FilesCollection({/* ... */});
imagesCollection.collection.attachSchema(new SimpleSchema(imagesCollection.schema));
```

*You're free to extend the schema to include your own properties. The default schema is stored under* `FilesCollection.schema` *object.*
Expand All @@ -1019,24 +1019,24 @@ const mySchema = {
type: Array
}
};
const Images = new FilesCollection({
const imagesCollection = new FilesCollection({
/* ... */
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
imagesCollection.collection.attachSchema(new SimpleSchema(mySchema));
```

#### Deny collection interaction on client [*Server*]:

*Deny insert/update/remove from client*
Deny insert/update/remove from client

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

if (Meteor.isServer) {
const Images = new FilesCollection({/* ... */});
Images.deny({
const imagesCollection = new FilesCollection({/* ... */});
imagesCollection.deny({
insert() {
return true;
},
Expand All @@ -1049,21 +1049,21 @@ if (Meteor.isServer) {
});

/* Equal shortcut: */
Images.denyClient();
imagesCollection.denyClient();
}
```

#### Allow collection interaction on client [*Server*]:

*Allow insert/update/remove from client*
Allow insert/update/remove from client

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

if (Meteor.isServer) {
const Images = new FilesCollection({/* ... */});
Images.allow({
const imagesCollection = new FilesCollection({/* ... */});
imagesCollection.allow({
insert() {
return true;
},
Expand All @@ -1076,27 +1076,27 @@ if (Meteor.isServer) {
});

/* Equal shortcut: */
Images.allowClient();
imagesCollection.allowClient();
}
```

#### Events listeners:

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({/* ... */});
const imagesCollection = new FilesCollection({/* ... */});
// Alias addListener
Images.on('afterUpload', function (fileRef) {
/* `this` context is the Images (FilesCollection) instance */
imagesCollection.on('afterUpload', function (fileRef) {
/* `this` context is the imagesCollection (FilesCollection) instance */
});
```

#### Use onBeforeUpload to avoid unauthorized upload:

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
const imagesCollection = new FilesCollection({
collectionName: 'images',
allowClientCode: true,
onBeforeUpload() {
if (this.userId) {
Expand All @@ -1116,12 +1116,12 @@ const Images = new FilesCollection({

#### Use onBeforeRemove to avoid unauthorized remove:

*For more info see [remove method](https://github.com/veliovgroup/Meteor-Files/blob/master/docs/remove.md).*
For more info see [remove method](https://github.com/veliovgroup/Meteor-Files/blob/master/docs/remove.md).

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
const imagesCollection = new FilesCollection({
collectionName: 'images',
allowClientCode: true,
onBeforeRemove() {
if (this.userId) {
Expand All @@ -1144,11 +1144,11 @@ const Images = new FilesCollection({
For additional security, it's recommended to verify the mimetype by looking at the content of the file and delete it, if it looks malicious. E.g. you can use [`mmmagic` package](https://github.com/mscdex/mmmagic) for this:

```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',
onAfterUpload(file) {
if (Meteor.isServer) {
// check real mimetype
Expand Down
10 changes: 5 additions & 5 deletions docs/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Find and return Cursor for matching documents.
- Returns {*[FilesCursor](https://github.com/veliovgroup/Meteor-Files/blob/master/docs/FilesCursor.md)*}

```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'});

// Usage:
// Set cursor:
const filesCursor = Images.find();
const filesCursor = imagesCollection.find();

// Get Mongo cursor:
Meteor.publish('images', function() {
Images.find().cursor;
imagesCollection.find().cursor;
});

// Get cursor's data:
Expand All @@ -33,7 +33,7 @@ filesCursor.remove(function (error) {
}
});
// Remove only Collection records from DB:
Images.collection.remove();
imagesCollection.collection.remove();

// Each:
filesCursor.each(function (file) {
Expand Down
Loading

0 comments on commit 5992438

Please sign in to comment.