From 0894a389785bfc747a6c2b261dc10044c6097acf Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sat, 15 Oct 2022 18:59:13 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/FileDownloader.js | 6 ++++-- server/core/RemoteLib.js | 10 ++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/server/core/FileDownloader.js b/server/core/FileDownloader.js index 5f86e5a..aab1c21 100644 --- a/server/core/FileDownloader.js +++ b/server/core/FileDownloader.js @@ -9,10 +9,10 @@ class FileDownloader { this.limitDownloadSize = limitDownloadSize; } - async load(url, callback, abort) { + async load(url, opts, callback, abort) { let errMes = ''; - const options = { + let options = { headers: { 'user-agent': userAgent, timeout: 300*1000, @@ -22,6 +22,8 @@ class FileDownloader { }), responseType: 'stream', }; + if (opts) + options = Object.assign({}, opts, options); try { const res = await axios.get(url, options); diff --git a/server/core/RemoteLib.js b/server/core/RemoteLib.js index fe0520c..e5cd9da 100644 --- a/server/core/RemoteLib.js +++ b/server/core/RemoteLib.js @@ -64,17 +64,11 @@ class RemoteLib { const response = await await this.wsRequest({action: 'get-book-link', bookPath, downFileName}); const link = response.link; - const buf = await this.down.load(`${this.remoteHost}${link}`); + const buf = await this.down.load(`${this.remoteHost}${link}`, {decompress: false}); - const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`; - const tmpFile2 = `${this.config.tempDir}/${utils.randomHexString(30)}`; const publicPath = `${this.config.publicDir}${link}`; - await fs.writeFile(tmpFile, buf); - - await utils.gzipFile(tmpFile, tmpFile2, 4); - await fs.remove(tmpFile); - await fs.move(tmpFile2, publicPath, {overwrite: true}); + await fs.writeFile(publicPath, buf); return path.basename(link); } catch (e) {