Enable use of string payload
This commit is contained in:
parent
a21c12068f
commit
0d8034eb5f
|
@ -34,8 +34,7 @@
|
||||||
<p>Posts to Micropub endpoints</p>
|
<p>Posts to Micropub endpoints</p>
|
||||||
<p>Connect to your Micropub powered blog and post messages.</p>
|
<p>Connect to your Micropub powered blog and post messages.</p>
|
||||||
<p>Input Parameters:</p>
|
<p>Input Parameters:</p>
|
||||||
<p><code>msg.type</code> - Default: 'json'
|
<p><code>msg.payload</code> - Should be an Micropub object using MF2, it will be sent without modification to the endpoint. If the payload is a string, it will be sent as a content value.</p>
|
||||||
<p><code>msg.payload</code> - Should be an Micropub object using MF2.</p>
|
|
||||||
<p><code>msg.payload.type</code> - Should be an array with the type.</p>
|
<p><code>msg.payload.type</code> - Should be an array with the type.</p>
|
||||||
<p><code>msg.payload.properties</code> - Should be on object with MF2 properties.</p>
|
<p><code>msg.payload.properties</code> - Should be on object with MF2 properties.</p>
|
||||||
<p><code>msg.payload.properties.name</code> - Should be an array with a string.</p>
|
<p><code>msg.payload.properties.name</code> - Should be an array with a string.</p>
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = function (RED) {
|
||||||
|
|
||||||
this.endpoint = RED.nodes.getNode(config.endpoint);
|
this.endpoint = RED.nodes.getNode(config.endpoint);
|
||||||
|
|
||||||
var node = this;
|
const node = this;
|
||||||
|
|
||||||
node.on('input', function (msg) {
|
node.on('input', function (msg) {
|
||||||
try {
|
try {
|
||||||
|
@ -14,8 +14,22 @@ module.exports = function (RED) {
|
||||||
micropubEndpoint: node.endpoint.credentials.micropub_endpoint,
|
micropubEndpoint: node.endpoint.credentials.micropub_endpoint,
|
||||||
token: node.endpoint.credentials.auth_token
|
token: node.endpoint.credentials.auth_token
|
||||||
});
|
});
|
||||||
var location = micropub.postMicropub(msg.payload);
|
|
||||||
msg.location = location;
|
let entry = {};
|
||||||
|
|
||||||
|
if (typeof msg.payload === 'string') {
|
||||||
|
entry.type = ['h-entry'];
|
||||||
|
entry.properties = {
|
||||||
|
content: [{
|
||||||
|
value: msg.payload
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
} else if (msg.payload.hasOwnProperty('type') && msg.payload.hasOwnProperty('properties')) {
|
||||||
|
entry = msg.payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.payload = entry;
|
||||||
|
msg.location = micropub.postMicropub(entry);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
node.error(e);
|
node.error(e);
|
||||||
|
@ -24,5 +38,5 @@ module.exports = function (RED) {
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("micropub-create", MicropubNode);
|
RED.nodes.registerType("micropub-create", MicropubNode);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user