diff --git a/js/gridHealth.js b/js/gridHealth.js index 6fe39850..7b814ee9 100644 --- a/js/gridHealth.js +++ b/js/gridHealth.js @@ -158,7 +158,7 @@ function normalizeResult(result) { }; } -function queueProbe(magnet, cacheKey, priority = 0) { +function queueProbe(magnet, cacheKey, priority = 0, webSeeds = []) { if (!magnet) { return Promise.resolve(null); } @@ -180,6 +180,7 @@ function queueProbe(magnet, cacheKey, priority = 0) { timeoutMs: PROBE_TIMEOUT_MS, maxWebConns: 2, polls: PROBE_POLL_COUNT, + urlList: webSeeds, }) .catch((err) => ({ healthy: false, @@ -584,7 +585,11 @@ function handleCardVisible({ card, pendingByCard, priority = 0 }) { setBadge(card, "checking"); - const probePromise = queueProbe(magnet, infoHash, priority); + const encodedUrl = card.dataset.urlHealthUrl || ""; + const webSeed = encodedUrl ? decodeURIComponent(encodedUrl) : ""; + const webSeeds = webSeed ? [webSeed] : []; + + const probePromise = queueProbe(magnet, infoHash, priority, webSeeds); pendingByCard.set(card, probePromise); diff --git a/js/webtorrent.js b/js/webtorrent.js index 0bb839eb..f3cf7a52 100644 --- a/js/webtorrent.js +++ b/js/webtorrent.js @@ -175,7 +175,7 @@ export class TorrentClient { */ async probePeers( magnetURI, - { timeoutMs = 8000, maxWebConns = 2, polls = 3 } = {} + { timeoutMs = 8000, maxWebConns = 2, polls = 3, urlList = [] } = {} ) { const magnet = typeof magnetURI === "string" ? magnetURI.trim() : ""; if (!magnet) { @@ -194,7 +194,9 @@ export class TorrentClient { const { magnet: augmentedMagnet, appended, hasProbeTrackers } = appendProbeTrackers(magnet, trackers); - const hasWebSeed = magnet.includes("ws=") || magnet.includes("webSeed="); + const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed="); + const hasExplicitWebSeed = Array.isArray(urlList) && urlList.length > 0; + const hasWebSeed = hasMagnetWebSeed || hasExplicitWebSeed; if (!hasProbeTrackers && !hasWebSeed) { return { @@ -270,10 +272,14 @@ export class TorrentClient { }; try { - torrent = client.add(augmentedMagnet, { + const addOptions = { announce: trackers, maxWebConns: safeMaxWebConns, - }); + }; + if (hasExplicitWebSeed) { + addOptions.urlList = urlList; + } + torrent = client.add(augmentedMagnet, addOptions); } catch (err) { finalize({ reason: "error",