From 657ee40eb5e3de878325d94979484e5465568bf6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 02:04:14 +0000 Subject: [PATCH] fix(r2): inject infohash into nip-71 imeta tags for webtorrent bootstrapping --- js/services/r2Service.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/js/services/r2Service.js b/js/services/r2Service.js index 429e0aa1..c5345e50 100644 --- a/js/services/r2Service.js +++ b/js/services/r2Service.js @@ -117,7 +117,10 @@ class R2Service { this.emit("uploadProgress", { fraction }); } - buildNip71MetadataForUpload(existingMetadata, { publicUrl = "", file = null } = {}) { + buildNip71MetadataForUpload( + existingMetadata, + { publicUrl = "", file = null, infoHash = "" } = {}, + ) { const base = existingMetadata && typeof existingMetadata === "object" ? { ...existingMetadata } @@ -168,8 +171,13 @@ class R2Service { const primaryVariant = imetaList[0]; const normalizedUrl = - typeof publicUrl === "string" ? publicUrl.trim() : String(publicUrl || "").trim(); - if (normalizedUrl && (!primaryVariant.url || !String(primaryVariant.url).trim())) { + typeof publicUrl === "string" + ? publicUrl.trim() + : String(publicUrl || "").trim(); + if ( + normalizedUrl && + (!primaryVariant.url || !String(primaryVariant.url).trim()) + ) { primaryVariant.url = normalizedUrl; } @@ -179,6 +187,15 @@ class R2Service { primaryVariant.m = mimeType; } + const normalizedHash = + typeof infoHash === "string" ? infoHash.trim().toLowerCase() : ""; + if ( + normalizedHash && + (!primaryVariant.x || !String(primaryVariant.x).trim()) + ) { + primaryVariant.x = normalizedHash; + } + base.imeta = imetaList; return base; @@ -688,6 +705,7 @@ class R2Service { const mergedNip71 = this.buildNip71MetadataForUpload(metadata?.nip71, { publicUrl, file, + infoHash, }); if (mergedNip71 && Object.keys(mergedNip71).length) { rawVideoPayload.nip71 = mergedNip71;