From 537e25a40bf6583b0c1e12731cb6baa62614f7bc Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 19 Jan 2025 13:19:09 +0800 Subject: [PATCH] feat: update wget.ts --- script-meta-v2.json | 4 ++-- single-scripts/wget.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/script-meta-v2.json b/script-meta-v2.json index 750a4dc..1c50470 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -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 } diff --git a/single-scripts/wget.ts b/single-scripts/wget.ts index 88375bd..78b8a4b 100755 --- a/single-scripts/wget.ts +++ b/single-scripts/wget.ts @@ -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: {