magnet-uri
Advanced tools
Comparing version 6.1.1 to 6.2.0
18
index.js
@@ -74,2 +74,4 @@ /*! magnet-uri. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */ | ||
result.infoHash = Buffer.from(decodedStr, 'binary').toString('hex') | ||
} else if ((m = xt.match(/^urn:btmh:1220(.{64})/))) { | ||
result.infoHashV2 = m[1].toLowerCase() | ||
} | ||
@@ -89,2 +91,3 @@ }) | ||
if (result.infoHash) result.infoHashBuffer = Buffer.from(result.infoHash, 'hex') | ||
if (result.infoHashV2) result.infoHashV2Buffer = Buffer.from(result.infoHashV2, 'hex') | ||
if (result.publicKey) result.publicKeyBuffer = Buffer.from(result.publicKey, 'hex') | ||
@@ -126,4 +129,15 @@ | ||
// (example: `infoHash` for `xt`, `name` for `dn`) | ||
if (obj.infoHashBuffer) obj.xt = `urn:btih:${obj.infoHashBuffer.toString('hex')}` | ||
if (obj.infoHash) obj.xt = `urn:btih:${obj.infoHash}` | ||
// Deduplicate xt by using a set | ||
let xts = new Set() | ||
if (obj.xt && typeof obj.xt === 'string') xts.add(obj.xt) | ||
if (obj.xt && Array.isArray(obj.xt)) xts = new Set(obj.xt) | ||
if (obj.infoHashBuffer) xts.add(`urn:btih:${obj.infoHashBuffer.toString('hex')}`) | ||
if (obj.infoHash) xts.add(`urn:btih:${obj.infoHash}`) | ||
if (obj.infoHashV2Buffer) xts.add(obj.xt = `urn:btmh:1220${obj.infoHashV2Buffer.toString('hex')}`) | ||
if (obj.infoHashV2) xts.add(`urn:btmh:1220${obj.infoHashV2}`) | ||
const xtsDeduped = Array.from(xts) | ||
if (xtsDeduped.length === 1) obj.xt = xtsDeduped[0] | ||
if (xtsDeduped.length > 1) obj.xt = xtsDeduped | ||
if (obj.publicKeyBuffer) obj.xs = `urn:btpk:${obj.publicKeyBuffer.toString('hex')}` | ||
@@ -130,0 +144,0 @@ if (obj.publicKey) obj.xs = `urn:btpk:${obj.publicKey}` |
{ | ||
"name": "magnet-uri", | ||
"description": "Parse a magnet URI and return an object of keys/values", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"author": { | ||
@@ -14,3 +14,3 @@ "name": "WebTorrent LLC", | ||
"dependencies": { | ||
"bep53-range": "^1.0.0", | ||
"bep53-range": "^1.1.0", | ||
"thirty-two": "^1.0.2" | ||
@@ -20,3 +20,3 @@ }, | ||
"standard": "*", | ||
"tape": "^5.0.1" | ||
"tape": "^5.2.2" | ||
}, | ||
@@ -23,0 +23,0 @@ "funding": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11864
146
Updatedbep53-range@^1.1.0