strapi/controllers/SettingsManager.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-08-26 14:07:57 +02:00
'use strict';
2016-08-31 12:24:16 +02:00
const sendfile = require('koa-sendfile');
const path = require('path');
2016-09-25 18:52:15 +02:00
const _ = require('lodash');
2016-09-26 17:28:40 +02:00
const fs = require('fs');
2016-08-31 12:24:16 +02:00
2016-08-26 14:07:57 +02:00
/**
* A set of functions called "actions" for `SettingsManager`
*/
module.exports = {
2016-11-22 12:05:37 +01:00
getGeneralSettings: function*() {
2016-09-25 18:52:15 +02:00
// Pick values from `strapi.config`
const settings = _.pick(strapi.config, [
'name',
'version',
2016-11-22 12:05:37 +01:00
'description'
2016-09-25 18:52:15 +02:00
]);
this.body = settings;
2016-08-31 12:24:16 +02:00
},
2016-11-22 12:05:37 +01:00
updateSettings: function*() {
2016-10-04 16:31:52 +02:00
var data = this.request.body;
try {
2016-10-05 15:15:43 +02:00
const settingsUpdated = yield strapi.plugins['settings-manager'].services.settingsservice.configurationsManager(strapi, data);
2016-10-04 16:31:52 +02:00
this.body = settingsUpdated.values;
} catch (err) {
this.status = err && err.status || 400;
return this.body = {
message: err.msg || 'An error occurred during settings update'
};
2016-11-22 12:05:37 +01:00
}
2016-09-26 17:28:40 +02:00
},
2016-11-22 12:05:37 +01:00
file: function*() {
2016-08-31 12:24:16 +02:00
yield sendfile(this, path.resolve(__dirname, '..', 'public', 'build', this.params.file));
if (!this.status) this.throw(404);
2016-08-26 14:07:57 +02:00
}
};