mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +00:00
fix(webtorrent): use web seeds in health probe
This commit is contained in:
1 parent
babf73d777
commit
215ff29f1a
2 files changed
+17
-6
No files matched your search
+7
-2
@@ -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
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user