Skip to content

Commit

Permalink
full support for flowhub with token
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Riessen committed Apr 1, 2024
1 parent 13f2ac1 commit 9c50daf
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
73 changes: 65 additions & 8 deletions red/deadred.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ var DEADRED = (function() {
// to the deadred server.
let deadredRedirectablesAjax = [
"FlowHubDiff",
"FlowHubPush",
"NodeFactorySidebarCfg"
];

Expand All @@ -875,29 +874,87 @@ var DEADRED = (function() {

// patial functionality provided by the deadred backend
if ( deadredRedirectablesAjax.indexOf( options.url ) > -1 ) {
options.url = RED.settings.get("dynamicServer", "") + options.url
}

if ( options.url == "FlowHubPush" ) {
options.success({})
jqXHR.abort()

let cfgNode = undefined

RED.nodes.eachConfig( nd => {
if ( nd.type == "FlowHubCfg" ) {
cfgNode = nd
}
})

if ( cfgNode && cfgNode.apiToken != "" ) {
let data = JSON.parse(options.data)

let postData = {
flowid: data.flowid,
flowdata: data.flowdata,
flowlabel: data.flowlabel,
svgdata: data.svgdata,
nodedetails: data.nodedetails,
flowrevision: (cfgNode.flowrevisions || {})[data.flowid] || "",
pushcomment: cfgNode.pushcomment,
pushnewflows: JSON.parse(cfgNode.pushnewflows),
forcepush: JSON.parse(cfgNode.forcepush),
}

if ( options.url == "FlowHubPush" ) {
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
headers: {
"Authorization": "Bearer " + cfgNode.apiToken
},
url: RED.settings.get("dynamicServer", "") + "v1/flows",
data: JSON.stringify(postData),
success: (resp) => {
RED.comms.emit([
{
topic: "flowhub:submission-result",
data: {
status: resp.msg,
statusType: resp.status == "failed" ? "error" : "success",
}
}
])
},
});
} else {
setTimeout( () => {
RED.comms.emit( [
RED.comms.emit([
{
topic: "flowhub:submission-result",
data: {
status: "Succeeded",
statusType: "success"
status: "No FlowHub.org token set - <a target=_blank href='https://flowhub.org/integration'>Get your token <i class='fa fa-external-link'></i></a>.",
statustype: "error"
}
}
])
}, 4345)
}, 1234)
}

options.url = RED.settings.get("dynamicServer", "") + options.url
return
}

// Token retrieval
mth = options.url.match(/^FlowHubToken/i)
if ( mth ) {
let cfgNode = undefined

RED.nodes.eachConfig( nd => {
if ( nd.type == "FlowHubCfg" ) {
cfgNode = nd
}
})

options.success({
"token": "xxx",
"token": (cfgNode ? cfgNode.apiToken : "xxx"),
})

jqXHR.abort();
Expand Down
27 changes: 26 additions & 1 deletion red/red.cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,32 @@ var RED = (function() {
cache: false,
url: srv + 'flows',
success: function(nodes) {

let updateData = {
flowid: nodes.flowid,
revision: nodes.revision,
token: nodes.token
}

setTimeout( () => {
try {
let cfgNode = undefined
RED.nodes.eachConfig( nd => {
if ( nd.type == "FlowHubCfg" ) {
cfgNode = nd
}
})

$("#node-input-flowhubpush-new-token-field").val( updateData.token)
$('#node-input-flowhubpush-new-token-name-field').val("first token")
$('#node-input-flowhubpush-add-token-btn').trigger('click')
cfgNode.apiToken = updateData.token
$("#node-input-flowhubpush-apiToken").typedInput('value', updateData.token);
$("#node-input-flowhubpush-apiToken").typedInput('type', 'cred');
} catch (ew) {}
}, 5000)


if (nodes) {
var currentHash = window.location.hash;
// store the initial flow to local storage for the
Expand Down Expand Up @@ -1003,7 +1029,6 @@ var RED = (function() {
})
}
}

});

RED.workspaces.init();
Expand Down

0 comments on commit 9c50daf

Please sign in to comment.