From dd8d4f206a84a3de811e61acb57d1ff1a5b6a084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= <barisusakli@gmail.com> Date: Tue, 19 Mar 2019 11:55:53 -0400 Subject: [PATCH] fix: remove async.series, dont crash if postAtIndex is undefined --- src/controllers/topics.js | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/controllers/topics.js b/src/controllers/topics.js index e3f8fa22ea..f3b31165b8 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -289,32 +289,21 @@ async function addTags(topicData, req, res) { } async function addOGImageTags(res, topicData, postAtIndex) { - const images = []; - - async.series([ - async function () { - 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)); + const uploads = postAtIndex ? await posts.uploads.listWithSizes(postAtIndex.pid) : []; + const images = uploads.map((upload) => { + upload.name = nconf.get('url') + nconf.get('upload_url') + '/files/' + upload.name; + return upload; }); + 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) {