mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +00:00
fix(r2): inject infohash into nip-71 imeta tags for webtorrent bootstrapping
This commit is contained in:
1 parent
4fc25ff70c
commit
657ee40eb5
1 file changed
+21
-3
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user