mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Include module name in requests for node icons
This commit is contained in:
@@ -94,7 +94,7 @@ function init(_server,_runtime) {
|
||||
});
|
||||
}
|
||||
editorApp.get("/",ensureRuntimeStarted,ui.ensureSlash,ui.editor);
|
||||
editorApp.get("/icons/:icon",ui.icon);
|
||||
editorApp.get("/icons/:module/:icon",ui.icon);
|
||||
theme.init(runtime);
|
||||
if (settings.editorTheme) {
|
||||
editorApp.use("/theme",theme.app());
|
||||
|
@@ -21,7 +21,9 @@ var theme = require("./theme");
|
||||
|
||||
var Mustache = require("mustache");
|
||||
|
||||
var icon_paths = [path.resolve(__dirname + '/../../public/icons')];
|
||||
var icon_paths = {
|
||||
"node-red":[path.resolve(__dirname + '/../../public/icons')]
|
||||
};
|
||||
var iconCache = {};
|
||||
//TODO: create a default icon
|
||||
var defaultIcon = path.resolve(__dirname + '/../../public/icons/arrow-in.png');
|
||||
@@ -29,7 +31,8 @@ var templateDir = path.resolve(__dirname+"/../../editor/templates");
|
||||
var editorTemplate;
|
||||
|
||||
function nodeIconDir(dir) {
|
||||
icon_paths.push(path.resolve(dir));
|
||||
icon_paths[dir.name] = icon_paths[dir.name] || [];
|
||||
icon_paths[dir.name].push(path.resolve(dir.path));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -54,18 +57,24 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
icon: function(req,res) {
|
||||
if (iconCache[req.params.icon]) {
|
||||
res.sendFile(iconCache[req.params.icon]); // if not found, express prints this to the console and serves 404
|
||||
var icon = req.params.icon;
|
||||
var module = req.params.module;
|
||||
var iconName = module+"/"+icon;
|
||||
if (iconCache[iconName]) {
|
||||
res.sendFile(iconCache[iconName]); // if not found, express prints this to the console and serves 404
|
||||
} else {
|
||||
for (var p=0;p<icon_paths.length;p++) {
|
||||
var iconPath = path.join(icon_paths[p],req.params.icon);
|
||||
try {
|
||||
fs.statSync(iconPath);
|
||||
res.sendFile(iconPath);
|
||||
iconCache[req.params.icon] = iconPath;
|
||||
return;
|
||||
} catch(err) {
|
||||
// iconPath doesn't exist
|
||||
var paths = icon_paths[module];
|
||||
if (paths) {
|
||||
for (var p=0;p<paths.length;p++) {
|
||||
var iconPath = path.join(paths[p],icon);
|
||||
try {
|
||||
fs.statSync(iconPath);
|
||||
res.sendFile(iconPath);
|
||||
iconCache[iconName] = iconPath;
|
||||
return;
|
||||
} catch(err) {
|
||||
// iconPath doesn't exist
|
||||
}
|
||||
}
|
||||
}
|
||||
res.sendFile(defaultIcon);
|
||||
|
@@ -89,7 +89,7 @@ function getLocalNodeFiles(dir) {
|
||||
if (!/^(\..*|lib|icons|node_modules|test|locales)$/.test(fn)) {
|
||||
result = result.concat(getLocalNodeFiles(path.join(dir,fn)));
|
||||
} else if (fn === "icons") {
|
||||
events.emit("node-icon-dir",path.join(dir,fn));
|
||||
events.emit("node-icon-dir",{name:'node-red',path:path.join(dir,fn)});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -182,7 +182,7 @@ function getModuleNodeFiles(module) {
|
||||
if (iconDirs.indexOf(iconDir) == -1) {
|
||||
try {
|
||||
fs.statSync(iconDir);
|
||||
events.emit("node-icon-dir",iconDir);
|
||||
events.emit("node-icon-dir",{name:pkg.name,path:iconDir});
|
||||
iconDirs.push(iconDir);
|
||||
} catch(err) {
|
||||
}
|
||||
|
Reference in New Issue
Block a user