Allow module to provide resources and automatically expose them

This commit is contained in:
Nick O'Leary
2021-03-15 21:06:10 +00:00
parent 827f8d4d51
commit 8543613563
8 changed files with 94 additions and 5 deletions

View File

@@ -75,6 +75,8 @@ module.exports = {
editorApp.get("/icons/:module/:icon",ui.icon);
editorApp.get("/icons/:scope/:module/:icon",ui.icon);
editorApp.get(/^\/resources\/((?:@[^\/]+\/)?[^\/]+)\/(.+)$/,ui.moduleResource);
var theme = require("./theme");
theme.init(settings, runtimeAPI);
editorApp.use("/theme",theme.app());

View File

@@ -68,6 +68,28 @@ module.exports = {
apiUtils.rejectHandler(req,res,err);
})
},
moduleResource: function(req, res) {
let resourcePath = req.params[1];
let opts = {
user: req.user,
module: req.params[0],
path: resourcePath
}
runtimeAPI.nodes.getModuleResource(opts).then(function(data) {
if (data) {
var contentType = mime.getType(resourcePath);
res.set("Content-Type", contentType);
res.send(data);
} else {
res.status(404).end()
}
}).catch(function(err) {
console.log(err.stack);
apiUtils.rejectHandler(req,res,err);
})
},
editor: async function(req,res) {
res.send(Mustache.render(editorTemplate,await theme.context()));
},