Skip to content

Commit

Permalink
feat: magnet hash key, ziahamza/webui-aria2#468
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Oct 27, 2024
1 parent 3b2eac8 commit 22e9316
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/js/ctrls/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down

0 comments on commit 22e9316

Please sign in to comment.