mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #2040 from PR0M3TH3AN/ai/fix-webseed-health-and-bootstrap-1140772652148172709
Fix WebTorrent webseed health check and bootstrap behavior
This commit is contained in:
2 files changed
+26
-9
No files matched your search
+2
-2
@@ -135,9 +135,9 @@ function normalizeResult(result) {
|
||||
const peers = Number.isFinite(result.peers)
|
||||
? Math.max(0, Number(result.peers))
|
||||
: 0;
|
||||
const healthy = Boolean(result.healthy) && peers > 0;
|
||||
const reason = typeof result.reason === "string" ? result.reason : "error";
|
||||
const webseedOnly = Boolean(result.webseedOnly) && peers === 0;
|
||||
const healthy = (Boolean(result.healthy) && peers > 0) || webseedOnly;
|
||||
const reason = typeof result.reason === "string" ? result.reason : "error";
|
||||
return {
|
||||
healthy,
|
||||
peers: healthy ? Math.max(1, peers) : peers,
|
||||
|
||||
+24
-7
@@ -222,11 +222,19 @@ export class TorrentClient {
|
||||
}
|
||||
|
||||
const trackers = normalizeTrackerList(TorrentClient.PROBE_TRACKERS);
|
||||
const { magnet: augmentedMagnet, appended, hasProbeTrackers } =
|
||||
let { magnet: augmentedMagnet, appended, hasProbeTrackers } =
|
||||
appendProbeTrackers(magnet, trackers);
|
||||
|
||||
const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed=");
|
||||
const hasExplicitWebSeed = Array.isArray(urlList) && urlList.length > 0;
|
||||
|
||||
if (hasExplicitWebSeed) {
|
||||
const wsParams = urlList
|
||||
.map((url) => `ws=${encodeURIComponent(url)}`)
|
||||
.join("&");
|
||||
const separator = augmentedMagnet.includes("?") ? "&" : "?";
|
||||
augmentedMagnet = `${augmentedMagnet}${separator}${wsParams}`;
|
||||
}
|
||||
const hasWebSeed = hasMagnetWebSeed || hasExplicitWebSeed;
|
||||
|
||||
if (!hasProbeTrackers && !hasWebSeed) {
|
||||
@@ -929,7 +937,21 @@ export class TorrentClient {
|
||||
*/
|
||||
async streamVideo(magnetURI, videoElement, opts = {}) {
|
||||
try {
|
||||
const effectiveMagnetURI = stripXsParameter(magnetURI);
|
||||
let effectiveMagnetURI = stripXsParameter(magnetURI);
|
||||
const candidateUrls = Array.isArray(opts?.urlList)
|
||||
? opts.urlList
|
||||
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
||||
.filter((entry) => /^https?:\/\//i.test(entry))
|
||||
: [];
|
||||
|
||||
if (candidateUrls.length > 0) {
|
||||
const wsParams = candidateUrls
|
||||
.map((url) => `ws=${encodeURIComponent(url)}`)
|
||||
.join("&");
|
||||
const separator = effectiveMagnetURI.includes("?") ? "&" : "?";
|
||||
effectiveMagnetURI = `${effectiveMagnetURI}${separator}${wsParams}`;
|
||||
}
|
||||
|
||||
if (
|
||||
effectiveMagnetURI !==
|
||||
(typeof magnetURI === "string" ? magnetURI.trim() : "")
|
||||
@@ -962,11 +984,6 @@ export class TorrentClient {
|
||||
}
|
||||
|
||||
const isFirefoxBrowser = this.isFirefox();
|
||||
const candidateUrls = Array.isArray(opts?.urlList)
|
||||
? opts.urlList
|
||||
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
||||
.filter((entry) => /^https?:\/\//i.test(entry))
|
||||
: [];
|
||||
|
||||
const chromeOptions = { strategy: "sequential" };
|
||||
if (candidateUrls.length) {
|
||||
|
||||
Reference in new issue
Block a user