Skip to content

Commit 5baef75

Browse files
authored
Merge pull request #211 from chughts/torfixes
File Inject related Translator fix
2 parents ac63acf + 8137e4b commit 5baef75

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.4.23
11+
- Fix to Language Translator Train Node to allow it work with File Inject
12+
1013
### New in version 0.4.22
1114
- Added new Date Extraction Node
1215
- Visual Recognition Node, now defaults detection setting and language on initial initialisation.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.4.22",
3+
"version": "0.4.23",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",

services/language_translator/v2.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ module.exports = function (RED) {
176176

177177
// If training is requested then the glossary will be a file input. We are using temp
178178
// to sync up the fetch of the file input stream, before invoking the train service.
179+
// If the file comes from a file-inject then the file will not have a filename assoicated
180+
// with it. In this case a temporary filename is given to the file. The file name submitted
181+
// to the service cannot have a '.' else it will throw a 400 error.
179182
var doTrain = function(msg, model_id, filetype){
180183
node.status({
181184
fill: 'blue',
@@ -189,8 +192,13 @@ module.exports = function (RED) {
189192
if (!err) {
190193
fs.write(info.fd, msg.payload);
191194
var params = {};
195+
192196
// only letters and numbers allowed in the submitted file name
193-
params.name = msg.filename.replace(/[^0-9a-z]/gi, '');
197+
// Default the name to a string representing now
198+
params.name = (new Date()).toString().replace(/[^0-9a-z]/gi, '');
199+
if (msg.filename) {
200+
params.name = msg.filename.replace(/[^0-9a-z]/gi, '');
201+
}
194202
params.base_model_id = model_id;
195203
switch (filetype) {
196204
case 'forcedglossary':

0 commit comments

Comments
 (0)