Compare commits

..

3 commits

Author SHA1 Message Date
6445664512
urldecode: cleanup, error handling 2025-07-12 10:50:26 -06:00
77283cc9d3 Merge branch 'feat/urldecode' into 'rewrite'
feat(modules/misc/urldecode): add urldecode command

See merge request Cynosphere/HiddenPhox!24
2025-07-12 10:47:45 -06:00
arHSM
9cbafac379 feat(modules/misc/urldecode): add urldecode command 2025-07-12 10:47:45 -06:00

View file

@ -0,0 +1,37 @@
const Command = require("#lib/command.js");
const {Icons} = require("#util/constants.js");
const urldecode = new Command("urldecode");
urldecode.category = "misc";
urldecode.helpText = "Get information on a URL";
urldecode.usage = "<url>";
urldecode.callback = async function (msg, line, [urlString]) {
try {
const url = new URL(urlString);
const info = [
["scheme", url.protocol],
["username", url.username],
["password", url.password],
["host", url.host],
["path", url.pathname],
["hash", url.hash],
];
return `\`\`\`py
${info
.filter((kv) => kv[1].length > 0)
.map(([k, v]) => `${k} = ${v}`)
.join("\n")}
${JSON.stringify(
url.searchParams,
(_, v) => (v instanceof URLSearchParams ? Object.fromEntries(v.entries()) : v),
"\t"
)}
\`\`\``;
} catch (err) {
return `${Icons.silk.error} Failed to decode URL:\n\`\`\`\n${err}\`\`\``;
}
};
hf.registerCommand(urldecode);