From 71ce30893691c7edb2c7212e4b015a4698dc52d6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 17 Sep 2024 14:18:16 -0400 Subject: [PATCH] fix: carry out mime-type guessing on incoming attachments --- src/posts/attachments.js | 6 ++++++ 1 file changed, 6 insertions(+) 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); });