mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #2903 from node-red/plugin-resources
Allow module to provide resources and automatically expose them
This commit is contained in:
@@ -463,5 +463,30 @@ var api = module.exports = {
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a resource from a module
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.module - the id of the module requesting the resource
|
||||
* @param {String} opts.path - the path of the resource
|
||||
* @param {Object} opts.req - the request to log (optional)
|
||||
* @return {Promise<Buffer>} - the resource file as a Buffer or null if not found
|
||||
* @memberof @node-red/runtime_nodes
|
||||
*/
|
||||
getModuleResource: async function(opts) {
|
||||
var resourcePath = runtime.nodes.getModuleResource(opts.module, opts.path);
|
||||
if (resourcePath) {
|
||||
return fs.readFile(resourcePath).catch(err => {
|
||||
if (err.code === 'EISDIR') {
|
||||
return null;
|
||||
}
|
||||
err.status = 400;
|
||||
throw err;
|
||||
});
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -230,6 +230,7 @@ module.exports = {
|
||||
getNodeIcons: registry.getNodeIcons,
|
||||
getNodeExampleFlows: registry.getNodeExampleFlows,
|
||||
getNodeExampleFlowPath: registry.getNodeExampleFlowPath,
|
||||
getModuleResource: registry.getModuleResource,
|
||||
|
||||
clearRegistry: registry.clear,
|
||||
cleanModuleList: registry.cleanModuleList,
|
||||
|
Reference in New Issue
Block a user