Я хочу отфильтровать свой результат подписки на мои изображения fs.collection.
Коллекция объявляется следующим образом:
Images = new FS.Collection('images', {
stores: [ImagesStore],
filter: {
//maxSize: 1048576 * 1, //in bytes //1MB
maxSize: 512 * 1024, //in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ]
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert("Your file must be a ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ], and must not exceed 512KBytes");
sAlert.error(message, {effect: 'stackslide', position: 'left-top', timeout: '3000'});
} else {
console.log(message);
}
}
}
});
FS.HTTP.setBaseUrl('/usrImg');
Images.deny({
insert: function(userId, fileObj) {
return false;
},
update: function(userId, fileObj) {
return false;
},
remove: function(userId, fileObj) {
return false;
},
download: function(userId, fileObj /*, shareId*/) {
return false;
},
fetch: []
});
Images.allow({
insert: function(userId, fileObj) {
return true;
},
update: function(userId, fileObj) {
return true;
},
remove: function(userId, fileObj) {
return true;
},
download: function(userId, fileObj /*, shareId*/) {
return true;
},
fetch: [] // ['owner']
});
Подписка такая:
var i = -1,
array = [],
usrAvatarId = Meteor.users.find({"profile.avatar.type": "doc"}, {fields: {"profile.avatar.data": 1}}).fetch(),
nbAvatar = Meteor.users.find({"profile.avatar.type": "doc"}).count();
console.log(nbAvatar);
console.log(usrAvatarId);
while(++i < nbAvatar)
array.push(usrAvatarId[i]._id);
console.log(array);
Meteor.subscribe('images', array);
И, наконец, публикация выглядит так:
Meteor.publish('images', function(array){
console.log(array);
return Images.find({});
});
В настоящее время цель состоит в том, чтобы передать в качестве параметра массив, содержащий идентификатор разрешенных файлов. Как и сейчас, я всегда скачиваю все документы коллекции.
Когда я регистрирую клиентскую часть коллекции, у меня хорошо получается массив файлов со свойством _id.
Но когда я пытаюсь это:
Meteor.publish('images', function(array){
console.log(array);
return Images.find({_id: {$in: array}});
});
Я не получаю никакого документа, думал, что сервер правильно регистрирует мне переданный массив.
Я, вероятно, что-то упускаю: я не привык к FS.collection, и его документ не самый простой для понимания, который я когда-либо видел...
Что касается Разрешить / Запретить, я не думаю, что это что-то меняет здесь, но я не менял их из исходного кода, который использовал для запуска.
Может ли кто-нибудь помочь? Скачивать по 200 файлов за соединение становится скучно :/
Спасибо