From 8137e4bd3fb67a6afdb05a8b98f7b65193f2960b Mon Sep 17 00:00:00 2001 From: chughts Date: Sun, 16 Oct 2016 17:33:23 +0100 Subject: [PATCH] fixed translator to work nicely with file inject --- README.md | 3 +++ package.json | 2 +- services/language_translator/v2.js | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 44309dd8..5247fa87 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix CLA assistant +### New in version 0.4.23 +- Fix to Language Translator Train Node to allow it work with File Inject + ### New in version 0.4.22 - Added new Date Extraction Node - Visual Recognition Node, now defaults detection setting and language on initial initialisation. diff --git a/package.json b/package.json index 3f52b235..3ec301be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-watson", - "version": "0.4.22", + "version": "0.4.23", "description": "A collection of Node-RED nodes for IBM Watson services", "dependencies": { "alchemy-api": "^1.3.0", diff --git a/services/language_translator/v2.js b/services/language_translator/v2.js index d2dbba8a..de97ded7 100644 --- a/services/language_translator/v2.js +++ b/services/language_translator/v2.js @@ -176,6 +176,9 @@ module.exports = function (RED) { // If training is requested then the glossary will be a file input. We are using temp // to sync up the fetch of the file input stream, before invoking the train service. + // If the file comes from a file-inject then the file will not have a filename assoicated + // with it. In this case a temporary filename is given to the file. The file name submitted + // to the service cannot have a '.' else it will throw a 400 error. var doTrain = function(msg, model_id, filetype){ node.status({ fill: 'blue', @@ -189,8 +192,13 @@ module.exports = function (RED) { if (!err) { fs.write(info.fd, msg.payload); var params = {}; + // only letters and numbers allowed in the submitted file name - params.name = msg.filename.replace(/[^0-9a-z]/gi, ''); + // Default the name to a string representing now + params.name = (new Date()).toString().replace(/[^0-9a-z]/gi, ''); + if (msg.filename) { + params.name = msg.filename.replace(/[^0-9a-z]/gi, ''); + } params.base_model_id = model_id; switch (filetype) { case 'forcedglossary':