avatars.js 489 B

123456789101112131415161718192021222324252627
  1. Avatars = new FS.Collection('avatars', {
  2. stores: [
  3. new FS.Store.GridFS('avatars')
  4. ],
  5. filter: {
  6. maxSize: 32000,
  7. allow: {
  8. contentTypes: ['image/*']
  9. }
  10. }
  11. });
  12. var isOwner = function(userId, file) {
  13. return userId && userId === file.userId;
  14. };
  15. Avatars.allow({
  16. insert: isOwner,
  17. update: isOwner,
  18. remove: isOwner,
  19. download: function() { return true; },
  20. fetch: ['userId']
  21. });
  22. Avatars.files.before.insert(function(userId, doc) {
  23. doc.userId = userId;
  24. });