From e26635620e8f2efe89431536bcd90bc3e69c76a3 Mon Sep 17 00:00:00 2001 From: Rish Date: Thu, 11 Jul 2019 12:58:08 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20theme=20upload=20error?= =?UTF-8?q?=20when=20overriding=20existing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - Cache invalidation header was set wrongly in frontend theme service - This moves cache invalidation out of theme service to themes controller by passing `themeOverriden` flag along with theme --- core/frontend/services/themes/storage.js | 11 ++++++----- core/server/api/v0.1/themes.js | 2 +- core/server/api/v2/themes.js | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/frontend/services/themes/storage.js b/core/frontend/services/themes/storage.js index d21cac25b3..fadb418fad 100644 --- a/core/frontend/services/themes/storage.js +++ b/core/frontend/services/themes/storage.js @@ -69,17 +69,18 @@ module.exports = { return themeLoader.loadOneTheme(shortName); }) .then((loadedTheme) => { + const overrideTheme = (shortName === settingsCache.get('active_theme')); // CASE: if this is the active theme, we are overriding - if (shortName === settingsCache.get('active_theme')) { + if (overrideTheme) { debug('Activating theme (method C, on API "override")', shortName); activate(loadedTheme, checkedTheme); - - // CASE: clear cache - this.headers.cacheInvalidate = true; } // @TODO: unify the name across gscan and Ghost! - return toJSON(shortName, checkedTheme); + return { + themeOverridden: overrideTheme, + theme: toJSON(shortName, checkedTheme) + }; }) .finally(() => { // @TODO: we should probably do this as part of saving the theme diff --git a/core/server/api/v0.1/themes.js b/core/server/api/v0.1/themes.js index 293ac83184..4e4e9b0a41 100644 --- a/core/server/api/v0.1/themes.js +++ b/core/server/api/v0.1/themes.js @@ -74,7 +74,7 @@ themes = { .then(() => { return themeService.storage.setFromZip(zip); }) - .then((theme) => { + .then(({theme}) => { common.events.emit('theme.uploaded'); return theme; }); diff --git a/core/server/api/v2/themes.js b/core/server/api/v2/themes.js index 19b16ea1dc..bc5c6301cd 100644 --- a/core/server/api/v2/themes.js +++ b/core/server/api/v2/themes.js @@ -61,7 +61,11 @@ module.exports = { }; return themeService.storage.setFromZip(zip) - .then((theme) => { + .then(({theme, themeOverriden}) => { + if (themeOverriden) { + // CASE: clear cache + this.headers.cacheInvalidate = true; + } common.events.emit('theme.uploaded'); return theme; });