Skip to content

Commit

Permalink
Merge pull request #534 from VeliovGroup/dev
Browse files Browse the repository at this point in the history
v1.9.3
  • Loading branch information
dr-dimitru authored Dec 9, 2017
2 parents 1d823fb + 1bb4ac0 commit b31a44e
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 155 deletions.
12 changes: 6 additions & 6 deletions .npm/package/npm-shrinkwrap.json

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

4 changes: 2 additions & 2 deletions .versions
67 changes: 1 addition & 66 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,72 +158,7 @@ export class FilesCollection extends FilesCollectionCore {
}

if (!this.schema) {
this.schema = {
size: {
type: Number
},
name: {
type: String
},
type: {
type: String
},
path: {
type: String
},
isVideo: {
type: Boolean
},
isAudio: {
type: Boolean
},
isImage: {
type: Boolean
},
isText: {
type: Boolean
},
isJSON: {
type: Boolean
},
isPDF: {
type: Boolean
},
extension: {
type: String,
optional: true
},
_storagePath: {
type: String
},
_downloadRoute: {
type: String
},
_collectionName: {
type: String
},
public: {
type: Boolean,
optional: true
},
meta: {
type: Object,
blackbox: true,
optional: true
},
userId: {
type: String,
optional: true
},
updatedAt: {
type: Date,
optional: true
},
versions: {
type: Object,
blackbox: true
}
};
this.schema = FilesCollectionCore.schema;
}

check(this.debug, Boolean);
Expand Down
67 changes: 67 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,73 @@ export default class FilesCollectionCore extends EventEmitter {
super();
}

static schema = {
size: {
type: Number
},
name: {
type: String
},
type: {
type: String
},
path: {
type: String
},
isVideo: {
type: Boolean
},
isAudio: {
type: Boolean
},
isImage: {
type: Boolean
},
isText: {
type: Boolean
},
isJSON: {
type: Boolean
},
isPDF: {
type: Boolean
},
extension: {
type: String,
optional: true
},
_storagePath: {
type: String
},
_downloadRoute: {
type: String
},
_collectionName: {
type: String
},
public: {
type: Boolean,
optional: true
},
meta: {
type: Object,
blackbox: true,
optional: true
},
userId: {
type: String,
optional: true
},
updatedAt: {
type: Date,
optional: true
},
versions: {
type: Object,
blackbox: true
}
};

/*
* @locus Anywhere
* @memberOf FilesCollectionCore
Expand Down
19 changes: 17 additions & 2 deletions docs/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,16 +821,31 @@ export default Images;
### Add extra security:

#### Attach schema [*Isomorphic*]:
*Default schema is stored under* `FilesCollection.schema` *object.*

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

*You're free to modify/overwrite* `FilesCollection.schema` *object.*
```jsx
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
const mySchema = {
...FilesCollection.schema,
myProp: String,
myOtherProp: {
type: Array
}
};
const Images = new FilesCollection({
/* ... */
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
```

#### Deny collection interaction on client [*Server*]:
*Deny insert/update/remove from client*
```jsx
Expand Down
4 changes: 2 additions & 2 deletions docs/meteorup-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ module.exports = {
Images = new FilesCollection({
debug: true,
storagePath: '/images',
permissions: 0774,
parentDirPermissions: 0774,
permissions: 0o774,
parentDirPermissions: 0o774,
collectionName: 'Images',
allowClientCode: false, // Disallow remove files from Client
onBeforeUpload: function(file) {
Expand Down
30 changes: 25 additions & 5 deletions docs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,42 @@ var defaultSchema = {
#### Attach schema (*Recommended*):
*Although this package comes with schema it isn't enabled (attached) by default (since v1.5.0), you're free to use it or not. To attach schema you need to install [Collection2](https://github.com/aldeed/meteor-collection2) and [simple-schema](https://atmospherejs.com/aldeed/simple-schema) packages separately.*
```javascript
this.Images = new FilesCollection({ collectionName: 'Images'});
Images = new FilesCollection({ collectionName: 'Images'});
Images.collection.attachSchema(new SimpleSchema(Images.schema));
```

#### Extend default schema:

The default schema is available as a static property of `FilesCollection`, so you can extend it using a library like underscore:
```javascript
var mySchema = _.extend(defaultSchema, {
var mySchema = _.extend(FilesCollection.schema, {
myProp: {
type: String
}
});

this.Images = new FilesCollection({
Images = new FilesCollection({
collectionName: 'Images',
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
```

Or with ES6 object spread syntax:

```javascript
const mySchema = {
...FilesCollection.schema
myProp: {
type: String
}
});

export default Images = new FilesCollection({
collectionName: 'Images',
schema: new SimpleSchema(mySchema)
schema: mySchema
});
Images.collection.attachSchema(new SimpleSchema(mySchema));
```

#### Pass your own schema (*not recommended*):
Expand All @@ -100,6 +120,6 @@ var mySchema = { /* Your schema here */ };

this.Images = new FilesCollection({
collectionName: 'Images',
schema: new SimpleSchema(mySchema)
schema: mySchema
});
```
2 changes: 1 addition & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const formatFleURL = (fileRef, version = 'original') => {
const _root = __meteor_runtime_config__.ROOT_URL.replace(/\/+$/, '');
const vRef = ((fileRef.versions && fileRef.versions[version]) || fileRef);

if (_.has(vRef, 'extension')) {
if (vRef.extension && _.isString(vRef, 'extension')) {
ext = `.${vRef.extension.replace(/^\./, '')}`;
} else {
ext = '';
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package.describe({
name: 'ostrio:files',
version: '1.9.2',
summary: 'File upload via DDP/HTTP to server FS, AWS, GridFS, DropBox, Google Drive or other 3rd party storage',
version: '1.9.3',
summary: 'File upload via DDP/HTTP to server FS. With 3rd party storage support, like: AWS, GridFS, DropBox, Google Drive or other',
git: 'https://github.com/VeliovGroup/Meteor-Files',
documentation: 'README.md'
});

Npm.depends({
'fs-extra': '4.0.2',
'fs-extra': '4.0.3',
'request': '2.83.0',
'file-type': '7.4.0',
'eventemitter3': '3.0.0'
Expand Down
67 changes: 1 addition & 66 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,72 +346,7 @@ export class FilesCollection extends FilesCollectionCore {
}

if (!this.schema) {
this.schema = {
size: {
type: Number
},
name: {
type: String
},
type: {
type: String
},
path: {
type: String
},
isVideo: {
type: Boolean
},
isAudio: {
type: Boolean
},
isImage: {
type: Boolean
},
isText: {
type: Boolean
},
isJSON: {
type: Boolean
},
isPDF: {
type: Boolean
},
extension: {
type: String,
optional: true
},
_storagePath: {
type: String
},
_downloadRoute: {
type: String
},
_collectionName: {
type: String
},
public: {
type: Boolean,
optional: true
},
meta: {
type: Object,
blackbox: true,
optional: true
},
userId: {
type: String,
optional: true
},
updatedAt: {
type: Date,
optional: true
},
versions: {
type: Object,
blackbox: true
}
};
this.schema = FilesCollectionCore.schema;
}

check(this.debug, Boolean);
Expand Down
Loading

0 comments on commit b31a44e

Please sign in to comment.