From 00e1dbfdfb00a5983cf4a6ae7e8504d1d438178c Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:49:25 +0900 Subject: Fix typo (#6238) --- src/misc/donwload-url.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/misc/donwload-url.ts (limited to 'src/misc/donwload-url.ts') diff --git a/src/misc/donwload-url.ts b/src/misc/donwload-url.ts deleted file mode 100644 index 3f42fb3bef..0000000000 --- a/src/misc/donwload-url.ts +++ /dev/null @@ -1,39 +0,0 @@ -import * as fs from 'fs'; -import * as stream from 'stream'; -import * as util from 'util'; -import fetch from 'node-fetch'; -import { httpAgent, httpsAgent } from './fetch'; -import { AbortController } from 'abort-controller'; -import config from '../config'; -import * as chalk from 'chalk'; -import Logger from '../services/logger'; - -const pipeline = util.promisify(stream.pipeline); - -export async function downloadUrl(url: string, path: string) { - const logger = new Logger('download'); - - logger.info(`Downloading ${chalk.cyan(url)} ...`); - const controller = new AbortController(); - setTimeout(() => { - controller.abort(); - }, 11 * 1000); - - const response = await fetch(new URL(url).href, { - headers: { - 'User-Agent': config.userAgent - }, - timeout: 10 * 1000, - signal: controller.signal, - agent: u => u.protocol == 'http:' ? httpAgent : httpsAgent, - }); - - if (!response.ok) { - logger.error(`Got ${response.status} (${url})`); - throw response.status; - } - - await pipeline(response.body, fs.createWriteStream(path)); - - logger.succ(`Download finished: ${chalk.cyan(url)}`); -} -- cgit v1.2.3-freya