From 1b6ad1ee4c8bc0837c13212eb10c0638a45074e0 Mon Sep 17 00:00:00 2001 From: Brandon Hudson Date: Tue, 30 Jul 2019 18:35:28 -0400 Subject: [PATCH] Adds support for fetching cached images from http(s) --- services/ImageFormats.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/ImageFormats.js b/services/ImageFormats.js index 0a8f2ab..93a083c 100644 --- a/services/ImageFormats.js +++ b/services/ImageFormats.js @@ -49,7 +49,17 @@ module.exports = { if (cachedImage) { const url = uploadProvider.getPath(cachedImage); - const buffer = fs.readFileSync(url); + + let buffer = null; + + # If the url is an HTTP url, get the image from the external source + if (url.indexOf('http://') >= 0 || url.indexOf('https://') >= 0) { + const image = await Jimp.read(url); + buffer = await image.getBufferAsync(Jimp.AUTO); + } else { + buffer = fs.readFileSync(url); + } + return { mime: cachedImage.mime, buffer }; }