From 22e9316a7d3c921ec9eecf7d001ef8af41b88cac Mon Sep 17 00:00:00 2001 From: Su Yang Date: Sun, 27 Oct 2024 22:54:47 +0800 Subject: [PATCH] feat: magnet hash key, https://github.com/ziahamza/webui-aria2/pull/468 --- src/js/ctrls/modal.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/js/ctrls/modal.js b/src/js/ctrls/modal.js index 5446f7c..7f22647 100644 --- a/src/js/ctrls/modal.js +++ b/src/js/ctrls/modal.js @@ -106,6 +106,20 @@ export default angular .filter(function(d) { return d.length; }) + .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(); } };