Initial release v1.0.0 — Nextcloud Collabora Node-RED sidecar
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
'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,
|
||||
createAssetLink: bridge.createAssetLink
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
Reference in New Issue
Block a user