2016-08-26 14:19:03 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2017-11-02 17:05:37 +01:00
|
|
|
const exec = require('child_process').execSync;
|
2018-03-23 12:44:17 +01:00
|
|
|
const _ = require('lodash');
|
2016-11-24 16:19:01 +01:00
|
|
|
|
2016-08-26 14:19:03 +02:00
|
|
|
/**
|
|
|
|
* A set of functions called "actions" for `Admin`
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
2018-03-08 10:32:01 +01:00
|
|
|
getCurrentEnvironment: async ctx => {
|
|
|
|
try {
|
|
|
|
ctx.send({ currentEnvironment: strapi.app.env });
|
|
|
|
} catch(err) {
|
2018-05-15 16:08:47 -04:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2018-03-08 10:32:01 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-12 23:45:17 +02:00
|
|
|
getStrapiVersion: async ctx => {
|
|
|
|
try {
|
|
|
|
const strapiVersion = _.get(strapi.config, 'info.strapi', null);
|
|
|
|
return ctx.send({ strapiVersion });
|
|
|
|
} catch(err) {
|
|
|
|
return ctx.badRequest(null, [{ messages: [{ id: 'The version is not available' }] }]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-05 11:13:49 +02:00
|
|
|
getGaConfig: async ctx => {
|
2018-03-23 12:44:17 +01:00
|
|
|
try {
|
|
|
|
const allowGa = _.get(strapi.config, 'info.customs.allowGa', true);
|
|
|
|
ctx.send({ allowGa });
|
|
|
|
} catch(err) {
|
2018-05-15 16:08:47 -04:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2018-03-23 12:44:17 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-05 11:13:49 +02:00
|
|
|
getLayout: async ctx => {
|
|
|
|
try {
|
|
|
|
const layout = require('../config/layout.js');
|
|
|
|
|
|
|
|
return ctx.send({ layout });
|
|
|
|
} catch(err) {
|
2018-05-15 16:08:47 -04:00
|
|
|
return ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2018-04-05 11:13:49 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-12-16 17:35:16 +01:00
|
|
|
installPlugin: async ctx => {
|
|
|
|
try {
|
2017-12-20 11:23:50 +01:00
|
|
|
const { plugin, port } = ctx.request.body;
|
2017-12-16 17:35:16 +01:00
|
|
|
const strapiBin = path.join(process.cwd(), 'node_modules', 'strapi', 'bin', 'strapi');
|
|
|
|
|
|
|
|
strapi.reload.isWatching = false;
|
|
|
|
|
|
|
|
strapi.log.info(`Installing ${plugin}...`);
|
2018-03-08 10:32:01 +01:00
|
|
|
|
2018-04-19 13:10:34 +02:00
|
|
|
exec(`node "${strapiBin}" install ${plugin} ${port === '4000' ? '--dev' : ''}`);
|
2017-12-16 17:35:16 +01:00
|
|
|
|
|
|
|
ctx.send({ ok: true });
|
|
|
|
|
|
|
|
strapi.reload();
|
|
|
|
} catch(err) {
|
|
|
|
strapi.reload.isWatching = true;
|
2018-05-15 16:08:47 -04:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2017-12-16 17:35:16 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-09 11:25:01 +01:00
|
|
|
plugins: async ctx => {
|
|
|
|
try {
|
2017-11-09 13:30:54 +01:00
|
|
|
const plugins = Object.keys(strapi.plugins).reduce((acc, key) => {
|
|
|
|
acc[key] = strapi.plugins[key].package.strapi;
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
ctx.send({ plugins });
|
2017-11-09 11:25:01 +01:00
|
|
|
} catch(err) {
|
2018-05-15 16:08:47 -04:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2017-11-09 11:25:01 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
uninstallPlugin: async ctx => {
|
|
|
|
try {
|
|
|
|
const { plugin } = ctx.params;
|
2017-11-03 14:13:47 +01:00
|
|
|
const strapiBin = path.join(process.cwd(), 'node_modules', 'strapi', 'bin', 'strapi');
|
2017-11-02 17:05:37 +01:00
|
|
|
|
|
|
|
strapi.reload.isWatching = false;
|
|
|
|
|
|
|
|
strapi.log.info(`Uninstalling ${plugin}...`);
|
2018-04-19 15:49:16 +02:00
|
|
|
exec(`node "${strapiBin}" uninstall ${plugin}`);
|
2017-11-02 17:05:37 +01:00
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
ctx.send({ ok: true });
|
2017-11-02 17:05:37 +01:00
|
|
|
|
|
|
|
strapi.reload();
|
2017-11-02 16:49:10 +01:00
|
|
|
} catch(err) {
|
2017-11-02 17:05:37 +01:00
|
|
|
strapi.reload.isWatching = true;
|
2018-05-15 16:08:47 -04:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
2017-11-02 16:49:10 +01:00
|
|
|
}
|
2016-08-26 14:19:03 +02:00
|
|
|
}
|
|
|
|
};
|