2022-04-07 10:25:56 +02:00
|
|
|
import Attachments from '/models/attachments';
|
2021-04-06 12:42:15 +02:00
|
|
|
import { ObjectID } from 'bson';
|
|
|
|
|
|
|
|
|
|
Meteor.publish('attachmentsList', function() {
|
2022-04-07 10:25:56 +02:00
|
|
|
const ret = Attachments.find(
|
2021-04-06 12:42:15 +02:00
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
fields: {
|
|
|
|
|
_id: 1,
|
2022-04-07 10:25:56 +02:00
|
|
|
name: 1,
|
|
|
|
|
size: 1,
|
|
|
|
|
type: 1,
|
|
|
|
|
meta: 1,
|
2021-04-06 12:42:15 +02:00
|
|
|
},
|
|
|
|
|
sort: {
|
2022-04-07 10:25:56 +02:00
|
|
|
name: 1,
|
2021-04-06 12:42:15 +02:00
|
|
|
},
|
|
|
|
|
limit: 250,
|
|
|
|
|
},
|
2022-04-07 10:25:56 +02:00
|
|
|
).cursor;
|
|
|
|
|
return ret;
|
2021-04-06 12:42:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.publish('orphanedAttachments', function() {
|
|
|
|
|
let keys = [];
|
|
|
|
|
|
2021-10-21 19:39:11 +03:00
|
|
|
if (Attachments.find({}, { fields: { copies: 1 } }) !== undefined) {
|
|
|
|
|
Attachments.find({}, { fields: { copies: 1 } }).forEach(att => {
|
|
|
|
|
keys.push(new ObjectID(att.copies.attachments.key));
|
|
|
|
|
});
|
|
|
|
|
keys.sort();
|
|
|
|
|
keys = _.uniq(keys, true);
|
|
|
|
|
|
|
|
|
|
return AttachmentStorage.find(
|
|
|
|
|
{ _id: { $nin: keys } },
|
|
|
|
|
{
|
|
|
|
|
fields: {
|
|
|
|
|
_id: 1,
|
|
|
|
|
filename: 1,
|
|
|
|
|
md5: 1,
|
|
|
|
|
length: 1,
|
|
|
|
|
contentType: 1,
|
|
|
|
|
metadata: 1,
|
|
|
|
|
},
|
|
|
|
|
sort: {
|
|
|
|
|
filename: 1,
|
|
|
|
|
},
|
|
|
|
|
limit: 250,
|
2021-04-06 12:42:15 +02:00
|
|
|
},
|
2021-10-21 19:39:11 +03:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2021-04-06 12:42:15 +02:00
|
|
|
});
|