28 lines
669 B
JavaScript
Raw Normal View History

'use strict';
const _ = require('lodash');
module.exports = async (ctx, next) => {
2019-08-21 11:05:33 +02:00
const { model } = ctx.params;
2019-11-15 11:49:32 +01:00
const ct = strapi.contentTypes[model];
if (!ct) {
return ctx.send({ error: 'contentType.notFound' }, 404);
}
const target = ct.plugin === 'admin' ? strapi.admin : strapi.plugins[ct.plugin];
2019-11-15 11:49:32 +01:00
const actionPath = ['config', 'layout', ct.modelName, 'actions', ctx.request.route.action];
2019-11-15 11:49:32 +01:00
if (_.has(target, actionPath)) {
const [controller, action] = _.get(target, actionPath, []).split('.');
if (controller && action) {
return await target.controllers[controller.toLowerCase()][action](ctx);
}
}
await next();
};