magnet-uri
Advanced tools
Comparing version 6.0.0 to 6.1.0
19
index.js
@@ -77,3 +77,14 @@ /*! magnet-uri. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */ | ||
} | ||
if (result.xs) { | ||
const xss = Array.isArray(result.xs) ? result.xs : [result.xs] | ||
xss.forEach(xs => { | ||
if ((m = xs.match(/^urn:btpk:(.{64})/))) { | ||
result.publicKey = m[1].toLowerCase() | ||
} | ||
}) | ||
} | ||
if (result.infoHash) result.infoHashBuffer = Buffer.from(result.infoHash, 'hex') | ||
if (result.publicKey) result.publicKeyBuffer = Buffer.from(result.publicKey, 'hex') | ||
@@ -116,2 +127,4 @@ if (result.dn) result.name = result.dn | ||
if (obj.infoHash) obj.xt = `urn:btih:${obj.infoHash}` | ||
if (obj.publicKeyBuffer) obj.xs = `urn:btpk:${obj.publicKeyBuffer.toString('hex')}` | ||
if (obj.publicKey) obj.xs = `urn:btpk:${obj.publicKey}` | ||
if (obj.name) obj.dn = obj.name | ||
@@ -135,5 +148,9 @@ if (obj.keywords) obj.kt = obj.keywords | ||
if (key === 'dn') val = encodeURIComponent(val).replace(/%20/g, '+') | ||
if (key === 'tr' || key === 'xs' || key === 'as' || key === 'ws') { | ||
if (key === 'tr' || key === 'as' || key === 'ws') { | ||
val = encodeURIComponent(val) | ||
} | ||
// Don't URI encode BEP46 keys | ||
if (key === 'xs' && !val.startsWith('urn:btpk:')) { | ||
val = encodeURIComponent(val) | ||
} | ||
if (key === 'kt') val = encodeURIComponent(val) | ||
@@ -140,0 +157,0 @@ if (key === 'so') return |
{ | ||
"name": "magnet-uri", | ||
"description": "Parse a magnet URI and return an object of keys/values", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "WebTorrent LLC", |
@@ -103,3 +103,3 @@ # magnet-uri [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] | ||
You can also use convenience key names like `name` (`dn`), `infoHash` (`xt`), | ||
`infoHashBuffer` (`xt`), `announce` (`tr`), and `keywords` (`kt`). | ||
`infoHashBuffer` (`xt`), `publicKey` (`xs`), `publicKeyBuffer` (`xs`), `announce` (`tr`), and `keywords` (`kt`). | ||
@@ -106,0 +106,0 @@ ## license |
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
11670
5
134