mirror of
https://github.com/yuto-yuto/node-red-contrib-password-generator.git
synced 2024-11-26 19:06:25 +01:00
26 lines
949 B
TypeScript
26 lines
949 B
TypeScript
import * as nodered from "node-red";
|
|
import { generatePassword } from "./PasswordGenerator";
|
|
import { PasswordGeneratorNodeDef } from "./PasswordGeneratorNodeDef";
|
|
import * as yutolity from "yutolity";
|
|
|
|
// it can't set to the input event listener now
|
|
// using any is workaround but not good
|
|
interface PayloadType extends nodered.NodeMessageInFlow {
|
|
to: string;
|
|
}
|
|
|
|
export = (RED: nodered.NodeAPI): void => {
|
|
RED.nodes.registerType("password-generator",
|
|
function (this: nodered.Node, config: PasswordGeneratorNodeDef): void {
|
|
RED.nodes.createNode(this, config);
|
|
|
|
this.on("input", async (msg: any, send, done) => {
|
|
const password = await generatePassword(config.length);
|
|
const valueSetPath = msg.to || config.setTo || "payload";
|
|
msg = yutolity.setValue(msg, valueSetPath, password);
|
|
send(msg);
|
|
done();
|
|
});
|
|
});
|
|
}
|