Skip to content

Node.js based forum software built for the modern web

fix: closes #14942, fix undefined attachment

Barış Soner Uşaklı85a9892c937a
diff --git a/src/posts/attachments.js b/src/posts/attachments.js
index cc5b6ebeb5..35fefefcff 100644
--- a/src/posts/attachments.js
+++ b/src/posts/attachments.js
@@ -20,14 +20,13 @@ Attachments.get = async (pids) => {
const hashToAttachment = _.zipObject(allHashes, allAttachments);
const data = postData.map((post) => {
const pidHashes = post ? post.attachments : [];
- return pidHashes.map(hash => hashToAttachment[hash]);
+ return pidHashes.map(hash => hashToAttachment[hash] || []);
});
return isArray ? data : data[0];
};
Attachments.getAttachments = async (hashes) => {
- const keys = hashes.map(hash => `attachment:${hash}`);
- return (await db.getObjects(keys)).filter(Boolean);
+ return await db.getObjects(hashes.map(hash => `attachment:${hash}`));
};
Attachments.update = async (pid, attachments) => {
diff --git a/src/topics/thumbs.js b/src/topics/thumbs.js
index cd9c4268e1..d7d38d9089 100644
--- a/src/topics/thumbs.js
+++ b/src/topics/thumbs.js
@@ -57,11 +57,11 @@ async function loadFromTopicData(topicData, options = {}) {
// Add attachments to thumb sets
mainPidAttachments.forEach((attachments, idx) => {
attachments = attachments.filter(
- attachment => !thumbs[idx].includes(attachment.url) && (attachment.mediaType && attachment.mediaType.startsWith('image/'))
+ a => a && !thumbs[idx].includes(a.url) && (a.mediaType && a.mediaType.startsWith('image/'))
);
if (attachments.length) {
- thumbs[idx].push(...attachments.map(attachment => attachment.url));
+ thumbs[idx].push(...attachments.map(a => a.url));
}
});