node-red-contrib-micropub/micropub-create.js

29 lines
815 B
JavaScript
Raw Normal View History

2019-02-06 14:14:39 +00:00
var Micropub = require('micropub-helper');
module.exports = function (RED) {
function MicropubNode(config) {
RED.nodes.createNode(this, config);
this.endpoint = RED.nodes.getNode(config.endpoint);
var node = this;
node.on('input', function (msg) {
try {
const micropub = new Micropub({
micropubEndpoint: node.endpoint.credentials.micropub_endpoint,
token: node.endpoint.credentials.auth_token
});
var location = micropub.postMicropub(msg.payload);
msg.location = location;
node.send(msg);
} catch (e) {
node.error(e);
}
});
}
RED.nodes.registerType("micropub-create", MicropubNode);
}