From f33a9185ff4719330cce8aa89db843434617433e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 23 Nov 2020 12:19:19 -0500 Subject: [PATCH] fix: on OP edit, call helper method to upload and resize thumb --- src/posts/edit.js | 6 +++++- src/topics/thumb.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/posts/edit.js b/src/posts/edit.js index 4bcb8a4d9f..667c1b0553 100644 --- a/src/posts/edit.js +++ b/src/posts/edit.js @@ -122,7 +122,11 @@ module.exports = function (Posts) { newTopicData.title = title; newTopicData.slug = tid + '/' + (slugify(title) || 'topic'); } - newTopicData.thumb = data.thumb || ''; + + if (data.thumb) { + await topics.resizeAndUploadThumb(data); + newTopicData.thumb = data.thumb; + } data.tags = data.tags || []; diff --git a/src/topics/thumb.js b/src/topics/thumb.js index f32c4fa96d..1423e3382e 100644 --- a/src/topics/thumb.js +++ b/src/topics/thumb.js @@ -23,6 +23,7 @@ module.exports = function (Topics) { const pipeToFileAsync = util.promisify(pipeToFile); Topics.resizeAndUploadThumb = async function (data) { + // Only continue if passed in thumbnail exists and is a URL. A system path means an upload is not necessary. if (!data.thumb || !validator.isURL(data.thumb)) { return; }