fix(webtorrent): use web seeds in health probe

This commit is contained in:
google-labs-jules[bot] committed 2026-01-23 04:06:11 +00:00
1 parent babf73d777
commit 215ff29f1a
2 files changed
+17 -6

No files matched your search

+7 -2
View File
@@ -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);
+10 -4
View File
@@ -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",