Skip to content

Commit

Permalink
Merge pull request #164 from arlemi/master
Browse files Browse the repository at this point in the history
Check on the URL validity for Document conversion
  • Loading branch information
chughts committed Jul 20, 2016
2 parents 70626f7 + 0239c60 commit 72ebb97
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions services/document_conversion/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,46 @@ module.exports = function(RED) {
version: 'v1',
version_date: '2015-12-01'
});

temp.open({
suffix: '.cvt'
}, function(err, info) {
if (err) {
throw err;
}
var stream_payload = (typeof msg.payload === 'string') ? payloadutils.stream_url : payloadutils.stream_buffer;

stream_payload(info.path, msg.payload, function(format) {
node.status({
fill: 'blue',
shape: 'dot',
text: 'converting'
});
document_conversion.convert({
file: fs.createReadStream(info.path),
conversion_target: msg.target || node.target,
word: msg.word,
pdf: msg.pdf,
normalized_html: msg.normalized_html
}, function(err, response) {
node.status({});
if (err) {
node.error(err);
} else {
node.send({
'payload': response
});
}
});
});
if(typeof msg.payload === 'string' && !payloadutils.urlCheck(msg.payload)) {
node.warn('Invalid URI, make sure to include the "http(s)" at the beginning.');
node.status({
fill: 'red',
shape: 'dot',
text: 'Invalid URI'
});
} else {
stream_payload(info.path, msg.payload, function(format) {
node.status({
fill: 'blue',
shape: 'dot',
text: 'converting'
});
document_conversion.convert({
file: fs.createReadStream(info.path),
conversion_target: msg.target || node.target,
word: msg.word,
pdf: msg.pdf,
normalized_html: msg.normalized_html
}, function(err, response) {
node.status({});
if (err) {
node.error(err);
} else {
node.send({
'payload': response
});
}
});
});
}
});
};
this.on('input', function(msg) {
Expand Down

0 comments on commit 72ebb97

Please sign in to comment.