Skip to content

Commit

Permalink
Ignoring unavailable mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
steel97 committed Oct 27, 2022
1 parent 039068a commit 4948d76
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/server/api/getmirrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,42 @@ const getMirrors = async () => {
let resultMirrors: Array<Mirror> = [];

for (const mirror of networkMirrors) {
const mirrorName = mirror.name;
const mirrorPath = mirror.path;

// get available snapshots
const snapshotInfo = (await $fetch(`${mirrorPath}snapshot.json`)) as any;

// construct data of mirror
const resultMirror: Mirror = {
name: mirrorName,
path: mirrorPath,
snapshots: Array<Snapshot>()
};

const snapshotResult: Array<Snapshot> = [];

for (const snapshot of snapshotInfo.snapshots) {
try {
const hash = ((await $fetch(`${mirrorPath}${snapshot.sha256}`)) as string).split(" ")[0];
snapshotResult.unshift({
name: snapshot.name as string,
sha256: hash,
block: snapshot.block as string,
date: snapshot.date as string
});
} catch {
// thrown if one of snapshots not found
try {
const mirrorName = mirror.name;
const mirrorPath = mirror.path;

// get available snapshots
const snapshotInfo = (await $fetch(`${mirrorPath}snapshot.json`)) as any;

// construct data of mirror
const resultMirror: Mirror = {
name: mirrorName,
path: mirrorPath,
snapshots: Array<Snapshot>()
};

const snapshotResult: Array<Snapshot> = [];

for (const snapshot of snapshotInfo.snapshots) {
try {
const hash = ((await $fetch(`${mirrorPath}${snapshot.sha256}`)) as string).split(" ")[0];
snapshotResult.unshift({
name: snapshot.name as string,
sha256: hash,
block: snapshot.block as string,
date: snapshot.date as string
});
} catch {
// thrown if one of snapshots not found
}
}
}

resultMirror.snapshots = snapshotResult;
resultMirror.snapshots = snapshotResult;

resultMirrors.push(resultMirror);
} catch {

resultMirrors.push(resultMirror);
}
}

result.timestamp = cTime;
Expand Down

0 comments on commit 4948d76

Please sign in to comment.