Рефакторинг
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const utils = require('./utils');
|
||||||
const decompress = require('decompress');
|
const decompress = require('decompress');
|
||||||
const FileDetector = require('./FileDetector');
|
const FileDetector = require('./FileDetector');
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ class FileDecompressor {
|
|||||||
if (!await fs.pathExists(outFilename)) {
|
if (!await fs.pathExists(outFilename)) {
|
||||||
await fs.writeFile(outFilename, await this.gzipBuffer(buf))
|
await fs.writeFile(outFilename, await this.gzipBuffer(buf))
|
||||||
} else {
|
} else {
|
||||||
await fs.utimes(outFilename, Date.now()/1000, Date.now()/1000);
|
await utils.touchFile(outFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return outFilename;
|
return outFilename;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class ReaderWorker {
|
|||||||
downloadedFilename = `${this.config.uploadDir}/${url.substr(7)}`;
|
downloadedFilename = `${this.config.uploadDir}/${url.substr(7)}`;
|
||||||
if (!await fs.pathExists(downloadedFilename))
|
if (!await fs.pathExists(downloadedFilename))
|
||||||
throw new Error('Файл не найден на сервере (возможно был удален как устаревший). Пожалуйста, загрузите файл с диска на сервер заново.');
|
throw new Error('Файл не найден на сервере (возможно был удален как устаревший). Пожалуйста, загрузите файл с диска на сервер заново.');
|
||||||
|
await utils.touchFile(downloadedFilename);
|
||||||
isUploaded = true;
|
isUploaded = true;
|
||||||
}
|
}
|
||||||
wState.set({progress: 100});
|
wState.set({progress: 100});
|
||||||
@@ -117,7 +118,7 @@ class ReaderWorker {
|
|||||||
if (!await fs.pathExists(outFilename)) {
|
if (!await fs.pathExists(outFilename)) {
|
||||||
await fs.move(file.path, outFilename);
|
await fs.move(file.path, outFilename);
|
||||||
} else {
|
} else {
|
||||||
await fs.utimes(outFilename, Date.now()/1000, Date.now()/1000);
|
await utils.touchFile(outFilename);
|
||||||
await fs.remove(file.path);
|
await fs.remove(file.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
@@ -8,7 +9,12 @@ function randomHexString(len) {
|
|||||||
return crypto.randomBytes(len).toString('hex')
|
return crypto.randomBytes(len).toString('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function touchFile(filename) {
|
||||||
|
await fs.utimes(filename, Date.now()/1000, Date.now()/1000);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sleep,
|
sleep,
|
||||||
randomHexString
|
randomHexString,
|
||||||
|
touchFile
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user