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-09-26 17:28:40 +02:00
|
|
|
getGeneralSettings: function* () {
|
2016-09-25 18:52:15 +02:00
|
|
|
// Pick values from `strapi.config`
|
|
|
|
const settings = _.pick(strapi.config, [
|
|
|
|
'name',
|
|
|
|
'version',
|
|
|
|
'description'
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.body = settings;
|
2016-08-31 12:24:16 +02:00
|
|
|
},
|
|
|
|
|
2016-09-26 17:28:40 +02:00
|
|
|
updateSettings: function* () {
|
|
|
|
console.log('updateSettings', this.request.body);
|
|
|
|
|
|
|
|
const packageJSONPath = fs.readFileSync(path.resolve(strapi.config.appPath, 'package.json'));
|
|
|
|
const packageJSONContent = JSON.parse(packageJSONPath, 'utf8');
|
|
|
|
|
|
|
|
// Update application name
|
|
|
|
if (this.request.body.name) {
|
|
|
|
packageJSONContent.name = this.request.body.name;
|
|
|
|
fs.writeFileSync('package.json', JSON.stringify(packageJSONContent, null, 4), 'utf8');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.body = {
|
|
|
|
name: packageJSONContent.name
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
};
|