UNPKG

node-red-contrib-filemaker

Version:

Node-RED FileMaker nodes. These nodes use the FileMaker Data API to connect with a FileMaker database.

59 lines (48 loc) 1.64 kB
module.exports = function(RED) { function upload(config) { const { send, handleError, constructParameters } = require("../services"); const { client, output, ...configuration } = config; RED.nodes.createNode(this, config); const node = this; node.client = RED.nodes.getNode(client); node.status({ fill: "blue", shape: "dot", text: "Loading" }); node.handleEvent = ({ connected, message }) => node.status( connected ? { fill: "green", shape: "dot", text: message } : { fill: "red", shape: "dot", text: message } ); /* istanbul ignore else */ if (node.client) node.client.on("status", node.handleEvent); node.on("input", async message => { node.status({ fill: "yellow", shape: "dot", text: "Processing" }); const { layout, field, file, recordId, ...parameters } = constructParameters(message, configuration, node.context(), [ "file", "layout", "field", "recordId", "parameters" ]); try { await this.client.connection; const client = await this.client.client; client .upload(file, layout, field, recordId, parameters) .then(response => send(node, output, message, response)) .catch(error => handleError(node, error.message, message)); } catch (error) { handleError(node, error.message, message); } }); node.on("close", () => node.client.removeListener("status", node.handleEvent) ); } RED.nodes.registerType("dapi-upload-file", upload); };