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