floBlockchainAPI v2.3.3
- If API is called when serverList is empty, reset the list and try again once
This commit is contained in:
parent
0683bf7318
commit
960aa1f52d
@ -1,4 +1,4 @@
|
|||||||
(function(EXPORTS) { //floBlockchainAPI v2.3.2a
|
(function(EXPORTS) { //floBlockchainAPI v2.3.3
|
||||||
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
|
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const floBlockchainAPI = EXPORTS;
|
const floBlockchainAPI = EXPORTS;
|
||||||
@ -46,7 +46,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const serverList = Array.from(floGlobals.apiURL && floGlobals.apiURL[DEFAULT.blockchain] ? floGlobals.apiURL[DEFAULT.blockchain] : DEFAULT.apiURL[DEFAULT.blockchain]);
|
const allServerList = new Set(floGlobals.apiURL && floGlobals.apiURL[DEFAULT.blockchain] ? floGlobals.apiURL[DEFAULT.blockchain] : DEFAULT.apiURL[DEFAULT.blockchain]);
|
||||||
|
|
||||||
|
var serverList = Array.from(allServerList);
|
||||||
var curPos = floCrypto.randInt(0, serverList - 1);
|
var curPos = floCrypto.randInt(0, serverList - 1);
|
||||||
|
|
||||||
function fetch_retry(apicall, rm_flosight) {
|
function fetch_retry(apicall, rm_flosight) {
|
||||||
@ -54,17 +56,24 @@
|
|||||||
let i = serverList.indexOf(rm_flosight)
|
let i = serverList.indexOf(rm_flosight)
|
||||||
if (i != -1) serverList.splice(i, 1);
|
if (i != -1) serverList.splice(i, 1);
|
||||||
curPos = floCrypto.randInt(0, serverList.length - 1);
|
curPos = floCrypto.randInt(0, serverList.length - 1);
|
||||||
fetch_api(apicall)
|
fetch_api(apicall, false)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch_api(apicall) {
|
function fetch_api(apicall, ic = true) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (serverList.length === 0)
|
if (serverList.length === 0) {
|
||||||
|
if (ic) {
|
||||||
|
serverList = Array.from(allServerList);
|
||||||
|
curPos = floCrypto.randInt(0, serverList.length - 1);
|
||||||
|
fetch_api(apicall, false)
|
||||||
|
.then(result => resolve(result))
|
||||||
|
.catch(error => reject(error));
|
||||||
|
} else
|
||||||
reject("No floSight server working");
|
reject("No floSight server working");
|
||||||
else {
|
} else {
|
||||||
let flosight = serverList[curPos];
|
let flosight = serverList[curPos];
|
||||||
fetch(flosight + apicall).then(response => {
|
fetch(flosight + apicall).then(response => {
|
||||||
if (response.ok)
|
if (response.ok)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user