mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
Update web-torrent-data.ts
Small adjustment to webTorrentData logic
This commit is contained in:
parent
d8937b3672
commit
d924c64710
@ -5,25 +5,34 @@ type WebTorrentHealthData = {
|
||||
peers: number;
|
||||
};
|
||||
|
||||
const MILLISECONDS = 1000;
|
||||
const SECONDS = 1.5;
|
||||
|
||||
export const webTorrentData = {
|
||||
async getSeedersAndPeers(
|
||||
magnet: string
|
||||
): Promise<{ seeders: number; peers: number }> {
|
||||
): Promise<{ seeders: number; peers: number } | null> {
|
||||
let peers = 0;
|
||||
let seeds = 0;
|
||||
let retry = 0;
|
||||
let timeout = SECONDS * MILLISECONDS;
|
||||
|
||||
while (retry < 3 && (!peers || !seeds)) {
|
||||
while (retry < 3) {
|
||||
try {
|
||||
const data: WebTorrentHealthData = await webTorrentHealth(magnet, {
|
||||
timeout: 1500 * (retry + 1),
|
||||
timeout,
|
||||
});
|
||||
|
||||
peers = data.peers;
|
||||
seeds = data.seeds;
|
||||
|
||||
if (peers || seeds) break;
|
||||
} catch (e) {
|
||||
retry++;
|
||||
return null;
|
||||
}
|
||||
|
||||
timeout *= 2;
|
||||
retry++;
|
||||
}
|
||||
|
||||
return { peers, seeders: seeds };
|
||||
|
Loading…
Reference in New Issue
Block a user