Мелкий рефакторинг
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
const got = require('got');
|
const got = require('got');
|
||||||
|
|
||||||
const maxDownloadSize = 50*1024*1024;
|
|
||||||
|
|
||||||
class FileDownloader {
|
class FileDownloader {
|
||||||
constructor() {
|
constructor(limitDownloadSize = 0) {
|
||||||
|
this.limitDownloadSize = limitDownloadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(url, callback) {
|
async load(url, callback) {
|
||||||
@@ -24,9 +23,11 @@ class FileDownloader {
|
|||||||
|
|
||||||
let prevProg = 0;
|
let prevProg = 0;
|
||||||
const request = got(url, options).on('downloadProgress', progress => {
|
const request = got(url, options).on('downloadProgress', progress => {
|
||||||
if (progress.transferred > maxDownloadSize) {
|
if (this.limitDownloadSize) {
|
||||||
errMes = 'file too big';
|
if (progress.transferred > this.limitDownloadSize) {
|
||||||
request.cancel();
|
errMes = 'Файл слишком большой';
|
||||||
|
request.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let prog = 0;
|
let prog = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user