Skip to content

Commit

Permalink
cleanup algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Jan 29, 2024
1 parent 0c55467 commit 2cfefc6
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions components/api-algorithm.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,29 @@
endpoint: config.endpoint,
}

// Inputs to this block will be saved in values Object
var inputData = $.data;

if (inputData.connection && inputData.url) {
var dbquery = "";
if (inputData.query && inputData.query.dbquery) {
dbquery = inputData.query.dbquery;
}
var payload = {
"algorithm": {
"source": config.algorithm,
"requirements": config.algorithmrequirements.split(' ').join('\n'),
"output": 'output'
},
"config": inputData
};
$.send('payload', payload);
let options = {
method: 'POST',
headers: {
'Content-Type':
'application/json;charset=utf-8'
},
body: JSON.stringify(payload)
}

// Sending request to get Data
let fetchRes = fetch(endpointData.endpoint,options);
fetchRes.then(res =>res.json())
.then(d => { $.send('output', d) })
.catch(err => { $.send('output', err) })

values.query = null;
} else {
// IMPORTANT: we must destroy the current message becase we don't need to send it next
$.destroy();
var payload = {
"algorithm": {
"source": config.algorithm,
"requirements": config.algorithmrequirements.split(' ').join('\n'),
"output": 'output'
},
"config": $.data || {}
};
$.send('payload', payload);
let options = {
method: 'POST',
headers: {
'Content-Type':
'application/json;charset=utf-8'
},
body: JSON.stringify(payload)
}

// Sending request to get Data
let fetchRes = fetch(endpointData.endpoint,options);
fetchRes.then(res =>res.json())
.then(d => { $.send('output', d) })
.catch(err => { $.send('output', err) })
};

instance.close = function() {
Expand Down

0 comments on commit 2cfefc6

Please sign in to comment.