Skip to content

Node.js based forum software built for the modern web

fix: carry out mime-type guessing on incoming attachments

Julian Lam71ce30893691
diff --git a/src/posts/attachments.js b/src/posts/attachments.js
index 679247da27..3683aa0de4 100644
--- a/src/posts/attachments.js
+++ b/src/posts/attachments.js
@@ -2,6 +2,7 @@
const crypto = require('crypto');
const _ = require('lodash');
+const mime = require('mime');
const db = require('../database');
@@ -50,6 +51,11 @@ Attachments.update = async (pid, attachments) => {
_type = 'attachment';
}
+ if (!mediaType) { // MIME type guessing
+ const { pathname } = new URL(url);
+ mediaType = mime.getType(pathname);
+ }
+
bulkOps.hash.push([key, { _type, mediaType, url, name, width, height }]);
hashes.push(hash);
});