Skip to content

Commit 22e9316

Browse files
committed
feat: magnet hash key, ziahamza/webui-aria2#468
1 parent 3b2eac8 commit 22e9316

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/js/ctrls/modal.js

+14
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ export default angular
106106
.filter(function(d) {
107107
return d.length;
108108
})
109+
.map(function(u) {
110+
/// transform bt-key into legal magnet link
111+
/// support BASE32 encoding key string or HEX encoding key string
112+
var str = _.toUpper(u[0]);
113+
var hashkey = _.head(_.split(str, "&")); //maybe url contains additional attribute such as dn/tr
114+
const base32Regex = /^[2-7 | A-Z]{32}$/;
115+
const hexRegex = /^[0-9 | A-Z]{40}$/;
116+
if (base32Regex.test(hashkey) || hexRegex.test(hashkey)) {
117+
u[0] = "magnet:?xt=urn:btih:" + u[0];
118+
// if hashkey is legal bt-hashkey string then add protocol's head
119+
// only support 32-bit length HEX encoding string or 40-bit length BASE32 length encoding string
120+
}
121+
return u;
122+
})
109123
.value();
110124
}
111125
};

0 commit comments

Comments
 (0)