🐛 Fixed theme upload error when overriding existing

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
This commit is contained in:
Rish 2019-07-11 12:58:08 +05:30 committed by Rishabh Garg
parent f3ec2fb2f7
commit e26635620e
3 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -74,7 +74,7 @@ themes = {
.then(() => {
return themeService.storage.setFromZip(zip);
})
.then((theme) => {
.then(({theme}) => {
common.events.emit('theme.uploaded');
return theme;
});

View File

@ -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;
});