diff --git a/script-meta-v2.json b/script-meta-v2.json index f90f38b..a14a624 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -367,11 +367,11 @@ }, "wget.ts": { "script_name": "wget.ts", - "script_length": 4076, - "script_sha256": "2d36cbb0c7f10807e7c83d0b616faa3d790b498ed64ad1bce441a2bb35baf785", + "script_length": 4887, + "script_sha256": "eff44560e0c4459748794a8343a8234a3e736abe4ffaaf9cf123447ab339f16b", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/wget.ts", "single_script_file": true, "publish_time": 1737272626139, - "update_time": 1750472965158 + "update_time": 1775957909453 } } \ No newline at end of file diff --git a/single-scripts/wget.ts b/single-scripts/wget.ts index 9c82395..4114290 100755 --- a/single-scripts/wget.ts +++ b/single-scripts/wget.ts @@ -4,15 +4,17 @@ // - https://docs.deno.com/examples/command_line_arguments/ // - 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 { clearLastLine, + exit, formatHumanTime, formatPercent, formatSize2, + getKeyRingPassword, log, 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 { const original = filename; @@ -55,7 +57,7 @@ function getEnvironmentProxy(): string | undefined { const args = Deno.args; const flags = parseArgs(Deno.args, { - boolean: ["help", "no-proxy"], + boolean: ["help", "no-proxy", "hatter-proxy"], string: ["proxy", "output"], }); @@ -66,7 +68,7 @@ if (args.length === 0) { if (flags.help) { console.log(`wget.ts - download file -wget.ts [--proxy socks5h://ip:port] [--no-proxy] [--output filename] `); +wget.ts [--proxy socks5h://ip:port] [--no-proxy] [--hatter-proxy] [--output filename] `); Deno.exit(0); } @@ -107,8 +109,9 @@ const outputFileWritable = Deno.createSync(outputFilename).writable; let init = undefined; const noProxy = flags["no-proxy"]; +const hatterProxy = flags["hatter-proxy"]; const proxy = flags.proxy || getEnvironmentProxy(); -if (proxy && !noProxy) { +if (proxy && !noProxy && !hatterProxy) { log.info(`Using proxy: ${proxy}`); init = { 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"); totalLength = -1; if (contentLength !== null) { @@ -141,5 +167,5 @@ log.success( }`, ); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250621T102718+08:00.MEQCIHvQwXrDEk9HSijMmtn+ -// Yusk647Yk2ewDfBOIcRwNH66AiBaAxbaVCoryP/e20SuL5JyL2qYyPb6SeDoxXF41AkGxA== +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T093742+08:00.MEQCIG3Xz35jg15qpr2fBc8B +// hKxbjDlAXpETYYKNzkaZb6a7AiBeZOvcgvU+V7VUhs1rGZze2NyKreSXoMxWFhdblic4tA==