feat: update wget.ts
This commit is contained in:
@@ -40,8 +40,8 @@
|
|||||||
},
|
},
|
||||||
"wget.ts": {
|
"wget.ts": {
|
||||||
"script_name": "wget.ts",
|
"script_name": "wget.ts",
|
||||||
"script_length": 3438,
|
"script_length": 3567,
|
||||||
"script_sha256": "d8cba907b1e1d669a4680c8b13328f284a2b10c47e47288389aab8ccbde71993",
|
"script_sha256": "cb1d30254fd85a9db948f1f2de1d5b966d290677d40917a705e72a0385be97e3",
|
||||||
"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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
// - 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 * as fs from "jsr:@std/fs@^1.0.0";
|
|
||||||
import {
|
import {
|
||||||
clearLastLine,
|
clearLastLine,
|
||||||
formatHumanTime,
|
formatHumanTime,
|
||||||
@@ -17,9 +16,15 @@ import {
|
|||||||
function getOutputFilename(filename: string): string {
|
function getOutputFilename(filename: string): string {
|
||||||
const original = filename;
|
const original = filename;
|
||||||
for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
|
for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
|
||||||
if (!fs.existsSync(filename)) {
|
try {
|
||||||
|
Deno.statSync(filename);
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e && e.name === "NotFound") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
filename = `${original}.${i}`;
|
filename = `${original}.${i}`;
|
||||||
}
|
}
|
||||||
return filename;
|
return filename;
|
||||||
@@ -72,7 +77,7 @@ const outputFilename = flags.output || getOutputFilenameFromUrl(url);
|
|||||||
const startTime = new Date().getTime();
|
const startTime = new Date().getTime();
|
||||||
let totalLength: number = -2;
|
let totalLength: number = -2;
|
||||||
|
|
||||||
console.log("Start download file:", url, " --> ", outputFilename);
|
console.log(`Start download file: ${url} --> ${outputFilename}`);
|
||||||
|
|
||||||
const stateFileInterVal = setInterval(async () => {
|
const stateFileInterVal = setInterval(async () => {
|
||||||
const costTime = new Date().getTime() - startTime;
|
const costTime = new Date().getTime() - startTime;
|
||||||
@@ -99,7 +104,7 @@ const outputFileWritable = Deno.createSync(outputFilename).writable;
|
|||||||
let init = undefined;
|
let init = undefined;
|
||||||
const proxy = flags.proxy || getEnvironmentProxy();
|
const proxy = flags.proxy || getEnvironmentProxy();
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
console.log("Using proxy: ", proxy);
|
console.log(`Using proxy: ${proxy}`);
|
||||||
init = {
|
init = {
|
||||||
client: Deno.createHttpClient({
|
client: Deno.createHttpClient({
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|||||||
Reference in New Issue
Block a user