Рефакторинг
This commit is contained in:
@@ -9,10 +9,10 @@ class FileDownloader {
|
|||||||
this.limitDownloadSize = limitDownloadSize;
|
this.limitDownloadSize = limitDownloadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(url, callback, abort) {
|
async load(url, opts, callback, abort) {
|
||||||
let errMes = '';
|
let errMes = '';
|
||||||
|
|
||||||
const options = {
|
let options = {
|
||||||
headers: {
|
headers: {
|
||||||
'user-agent': userAgent,
|
'user-agent': userAgent,
|
||||||
timeout: 300*1000,
|
timeout: 300*1000,
|
||||||
@@ -22,6 +22,8 @@ class FileDownloader {
|
|||||||
}),
|
}),
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
};
|
};
|
||||||
|
if (opts)
|
||||||
|
options = Object.assign({}, opts, options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(url, options);
|
const res = await axios.get(url, options);
|
||||||
|
|||||||
@@ -64,17 +64,11 @@ class RemoteLib {
|
|||||||
const response = await await this.wsRequest({action: 'get-book-link', bookPath, downFileName});
|
const response = await await this.wsRequest({action: 'get-book-link', bookPath, downFileName});
|
||||||
const link = response.link;
|
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}`;
|
const publicPath = `${this.config.publicDir}${link}`;
|
||||||
|
|
||||||
await fs.writeFile(tmpFile, buf);
|
await fs.writeFile(publicPath, buf);
|
||||||
|
|
||||||
await utils.gzipFile(tmpFile, tmpFile2, 4);
|
|
||||||
await fs.remove(tmpFile);
|
|
||||||
await fs.move(tmpFile2, publicPath, {overwrite: true});
|
|
||||||
|
|
||||||
return path.basename(link);
|
return path.basename(link);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user