@knapsack/app
Version:
Build Design Systems on top of knapsack, by Basalt
48 lines (37 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.handlePluginsEndpoint = handlePluginsEndpoint;
var _bootstrap = require("../../lib/bootstrap");
var _plugins = require("../../schemas/api/plugins");
async function handlePluginsEndpoint(req, res) {
var _getBrain, _getBrain$config;
const reqBody = req.body;
const response = {
type: reqBody.type,
ok: true,
payload: {}
};
const plugins = (_getBrain = (0, _bootstrap.getBrain)()) === null || _getBrain === void 0 ? void 0 : (_getBrain$config = _getBrain.config) === null || _getBrain$config === void 0 ? void 0 : _getBrain$config.plugins;
if (!plugins) {
response.message = `Plugins not loaded at all! Probably the server's fault.`;
response.ok = false;
}
const plugin = plugins === null || plugins === void 0 ? void 0 : plugins.find(p => p.id === (reqBody === null || reqBody === void 0 ? void 0 : reqBody.pluginId));
if (!plugin) {
response.message = `Plugin not found for id: "${reqBody.pluginId}"`;
response.ok = false;
}
if (!response.ok) {
return res.send(response);
}
switch (reqBody.type) {
case _plugins.ACTIONS.getContent:
{
response.payload = await plugin.loadContent();
break;
}
}
return res.send(response);
}