feat: update wget.ts

This commit is contained in:
2025-01-19 13:19:09 +08:00
parent f781336dbe
commit 537e25a40b
2 changed files with 12 additions and 7 deletions

View File

@@ -40,8 +40,8 @@
},
"wget.ts": {
"script_name": "wget.ts",
"script_length": 3438,
"script_sha256": "d8cba907b1e1d669a4680c8b13328f284a2b10c47e47288389aab8ccbde71993",
"script_length": 3567,
"script_sha256": "cb1d30254fd85a9db948f1f2de1d5b966d290677d40917a705e72a0385be97e3",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/wget.ts",
"single_script_file": true
}

View File

@@ -5,7 +5,6 @@
// - https://jsr.io/@chiba/wget/1.0.0/mod.ts
import { parseArgs } from "jsr:@std/cli/parse-args";
import * as fs from "jsr:@std/fs@^1.0.0";
import {
clearLastLine,
formatHumanTime,
@@ -17,8 +16,14 @@ import {
function getOutputFilename(filename: string): string {
const original = filename;
for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
if (!fs.existsSync(filename)) {
break;
try {
Deno.statSync(filename);
// deno-lint-ignore no-explicit-any
} catch (e: any) {
if (e && e.name === "NotFound") {
break;
}
throw e;
}
filename = `${original}.${i}`;
}
@@ -72,7 +77,7 @@ const outputFilename = flags.output || getOutputFilenameFromUrl(url);
const startTime = new Date().getTime();
let totalLength: number = -2;
console.log("Start download file:", url, " --> ", outputFilename);
console.log(`Start download file: ${url} --> ${outputFilename}`);
const stateFileInterVal = setInterval(async () => {
const costTime = new Date().getTime() - startTime;
@@ -99,7 +104,7 @@ const outputFileWritable = Deno.createSync(outputFilename).writable;
let init = undefined;
const proxy = flags.proxy || getEnvironmentProxy();
if (proxy) {
console.log("Using proxy: ", proxy);
console.log(`Using proxy: ${proxy}`);
init = {
client: Deno.createHttpClient({
proxy: {