55 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-08-26 14:19:03 +02:00
'use strict';
const fs = require('fs');
2016-08-26 14:19:03 +02:00
const path = require('path');
2016-08-26 14:19:03 +02:00
/**
* A set of functions called "actions" for `Admin`
*/
module.exports = {
index: async(ctx) => {
2017-01-04 18:28:47 +01:00
try {
// Send the HTML file with injected scripts
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
} catch (err) {
ctx.body = err;
}
2016-08-26 14:19:03 +02:00
},
2017-10-09 11:51:28 +02:00
pluginFile: async (ctx, next) => {
2017-05-17 11:21:03 +02:00
try {
2017-10-09 11:51:28 +02:00
// Will be served through the public middleware
if (ctx.params.plugin === 'plugins') {
return await next();
}
const file = fs.readFileSync(path.resolve(process.cwd(), 'plugins', ctx.params.plugin, 'admin', 'build', `${ctx.params.file}`));
2017-05-17 11:21:03 +02:00
ctx.body = file;
} catch (err) {
ctx.body = ctx.notFound();
}
},
2016-12-01 16:44:03 +01:00
file: async ctx => {
try {
const file = fs.readFileSync(path.resolve(__dirname, '..', 'admin', 'build', ctx.params.file));
ctx.body = file;
} catch (err) {
2017-08-18 14:21:09 +02:00
// Fallback, render admin page
ctx.body = strapi.admin.services.admin.generateAdminIndexFile();
}
},
uninstallPlugin: async ctx => {
try {
const { plugin } = ctx.params;
console.log('plugin', plugin);
ctx.send({ ok: true });
} catch(err) {
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
}
2016-08-26 14:19:03 +02:00
}
};