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,43 @@
|
||||
'use strict';
|
||||
|
||||
const { getConfig, setError, setSuccess, clearStatus, pickMsgField } = require('../lib/utils');
|
||||
const { extractStructure } = require('../lib/collabora');
|
||||
const { loadSourceBuffer } = require('../lib/bridge');
|
||||
|
||||
module.exports = function (RED) {
|
||||
function CollaboraExtractNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
const node = this;
|
||||
node.configNode = RED.nodes.getNode(config.config);
|
||||
node.filter = config.filter || 'contentcontrol';
|
||||
|
||||
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 source = await loadSourceBuffer(cfg, msg);
|
||||
const filter = pickMsgField(msg, 'filter') || node.filter;
|
||||
const structure = await extractStructure(cfg, {
|
||||
buffer: source.buffer,
|
||||
filename: source.filename,
|
||||
filter
|
||||
});
|
||||
|
||||
msg.payload = structure;
|
||||
msg.structure = structure;
|
||||
setSuccess(node, msg, 'extract');
|
||||
send(msg);
|
||||
done();
|
||||
} catch (err) {
|
||||
setError(node, msg, err);
|
||||
send(msg);
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType('collabora-extract', CollaboraExtractNode);
|
||||
};
|
||||
Reference in New Issue
Block a user