Skip to content

Commit

Permalink
Merge pull request #594 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.9.9
  • Loading branch information
dr-dimitru authored Mar 24, 2018
2 parents b898d4e + 62c5de0 commit 7cfe086
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 295 deletions.
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
### I'm having an issue:
- Give an expressive description
- Give an expressive description of what is went wrong
- Version of `Meteor-Files` you're experiencing this issue
- Version of `Meteor` you're experiencing this issue
- Where this issue appears? OS (Mac/Win/Linux)? Browser name and its version?
- Is it *Client* or *Server* issue?
- Post *Client* and/or *Server* logs with enabled `debug` option, you can enable "debug" mode in [*Constructor*](https://github.com/VeliovGroup/Meteor-Files/wiki/Constructor)

### I had an issue and I've solved it on my own:
- Provide a description of steps that you've followed to solve the problem.
- Provide links to websites and/or pages with the information that helped you (*if there are any*).

- Provide a description of steps that you've followed to solve the problem
- Provide links to websites and/or pages with the information that helped you (*if there are any*)

### I have a suggestion:
- Describe your feature / request
Expand Down
24 changes: 12 additions & 12 deletions .npm/package/npm-shrinkwrap.json

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

2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ [email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:[email protected].8
ostrio:[email protected].9
[email protected]
[email protected]
[email protected]
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
- Give an expressive description of what is went wrong
- Version of `Meteor-Files` you're experiencing this issue
- Version of `Meteor` you're experiencing this issue
- Where this issue appears? OS (Mac/Win/Linux)? Browser name and its version?
- Is it *Client* or *Server* issue?
- Post *Client* and/or *Server* logs with enabled `debug` option, you can enable "debug" mode in [*Constructor*](https://github.com/VeliovGroup/Meteor-Files/wiki/Constructor)

### I had an issue and I've solved it on my own:
- Provide a description of steps that you've followed to solve the problem
- Provide links to websites and/or pages with the information that helped you (*if there are any*)

### I have a suggestion:
1. PRs are always welcome - [send a PR](https://github.com/VeliovGroup/Meteor-Files/compare)
- Always send PRs only to [`dev` branch](https://github.com/VeliovGroup/Meteor-Files/compare/dev), thank you
Expand Down
171 changes: 105 additions & 66 deletions README.md

Large diffs are not rendered by default.

91 changes: 69 additions & 22 deletions docs/constructor.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
##### `new FilesCollection([config])` [*Isomorphic*]

*Initialize FilesCollection collection.*

<table>
Expand Down Expand Up @@ -66,7 +67,7 @@
Note: When running in development mode files stored at a relative path (within the Meteor project) are silently removed when Meteor is restarted.<br /><br />
To preserve files in development mode store them outside of the Meteor application, e.g. <code>/data/Meteor/uploads/</code><br /><br />
The Meteor-Files package operates on the host filesystem, unlike Meteor Assets. When a relative path is specified for <code>config.storagePath</code> (path starts with ./ or no slash) files will be located relative to the assets folder.<br /><br /> When an absolute path is used (path starts with /) files will be located starting at the root of the filesystem.
<br /><br />If using <a href="https://github.com/kadirahq/meteor-up">MeteorUp</a>, Docker volumes has to be created in <code>mup.json</code>, see <a href="https://github.com/bryanlimy/Meteor-Files/blob/master/docs/constructor.md#example-on-using-meteorup">Usage on MeteorUp</a>
<br /><br />If using <a href="https://github.com/kadirahq/meteor-up">MeteorUp</a>, Docker volumes has to be created in <code>mup.json</code>, see <a href="https://github.com/bryanlimy/Meteor-Files/blob/master/docs/constructor.md#example-on-using-meteorup">Usage on MeteorUp</a>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -725,11 +726,42 @@
Use for security reasons when only upload from <em>Client</em> to <em>Server</em> usage is needed, and files shouldn't be downloaded by any user.
</td>
</tr>
<tr>
<td align="right">
<code>config._preCollection</code> {<em>Mongo.Collection</em>}
</td>
<td>
Server
</td>
<td>
Mongo.Collection Instance
</td>
<td>
</td>
<td>
You can pass your own Mongo Collection instance <code>{_preCollection: new Mongo.Collection('__pre_myFiles')}</code>
</td>
</tr>
<tr>
<td align="right">
<code>config._preCollectionName</code> {<em>String</em>}
</td>
<td>
Server
</td>
<td>
preCollection name
</td>
<td>
<code>__pre_MeteorUploadFiles</code>
</td>
<td></td>
</tr>
</tbody>
</table>


### Event map:

<table>
<thead>
<tr>
Expand Down Expand Up @@ -769,14 +801,15 @@
</tbody>
</table>


### Examples:
```jsx

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
storagePath: 'assets/app/uploads/Images',
downloadRoute: '/files/images'
downloadRoute: '/files/images',
collectionName: 'Images',
permissions: 0755,
permissions: 0o755,
allowClientCode: false,
cacheControl: 'public, max-age=31536000',
// Read more about cacheControl: https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers
Expand All @@ -792,9 +825,8 @@ const Images = new FilesCollection({
// and on server at `onAfterUpload` hook (trusted side)
if (file.size <= 10485760 && /png|jpe?g/i.test(file.ext)) {
return true;
} else {
return 'Please upload image, with size equal or less than 10MB';
}
return 'Please upload image, with size equal or less than 10MB';
},
downloadCallback(fileObj) {
if (this.params.query.download == 'true') {
Expand All @@ -808,9 +840,8 @@ const Images = new FilesCollection({
// Check if current user is owner of the file
if (fileObj.meta.owner === this.userId) {
return true;
} else {
return false;
}
return false;
}
});

Expand All @@ -824,14 +855,16 @@ export default Images;

*To attach schema, use/install [aldeed:collection2](https://github.com/aldeed/meteor-collection2) and [simple-schema](https://atmospherejs.com/aldeed/simple-schema) packages.*

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

*You're free to extend the schema to include your own properties. The default schema is stored under* `FilesCollection.schema` *object.*

```jsx
```js
import { FilesCollection } from 'meteor/ostrio:files';
const mySchema = {
...FilesCollection.schema,
myProp: String,
Expand All @@ -847,8 +880,11 @@ Images.collection.attachSchema(new SimpleSchema(mySchema));
```

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

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

```js
import { FilesCollection } from 'meteor/ostrio:files';
if (Meteor.isServer) {
const Images = new FilesCollection({/* ... */});
Images.deny({
Expand All @@ -869,8 +905,11 @@ if (Meteor.isServer) {
```

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

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

```js
import { FilesCollection } from 'meteor/ostrio:files';
if (Meteor.isServer) {
const Images = new FilesCollection({/* ... */});
Images.allow({
Expand All @@ -891,7 +930,9 @@ if (Meteor.isServer) {
```

#### Events listeners:
```jsx

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({/* ... */});
// Alias addListener
Images.on('afterUpload', function (fileRef) {
Expand All @@ -900,7 +941,9 @@ Images.on('afterUpload', function (fileRef) {
```

#### Use onBeforeUpload to avoid unauthorized upload:
```jsx

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
allowClientCode: true,
Expand All @@ -921,8 +964,11 @@ const Images = new FilesCollection({
```

#### Use onBeforeRemove to avoid unauthorized remove:

*For more info see [remove method](https://github.com/VeliovGroup/Meteor-Files/wiki/remove).*
```jsx

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
allowClientCode: true,
Expand All @@ -942,14 +988,15 @@ const Images = new FilesCollection({
});
```


#### Use onAfterUpload to avoid mime-type and/or extension substitution:

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:
```jsx

```js
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
onAfterUpload(file) {
const self = this;
if (Meteor.isServer) {
// check real mimetype
const { Magic, MAGIC_MIME_TYPE } = require('mmmagic');
Expand All @@ -959,10 +1006,10 @@ const Images = new FilesCollection({
// is not a real image --> delete
console.log('onAfterUpload, not an image: ', file.path);
console.log('deleted', file.path);
self.remove(file._id);
this.remove(file._id);
}
}));
}
}
};
});
```
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package.describe({
name: 'ostrio:files',
version: '1.9.8',
version: '1.9.9',
summary: 'File upload via DDP/HTTP to server, 3rd party storage support: AWS S3, GridFS, DropBox and others',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
});

Npm.depends({
'fs-extra': '5.0.0',
'request': '2.83.0',
'request': '2.85.0',
'file-type': '7.6.0',
'eventemitter3': '3.0.1'
});
Expand Down
Loading

0 comments on commit 7cfe086

Please sign in to comment.