This commit is contained in:
tamaina 2023-01-24 01:00:09 +00:00
parent 88b41f86a9
commit 9623e8aa62
1 changed files with 2 additions and 11 deletions

View File

@ -4,7 +4,6 @@ import * as util from 'node:util';
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import IPCIDR from 'ip-cidr'; import IPCIDR from 'ip-cidr';
import PrivateIp from 'private-ip'; import PrivateIp from 'private-ip';
import got, * as Got from 'got';
import chalk from 'chalk'; import chalk from 'chalk';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js'; import type { Config } from '@/config.js';
@ -83,16 +82,8 @@ export class DownloadService {
throw new StatusError('No body', 400, 'No body'); throw new StatusError('No body', 400, 'No body');
} }
try { this.logger.info(`Saving File to ${chalk.cyanBright(path)} from downloading ...`);
this.logger.info(`Saving File to ${chalk.cyanBright(path)} from downloading ...`); await pipeline(stream.Readable.fromWeb(response.body), fs.createWriteStream(path));
await pipeline(stream.Readable.fromWeb(response.body), fs.createWriteStream(path));
} catch (e) {
if (e instanceof Got.HTTPError) {
throw new StatusError(`${e.response.statusCode} ${e.response.statusMessage}`, e.response.statusCode, e.response.statusMessage);
} else {
throw e;
}
}
} }
@bindThis @bindThis