Merge branch 'main' into feature/steam-client-icon-cache

This commit is contained in:
Chubby Granny Chaser 2024-05-18 22:00:08 +01:00 committed by GitHub
commit 7a13ecd2b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 16 additions and 794 deletions

View file

@ -1,40 +0,0 @@
import webTorrentHealth from "webtorrent-health";
type WebTorrentHealthData = {
seeds: number;
peers: number;
};
const MILLISECONDS = 1000;
const SECONDS = 1.5;
export const webTorrentData = {
async getSeedersAndPeers(
magnet: string
): Promise<{ seeders: number; peers: number } | null> {
let peers = 0;
let seeds = 0;
let retry = 0;
let timeout = SECONDS * MILLISECONDS;
while (retry < 3) {
try {
const data: WebTorrentHealthData = await webTorrentHealth(magnet, {
timeout,
});
peers = data.peers;
seeds = data.seeds;
if (peers || seeds) break;
} catch (e) {
return null;
}
timeout *= 2;
retry++;
}
return { peers, seeders: seeds };
},
};