Skip to content

Instantly share code, notes, and snippets.

@nickbenes
Created June 7, 2015 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickbenes/0cb013e8a4522c63169d to your computer and use it in GitHub Desktop.
Save nickbenes/0cb013e8a4522c63169d to your computer and use it in GitHub Desktop.
Meteor collection for images using CollectionFS
var createThumb = function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
};
var createWeb = function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('320', '180').stream().pipe(writeStream);
};
var convertToPng = function(fileObj) {
return {
extension: 'png',
type: 'image/png'
}
};
this.Images = new FS.Collection("images", {
stores: [
new FS.Store.FileSystem("full", {
beforeWrite: convertToPng
}),
new FS.Store.FileSystem("web", {
beforeWrite: convertToPng,
transformWrite: createWeb
}),
new FS.Store.FileSystem("thumb", {
beforeWrite: convertToPng,
transformWrite: createThumb
})
],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});
this.Images.userCanInsert = function(userId, doc) {
return Users.isInRoles(userId, ["user"]);
}
this.Images.userCanUpdate = function(userId, doc) {
return userId && Users.isInRoles(userId, ["user"]);
}
this.Images.userCanRemove = function(userId, doc) {
return userId && Users.isInRoles(userId, ["admin"]);
}
this.Images.userCanDownload = function(userId, doc) {
return Users.isInRoles(userId, ["user"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment