Рефакторинг, поправки
This commit is contained in:
@@ -6,15 +6,27 @@ const utils = require('../utils');
|
|||||||
|
|
||||||
class MegaStorage {
|
class MegaStorage {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.readingFiles = false;
|
this.inited = false;
|
||||||
this.stats = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(config) {
|
async init(config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.megaStorageDir = config.megaStorageDir;
|
this.megaStorageDir = config.megaStorageDir;
|
||||||
|
this.statsPath = `${this.megaStorageDir}/stats.json`;
|
||||||
this.compressLevel = (config.compressLevel ? config.compressLevel : 4);
|
this.compressLevel = (config.compressLevel ? config.compressLevel : 4);
|
||||||
await fs.ensureDir(this.megaStorageDir);
|
await fs.ensureDir(this.megaStorageDir);
|
||||||
|
|
||||||
|
this.readingFiles = false;
|
||||||
|
this.stats = {};
|
||||||
|
|
||||||
|
if (await fs.pathExists(this.statsPath)) {
|
||||||
|
this.stats = Object.assign({},
|
||||||
|
JSON.parse(await fs.readFile(this.statsPath, 'utf8')),
|
||||||
|
this.stats
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async nameHash(filename) {
|
async nameHash(filename) {
|
||||||
@@ -63,17 +75,18 @@ class MegaStorage {
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
dir = this.megaStorageDir;
|
dir = this.megaStorageDir;
|
||||||
|
|
||||||
|
let result;
|
||||||
const files = await fs.readdir(dir, { withFileTypes: true });
|
const files = await fs.readdir(dir, { withFileTypes: true });
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (!this.readingFiles)
|
if (!this.readingFiles)
|
||||||
return;
|
return;
|
||||||
const found = path.resolve(dir, file.name);
|
const found = path.resolve(dir, file.name);
|
||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
await this._findFiles(callback, found);
|
result = await this._findFiles(callback, found);
|
||||||
else
|
else
|
||||||
callback(found);
|
callback(found);
|
||||||
}
|
}
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async startFindFiles(callback, dir) {
|
async startFindFiles(callback, dir) {
|
||||||
|
|||||||
Reference in New Issue
Block a user