fix: remove async.series, dont crash if postAtIndex is undefined

v1.18.x
Barış Soner Uşaklı 6 years ago
parent c12e1d19a7
commit dd8d4f206a

@ -289,32 +289,21 @@ async function addTags(topicData, req, res) {
} }
async function addOGImageTags(res, topicData, postAtIndex) { async function addOGImageTags(res, topicData, postAtIndex) {
const images = []; const uploads = postAtIndex ? await posts.uploads.listWithSizes(postAtIndex.pid) : [];
const images = uploads.map((upload) => {
async.series([ upload.name = nconf.get('url') + nconf.get('upload_url') + '/files/' + upload.name;
async function () { return upload;
const uploads = await posts.uploads.listWithSizes(postAtIndex.pid);
uploads.forEach((upload) => {
upload.name = nconf.get('url') + nconf.get('upload_url') + '/files/' + upload.name;
images.push(upload);
});
},
function (next) {
if (topicData.thumb) {
images.push(topicData.thumb);
}
if (topicData.category.backgroundImage && (!postAtIndex || !postAtIndex.index)) {
images.push(topicData.category.backgroundImage);
}
if (postAtIndex && postAtIndex.user && postAtIndex.user.picture) {
images.push(postAtIndex.user.picture);
}
process.nextTick(next);
},
], function () {
images.forEach(path => addOGImageTag(res, path));
}); });
if (topicData.thumb) {
images.push(topicData.thumb);
}
if (topicData.category.backgroundImage && (!postAtIndex || !postAtIndex.index)) {
images.push(topicData.category.backgroundImage);
}
if (postAtIndex && postAtIndex.user && postAtIndex.user.picture) {
images.push(postAtIndex.user.picture);
}
images.forEach(path => addOGImageTag(res, path));
} }
function addOGImageTag(res, image) { function addOGImageTag(res, image) {

Loading…
Cancel
Save