check if is online

This commit is contained in:
MathieuG-P
2022-07-24 16:29:20 +02:00
parent 865ea40a04
commit 2de356bbd1
4 changed files with 238 additions and 76 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ import { UtilsService } from './utils.service';
import path from 'path';
import { writeFileSync } from 'fs';
import { BSVersion } from 'shared/bs-version.interface';
import isOnline from 'is-online';
export class BSVersionLibService{
@@ -34,7 +35,7 @@ export class BSVersionLibService{
this.bsVersions = JSON.parse(body);
resolve(this.bsVersions);
});
res.on('error', (err) => reject(null))
res.on('error', () => reject(null))
})
})
}
@@ -52,7 +53,7 @@ export class BSVersionLibService{
private async loadBsVersions(): Promise<BSVersion[]>{
const [localVersions, remoteVersions] = await Promise.all([
this.getLocalVersions(), this.getRemoteVersions()
this.getLocalVersions(), (await isOnline({timeout: 1500}) && this.getRemoteVersions())
]);
let resVersions = localVersions;
if(remoteVersions && remoteVersions.length){ resVersions = remoteVersions; this.updateLocalVersions(resVersions); }