🌟 Enhance wget.ts with Hatter proxy support and update script metadata
This commit is contained in:
@@ -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] <URL>`);
|
||||
wget.ts [--proxy socks5h://ip:port] [--no-proxy] [--hatter-proxy] [--output filename] <URL>`);
|
||||
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==
|
||||
|
||||
Reference in New Issue
Block a user