From 5e5570cac12fa575047d67fed833512067a06ff8 Mon Sep 17 00:00:00 2001 From: Bregwin Jogi Date: Thu, 8 Aug 2024 11:03:13 -0400 Subject: [PATCH] convertFileType function to use bufferData consistently --- src/routes/api/get.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routes/api/get.js b/src/routes/api/get.js index aadb4b5..7299b4a 100644 --- a/src/routes/api/get.js +++ b/src/routes/api/get.js @@ -137,8 +137,8 @@ module.exports = (req, res) => { // } // }; - const convertFileType = async (mimeType, data, extension) => { - data = data.toString(); + const convertFileType = async (mimeType, bufferData, extension) => { + const data = bufferData.toString(); if (mimeType === 'text/plain') { if (extension === 'txt') return data; @@ -170,12 +170,13 @@ module.exports = (req, res) => { } if (extension === 'txt' || extension == 'csv') return data; } else if (mimeType.startsWith('image/')) { - const image = sharp(Buffer.from(data, 'base64')); + const image = sharp(bufferData); if (extension === 'png') return image.png().toBuffer(); if (extension === 'jpg' || extension === 'jpeg') return image.jpeg().toBuffer(); if (extension === 'webp') return image.webp().toBuffer(); if (extension === 'avif') return image.avif().toBuffer(); if (extension === 'gif') return image.gif().toBuffer(); + return bufferData; } else { throw new Error(`Conversion failed: Unsupported conversion (${mimeType} to ${extension})`); }