2026-08-22 14:56:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const bridge = require('../lib/bridge');
|
|
|
|
|
const { getConfig, setError, setSuccess, clearStatus, pickMsgField } = require('../lib/utils');
|
|
|
|
|
|
|
|
|
|
const OPERATIONS = {
|
|
|
|
|
ncFileToPdf: bridge.ncFileToPdf,
|
|
|
|
|
ncFileToPng: bridge.ncFileToPng,
|
|
|
|
|
ncFileToHtml: bridge.ncFileToHtml,
|
|
|
|
|
htmlToOffice: bridge.htmlToOffice,
|
|
|
|
|
fillTemplateSave: bridge.fillTemplateSave,
|
|
|
|
|
compareVersionsPdf: bridge.compareVersionsPdf,
|
|
|
|
|
extractToPayload: bridge.extractToPayload,
|
2026-08-22 22:50:47 +02:00
|
|
|
createAssetLink: bridge.createAssetLink,
|
|
|
|
|
pickDemoSource: bridge.pickDemoSource
|
2026-08-22 14:56:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = function (RED) {
|
|
|
|
|
function CollaboraBridgeNode(config) {
|
|
|
|
|
RED.nodes.createNode(this, config);
|
|
|
|
|
const node = this;
|
|
|
|
|
node.configNode = RED.nodes.getNode(config.config);
|
|
|
|
|
node.operation = config.operation || 'ncFileToPdf';
|
|
|
|
|
|
|
|
|
|
node.on('input', async (msg, send, done) => {
|
|
|
|
|
send = send || function () { node.send.apply(node, arguments); };
|
|
|
|
|
done = done || function (err) { if (err) { node.error(err, msg); } };
|
|
|
|
|
clearStatus(node);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const cfg = getConfig(node);
|
|
|
|
|
const op = pickMsgField(msg, 'operation') || node.operation;
|
|
|
|
|
const fn = OPERATIONS[op];
|
|
|
|
|
if (!fn) {
|
|
|
|
|
throw new Error(`Okänd bridge-operation: ${op}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await fn(cfg, msg);
|
|
|
|
|
Object.assign(msg, result);
|
|
|
|
|
if (result.payload !== undefined) {
|
|
|
|
|
msg.payload = result.payload;
|
|
|
|
|
} else {
|
|
|
|
|
msg.payload = {
|
|
|
|
|
destNcPath: result.destNcPath,
|
|
|
|
|
filename: result.filename,
|
|
|
|
|
format: result.format,
|
|
|
|
|
assetUrl: result.assetUrl,
|
|
|
|
|
fields: result.fields,
|
|
|
|
|
structure: result.structure
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSuccess(node, msg, op);
|
|
|
|
|
send(msg);
|
|
|
|
|
done();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
setError(node, msg, err);
|
|
|
|
|
send(msg);
|
|
|
|
|
done(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RED.nodes.registerType('collabora-bridge', CollaboraBridgeNode);
|
|
|
|
|
};
|