2020-05-22 21:22:20 +03:00
|
|
|
const {events} = require('../../lib/common');
|
2019-06-19 12:30:28 +03:00
|
|
|
const themeService = require('../../../frontend/services/themes');
|
2019-01-30 16:14:27 +03:00
|
|
|
const models = require('../../models');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
docName: 'themes',
|
|
|
|
|
|
|
|
browse: {
|
|
|
|
permissions: true,
|
|
|
|
query() {
|
2019-07-09 17:35:18 +03:00
|
|
|
return themeService.getJSON();
|
2019-01-30 16:14:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: {
|
|
|
|
headers: {
|
|
|
|
cacheInvalidate: true
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
'name'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
name: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
|
|
|
let themeName = frame.options.name;
|
|
|
|
const newSettings = [{
|
|
|
|
key: 'active_theme',
|
|
|
|
value: themeName
|
|
|
|
}];
|
|
|
|
|
2019-07-01 17:56:23 +03:00
|
|
|
return themeService.activate(themeName)
|
|
|
|
.then((checkedTheme) => {
|
2019-01-30 16:14:27 +03:00
|
|
|
// @NOTE: we use the model, not the API here, as we don't want to trigger permissions
|
2019-07-01 17:56:23 +03:00
|
|
|
return models.Settings.edit(newSettings, frame.options)
|
|
|
|
.then(() => checkedTheme);
|
2019-01-30 16:14:27 +03:00
|
|
|
})
|
2019-07-01 17:56:23 +03:00
|
|
|
.then((checkedTheme) => {
|
2019-07-09 17:35:18 +03:00
|
|
|
return themeService.getJSON(themeName, checkedTheme);
|
2019-01-30 16:14:27 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
upload: {
|
|
|
|
headers: {},
|
|
|
|
permissions: {
|
|
|
|
method: 'add'
|
|
|
|
},
|
|
|
|
query(frame) {
|
|
|
|
// @NOTE: consistent filename uploads
|
|
|
|
frame.options.originalname = frame.file.originalname.toLowerCase();
|
|
|
|
|
|
|
|
let zip = {
|
|
|
|
path: frame.file.path,
|
2019-07-01 17:56:23 +03:00
|
|
|
name: frame.file.originalname
|
2019-01-30 16:14:27 +03:00
|
|
|
};
|
|
|
|
|
2019-07-09 17:35:18 +03:00
|
|
|
return themeService.storage.setFromZip(zip)
|
2019-07-17 16:11:16 +03:00
|
|
|
.then(({theme, themeOverridden}) => {
|
|
|
|
if (themeOverridden) {
|
2019-07-11 10:28:08 +03:00
|
|
|
// CASE: clear cache
|
|
|
|
this.headers.cacheInvalidate = true;
|
|
|
|
}
|
2020-05-22 21:22:20 +03:00
|
|
|
events.emit('theme.uploaded');
|
2019-07-01 17:56:23 +03:00
|
|
|
return theme;
|
2019-01-30 16:14:27 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
download: {
|
|
|
|
options: [
|
|
|
|
'name'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
name: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: {
|
|
|
|
method: 'read'
|
|
|
|
},
|
|
|
|
query(frame) {
|
|
|
|
let themeName = frame.options.name;
|
|
|
|
|
2019-07-09 17:35:18 +03:00
|
|
|
return themeService.storage.getZip(themeName);
|
2019-01-30 16:14:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: {
|
|
|
|
statusCode: 204,
|
|
|
|
headers: {
|
|
|
|
cacheInvalidate: true
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
'name'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
name: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
|
|
|
let themeName = frame.options.name;
|
|
|
|
|
2019-07-09 17:35:18 +03:00
|
|
|
return themeService.storage.destroy(themeName);
|
2019-01-30 16:14:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|