From 307df28c1cebfe5d0bea1124e4bc69495699feb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=87=AF?= <282916711@qq.com> Date: Sat, 1 Sep 2018 12:13:43 +0800 Subject: [PATCH 1/2] Update modal.js Support add BT-magnet hash code URI directly, such as '24B971DF922333C66E674E0F1F4248240C4A6F08' If you search some resource from THE PIRATE BAY, this feature is usefull. --- js/ctrls/modal.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 55d9c6d5..66cf0b4c 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -91,7 +91,17 @@ angular }); }) .filter(function(d) { return d.length }) - .value(); + .map(function(u){ + var t=_.toUpper(u[0]) + + if(t.startsWith("HTTP")||t.startsWith("MAGNET")||t.startsWith("FTP")){ + return u + }else{ + u[0]= "magnet:?xt=urn:btih:"+u[0] + return u + } + }) + .value(); } }; From 43a53eab165ccac8d2cf7968dca64fd736f7a66f Mon Sep 17 00:00:00 2001 From: xu kai Date: Mon, 10 Sep 2018 16:04:54 +0800 Subject: [PATCH 2/2] support add marget-key directly --- js/ctrls/modal.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 66cf0b4c..2f2b9fef 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -91,17 +91,21 @@ angular }); }) .filter(function(d) { return d.length }) - .map(function(u){ - var t=_.toUpper(u[0]) - - if(t.startsWith("HTTP")||t.startsWith("MAGNET")||t.startsWith("FTP")){ - return u - }else{ - u[0]= "magnet:?xt=urn:btih:"+u[0] - return u - } - }) - .value(); + .map(function(u){ + /// transform bt-key into legal magnet link + /// support BASE32 encoding key string or HEX encoding key string + var str=_.toUpper(u[0]) + var hashkey=_.head(_.split(str,"&"))//maybe url contains additional attribute such as dn/tr + const base32Regex=/^[2-7 | A-Z]{32}$/ + const hexRegex=/^[0-9 | A-Z]{40}$/ + if(base32Regex.test(hashkey)||hexRegex.test(hashkey)){ + u[0]= "magnet:?xt=urn:btih:"+u[0] + // if hashkey is legal bt-hashkey string then add protocol's head + // only support 32-bit length HEX encoding string or 40-bit length BASE32 length encoding string + } + return u + }) + .value(); } };