summaryrefslogtreecommitdiffstats
path: root/models/avatars.js
blob: 53924ffb01e0c5f421807a6acde18fd59bafa748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Avatars = new FS.Collection('avatars', {
  stores: [
    new FS.Store.GridFS('avatars'),
  ],
  filter: {
    maxSize: 72000,
    allow: {
      contentTypes: ['image/*'],
    },
  },
});

function isOwner(userId, file) {
  return userId && userId === file.userId;
}

Avatars.allow({
  insert: isOwner,
  update: isOwner,
  remove: isOwner,
  download() { return true; },
  fetch: ['userId'],
});

Avatars.files.before.insert((userId, doc) => {
  doc.userId = userId;
});