feat: improve magnet link reliability with webseeds

- Update `UploadModal.js` to pre-calculate R2 keys and public URLs before upload.
- Update `torrentHash.js` to embed the calculated video URL as a webseed (`url-list`) in the `.torrent` file.
- Update `r2Service.js` to accept forced keys/URLs and append `&xs=` (pointing to the .torrent file) to the magnet link.
- Ensures magnet links work for peerless downloads via WebSeed (BEP19) and HTTP Seeding (BEP17).
This commit is contained in:
google-labs-jules[bot] committed 2026-01-15 13:26:27 +00:00
1 parent f748f663c8
commit 4e840c6159
3 files changed
+68 -9

No files matched your search

+21 -5
View File
@@ -551,6 +551,10 @@ class R2Service {
settingsInput = null,
publishVideoNote,
onReset,
forcedVideoKey = "",
forcedVideoUrl = "",
forcedTorrentKey = "",
forcedTorrentUrl = "",
} = {}) {
if (settingsInput) {
const saved = await this.handleCloudflareSettingsSubmit(settingsInput, {
@@ -638,9 +642,12 @@ class R2Service {
let statusMessage = `Uploading to ${bucketEntry.bucket}…`;
this.setCloudflareUploadStatus(statusMessage, "info");
const key = buildR2Key(npub, file);
const publicUrl = buildPublicUrl(bucketEntry.publicBaseUrl, key);
// Use forced keys if provided, otherwise generate them
const key = forcedVideoKey || buildR2Key(npub, file);
const publicUrl = forcedVideoUrl || buildPublicUrl(bucketEntry.publicBaseUrl, key);
const buildTorrentKey = () => {
if (forcedTorrentKey) return forcedTorrentKey;
const baseKey = key.replace(/\.[^/.]+$/, "");
if (baseKey && baseKey !== key) {
return `${baseKey}.torrent`;
@@ -687,7 +694,7 @@ class R2Service {
});
let publishOutcome = true;
let torrentUrl = "";
let torrentUrl = forcedTorrentUrl || "";
if (torrentFile) {
this.setCloudflareUploadStatus("Uploading torrent metadata...", "info");
@@ -700,7 +707,9 @@ class R2Service {
file: torrentFile,
contentType: "application/x-bittorrent",
});
torrentUrl = buildPublicUrl(bucketEntry.publicBaseUrl, torrentKey);
if (!torrentUrl) {
torrentUrl = buildPublicUrl(bucketEntry.publicBaseUrl, torrentKey);
}
} catch (err) {
userLogger.warn("Torrent metadata upload failed, continuing...", err);
}
@@ -722,7 +731,14 @@ class R2Service {
if (hasValidInfoHash) {
const encodedDn = encodeURIComponent(file.name);
const encodedWs = encodeURIComponent(publicUrl);
generatedMagnet = `magnet:?xt=urn:btih:${normalizedInfoHash}&dn=${encodedDn}&ws=${encodedWs}`;
let magnet = `magnet:?xt=urn:btih:${normalizedInfoHash}&dn=${encodedDn}&ws=${encodedWs}`;
if (torrentUrl) {
const encodedXs = encodeURIComponent(torrentUrl);
magnet += `&xs=${encodedXs}`;
}
generatedMagnet = magnet;
generatedWs = publicUrl;
} else {
if (infoHash) {