🌟 Enhance wget.ts with Hatter proxy support and update script metadata

This commit is contained in:
2026-04-12 09:38:33 +08:00
parent d87ca12cd4
commit 451e1c9fd0
2 changed files with 37 additions and 11 deletions
+3 -3
View File
@@ -367,11 +367,11 @@
}, },
"wget.ts": { "wget.ts": {
"script_name": "wget.ts", "script_name": "wget.ts",
"script_length": 4076, "script_length": 4887,
"script_sha256": "2d36cbb0c7f10807e7c83d0b616faa3d790b498ed64ad1bce441a2bb35baf785", "script_sha256": "eff44560e0c4459748794a8343a8234a3e736abe4ffaaf9cf123447ab339f16b",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/wget.ts", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/wget.ts",
"single_script_file": true, "single_script_file": true,
"publish_time": 1737272626139, "publish_time": 1737272626139,
"update_time": 1750472965158 "update_time": 1775957909453
} }
} }
+34 -8
View File
@@ -4,15 +4,17 @@
// - https://docs.deno.com/examples/command_line_arguments/ // - https://docs.deno.com/examples/command_line_arguments/
// - https://jsr.io/@chiba/wget/1.0.0/mod.ts // - https://jsr.io/@chiba/wget/1.0.0/mod.ts
import { parseArgs } from "jsr:@std/cli/parse-args"; import {parseArgs} from "jsr:@std/cli/parse-args";
import { import {
clearLastLine, clearLastLine,
exit,
formatHumanTime, formatHumanTime,
formatPercent, formatPercent,
formatSize2, formatSize2,
getKeyRingPassword,
log, log,
printLastLine, printLastLine,
} from "https://global.hatter.ink/script/get/@1/deno-commons-mod.ts"; } from "https://script.hatter.ink/@70/deno-commons-mod.ts";
function getOutputFilename(filename: string): string { function getOutputFilename(filename: string): string {
const original = filename; const original = filename;
@@ -55,7 +57,7 @@ function getEnvironmentProxy(): string | undefined {
const args = Deno.args; const args = Deno.args;
const flags = parseArgs(Deno.args, { const flags = parseArgs(Deno.args, {
boolean: ["help", "no-proxy"], boolean: ["help", "no-proxy", "hatter-proxy"],
string: ["proxy", "output"], string: ["proxy", "output"],
}); });
@@ -66,7 +68,7 @@ if (args.length === 0) {
if (flags.help) { if (flags.help) {
console.log(`wget.ts - download file console.log(`wget.ts - download file
wget.ts [--proxy socks5h://ip:port] [--no-proxy] [--output filename] <URL>`); wget.ts [--proxy socks5h://ip:port] [--no-proxy] [--hatter-proxy] [--output filename] <URL>`);
Deno.exit(0); Deno.exit(0);
} }
@@ -107,8 +109,9 @@ const outputFileWritable = Deno.createSync(outputFilename).writable;
let init = undefined; let init = undefined;
const noProxy = flags["no-proxy"]; const noProxy = flags["no-proxy"];
const hatterProxy = flags["hatter-proxy"];
const proxy = flags.proxy || getEnvironmentProxy(); const proxy = flags.proxy || getEnvironmentProxy();
if (proxy && !noProxy) { if (proxy && !noProxy && !hatterProxy) {
log.info(`Using proxy: ${proxy}`); log.info(`Using proxy: ${proxy}`);
init = { init = {
client: Deno.createHttpClient({ client: Deno.createHttpClient({
@@ -118,7 +121,30 @@ if (proxy && !noProxy) {
}), }),
}; };
} }
const response = await fetch(url, init); if (hatterProxy) {
log.info(`Using hatter proxy.`);
}
let realUrl = url;
if (hatterProxy) {
try {
const token = await getKeyRingPassword(
"play-hater-me",
"xgetfile-token",
);
realUrl = `https://play.hatter.me/xgetfile?__token=${
encodeURIComponent(token)
}&url=${encodeURIComponent(url)}`;
log.info(`Proxy URL: ${realUrl}`);
} catch (e) {
log.error("Get xgetfile token failed", e);
if (!confirm("Continue get file without hatter proxy?")) {
log.warn("Wget file abort for no valid hatter proxy token");
exit(1);
}
}
}
log.debug(`Wget url: ${realUrl}`);
const response = await fetch(realUrl, init);
const contentLength = response.headers.get("content-length"); const contentLength = response.headers.get("content-length");
totalLength = -1; totalLength = -1;
if (contentLength !== null) { if (contentLength !== null) {
@@ -141,5 +167,5 @@ log.success(
}`, }`,
); );
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250621T102718+08:00.MEQCIHvQwXrDEk9HSijMmtn+ // @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T093742+08:00.MEQCIG3Xz35jg15qpr2fBc8B
// Yusk647Yk2ewDfBOIcRwNH66AiBaAxbaVCoryP/e20SuL5JyL2qYyPb6SeDoxXF41AkGxA== // hKxbjDlAXpETYYKNzkaZb6a7AiBeZOvcgvU+V7VUhs1rGZze2NyKreSXoMxWFhdblic4tA==