Мелкий рефакторинг

This commit is contained in:
Book Pauk
2020-01-26 15:07:14 +07:00
parent 2569d00bd0
commit 7997c486cf

View File

@@ -1,9 +1,8 @@
const got = require('got');
const maxDownloadSize = 50*1024*1024;
class FileDownloader {
constructor() {
constructor(limitDownloadSize = 0) {
this.limitDownloadSize = limitDownloadSize;
}
async load(url, callback) {
@@ -24,9 +23,11 @@ class FileDownloader {
let prevProg = 0;
const request = got(url, options).on('downloadProgress', progress => {
if (progress.transferred > maxDownloadSize) {
errMes = 'file too big';
request.cancel();
if (this.limitDownloadSize) {
if (progress.transferred > this.limitDownloadSize) {
errMes = 'Файл слишком большой';
request.cancel();
}
}
let prog = 0;