是否可以从 Node-RED 上的 80-template.html 和 10-function.html 文件中知道 运行 节点的用户?
Is it possible to know the user that is running a node from inside the 80-template.html and 10-function.html files on Node-RED?
Node-RED 使用 Ace editor
并且 Ace editor
有一个可以激活的 vim 模式。要在 Node-RED 上激活 vim 模式,我们需要执行以下 4 个步骤:
- 在 this GitHub 页上下载文件
keybindings-vim.js
。
- 将文件
keybindings-vim.js
保存到 /usr/local/lib/node_modules/node-red/node_modules/@node-red/editor-client/public/vendor/ace
(对于 Linux 用户)。
- 进入位于
/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/
的 80-template.html
或 10-function.html
代码并更改以下代码:
//// add this block ////
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
////
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();
- 重新启动 运行 Node-RED 服务。
这些步骤非常适合在特定 Node-RED 节点上激活 vim 模式。然而,
通过直接更改 80-template.html
或 10-function.html
文件,我将在系统上全局应用这些更改。这意味着将为使用不同 Node-RED 实例的所有系统用户激活 vim 模式。我想以只有我的用户可以访问的方式激活 vim 模式。可能吗?
我认为的解决方案是找到一种方法来获取登录 Node-RED 的用户的名称。伪代码是这样的:
const user = object.getUser();
if ( user === 'myuser' ){
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
}
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();
是否有任何命令允许我获取作为 运行 节点的 Node-RED 用户的名称?或者是否有任何替代答案可以将 vim 模式仅限于系统上 运行 的特定 Node-RED 实例?
正如 hardillb 在评论中所述,一种解决方案是安装与全局 运行 不同的 Node-RED 实例。
但是,也可以通过获取其端口号而不是用户名来区分哪个 Node-RED 实例是 运行。以下代码对我来说很好用:
const port = location.port;
if ( port === '1880' ){
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
}
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();
Node-RED 使用 Ace editor
并且 Ace editor
有一个可以激活的 vim 模式。要在 Node-RED 上激活 vim 模式,我们需要执行以下 4 个步骤:
- 在 this GitHub 页上下载文件
keybindings-vim.js
。 - 将文件
keybindings-vim.js
保存到/usr/local/lib/node_modules/node-red/node_modules/@node-red/editor-client/public/vendor/ace
(对于 Linux 用户)。 - 进入位于
/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/
的80-template.html
或10-function.html
代码并更改以下代码:
//// add this block ////
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
////
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();
- 重新启动 运行 Node-RED 服务。
这些步骤非常适合在特定 Node-RED 节点上激活 vim 模式。然而,
通过直接更改 80-template.html
或 10-function.html
文件,我将在系统上全局应用这些更改。这意味着将为使用不同 Node-RED 实例的所有系统用户激活 vim 模式。我想以只有我的用户可以访问的方式激活 vim 模式。可能吗?
我认为的解决方案是找到一种方法来获取登录 Node-RED 的用户的名称。伪代码是这样的:
const user = object.getUser();
if ( user === 'myuser' ){
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
}
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();
是否有任何命令允许我获取作为 运行 节点的 Node-RED 用户的名称?或者是否有任何替代答案可以将 vim 模式仅限于系统上 运行 的特定 Node-RED 实例?
正如 hardillb 在评论中所述,一种解决方案是安装与全局 运行 不同的 Node-RED 实例。
但是,也可以通过获取其端口号而不是用户名来区分哪个 Node-RED 实例是 运行。以下代码对我来说很好用:
const port = location.port;
if ( port === '1880' ){
this.editor.setKeyboardHandler("ace/keyboard/vim");
setTimeout(function() {
let panel = $(".ace_text-input");
panel.focus();
},600);
}
RED.library.create({
url:"templates", // where to get the data from
type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to
fields:['name','format','output','syntax'],
ext: "txt"
});
this.editor.focus();