Skip to content

Commit a6504b0

Browse files
committed
fixed upload config bug
1 parent 3c19f3e commit a6504b0

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

services/retrieve_and_rank/v1.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,6 @@
481481
<label for="node-input-configname"><i class="fa fa-tag"></i> Configuration Name</label>
482482
<input type="text" id="node-input-configname" placeholder="Configuration Name">
483483
</div>
484-
<div class="form-row mode configzippath">
485-
<label for="node-input-configzippath"><i class="fa fa-tag"></i> Configuration .zip File Path</label>
486-
<input type="text" id="node-input-configzippath" placeholder="Configuration .zip File Path">
487-
</div>
488484
</script>
489485

490486
<script type="text/x-red" data-help-name="watson-retrieve-rank-upload-solr-configuration">
@@ -498,8 +494,7 @@
498494
defaults: {
499495
name: {value: ""},
500496
clusterid: {value: "", required: true},
501-
configname: {value: "", required: true},
502-
configzippath: {value: "", required: true}
497+
configname: {value: "", required: true}
503498
},
504499
credentials: {
505500
username: {type:"text"},

services/retrieve_and_rank/v1.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,42 @@ module.exports = function (RED) {
227227

228228
this.on('input', function(msg) {
229229
setupRankRetrieveNode(msg,config,this,function(retrieve_and_rank) {
230-
var params = {
231-
cluster_id: config.clusterid,
232-
config_name: config.configname,
233-
config_zip_path: config.configzippath
234-
};
235-
if (!params.cluster_id || !params.config_name || !params.config_zip_path) {
236-
var message = 'No cluster id, configuration name or .zip file path specified';
237-
node.error(message, msg)
230+
231+
//zip file comes in on msg.payload as buffer
232+
if (!msg.payload instanceof Buffer) {
233+
var message = 'Invalid property: msg.payload, must be a Buffer.';
234+
node.error(message, msg);
238235
return;
239236
}
240-
node.status({fill: 'blue', shape: 'ring', text: 'Uploading solr configuration...' });
241-
retrieve_and_rank.uploadConfig(params, function (err, res) {
242-
node.status({});
243-
handleWatsonCallback(null,node,msg,err,res);
237+
238+
var uploadConfig = function(filePath,cb) {
239+
var params = {
240+
cluster_id: config.clusterid,
241+
config_name: config.configname,
242+
config_zip_path: filePath
243+
};
244+
if (!params.cluster_id || !params.config_name) {
245+
var message = 'No cluster id or configuration name specified';
246+
return node.error(message, msg);
247+
}
248+
node.status({fill: 'blue', shape: 'ring', text: 'Uploading solr configuration...' });
249+
retrieve_and_rank.uploadConfig(params, function (err, res) {
250+
node.status({});
251+
handleWatsonCallback(null,node,msg,err,res);
252+
});
253+
}
254+
255+
var stream_buffer = function (file, contents, cb) {
256+
fs.writeFile(file, contents, function (err) {
257+
if (err) throw err;
258+
cb(file);
259+
});
260+
};
261+
temp.open({suffix: '.zip'}, function (err, info) {
262+
if (err) throw err;
263+
stream_buffer(info.path, msg.payload, function (file) {
264+
uploadConfig(file, temp.cleanup);
265+
});
244266
});
245267
});
246268
});

0 commit comments

Comments
 (0)