Created
June 7, 2015 15:16
-
-
Save nickbenes/0cb013e8a4522c63169d to your computer and use it in GitHub Desktop.
Meteor collection for images using CollectionFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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