Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
isOnline(function(err, internetOnline) {
if (internetOnline) {
// Is pushover reachable
isReachable('api.pushover.net:443', function(error, reachable) {
if (reachable) {
debug.log('We are online again')
clearInterval(checkInternetInterval)
online()
}
checkingInternet = false
})
}
else {
checkingInternet = false
}
})
}
export async function getModels() {
const tcUrl = new URL('models', tcServer);
const msTimeout = 1000;
if (!(await isReachable(tcUrl.href, { timeout: msTimeout }))) {
// TODO: move this backend check to server start-up time, maybe
return {
models: {},
error: `Topic Classification server is unreachable (${msTimeout})`,
};
}
return fetch(tcUrl.href, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => res.json())
.catch(err => {
return {
models: {},
export async function checkModelReady(arg: { model: string }) {
const tcUrl = new URL('models', tcServer);
tcUrl.searchParams.set('model', arg.model);
const msTimeout = 1000;
if (!(await isReachable(tcUrl.href, { timeout: msTimeout }))) {
// TODO: move this backend check to server start-up time, maybe
return { models: {}, error: `Topic Classification server is unreachable (${msTimeout})` };
}
return fetch(tcUrl.href, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => res.json())
.catch(err => {
return {
models: '',
error: `Error from topic-classification server: ${err.toString()}`,
};
});
private async getPeer(): Promise<{ ip: string; port: number }> {
const peer: { ip: string; port: number } = sample(this.getPeers());
const reachable: boolean = await isReachable(`${peer.ip}:${peer.port}`);
if (!reachable) {
this.logger.warn(`${peer} is unresponsive. Choosing new peer.`);
return this.getPeer();
}
return peer;
}
return new Promise((resolve, reject) => {
isReachable(dests, (err, reachable) => {
if (err) {
reject(err);
} else {
resolve(reachable);
}
});
});
}