Skip to content

Commit

Permalink
convertFileType function to use bufferData consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
brokoli777 committed Aug 8, 2024
1 parent b14559a commit 5e5570c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/routes/api/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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})`);
}
Expand Down

0 comments on commit 5e5570c

Please sign in to comment.