Работа над RemoteLib

This commit is contained in:
Book Pauk
2022-10-07 19:06:00 +07:00
parent e6dfe4d221
commit a82392197f
6 changed files with 181 additions and 17 deletions

View File

@@ -38,6 +38,11 @@ class WebWorker {
if (!instance) {
this.config = config;
this.workerState = new WorkerState();
this.remoteLib = null;
if (config.remoteLib) {
this.remoteLib = new RemoteLib(config);
}
this.wState = this.workerState.getControl('server_state');
this.myState = '';
@@ -314,9 +319,16 @@ class WebWorker {
async restoreBook(bookPath, downFileName) {
const db = this.db;
const extractedFile = await this.extractBook(bookPath);
let extractedFile = '';
let hash = '';
if (!this.remoteLib) {
extractedFile = await this.extractBook(bookPath);
hash = await utils.getFileHash(extractedFile, 'sha256', 'hex');
} else {
hash = await this.remoteLib.downloadBook(bookPath, downFileName);
}
const hash = await utils.getFileHash(extractedFile, 'sha256', 'hex');
const link = `/files/${hash}`;
const publicPath = `${this.config.publicDir}${link}`;
@@ -328,7 +340,8 @@ class WebWorker {
await fs.remove(extractedFile);
await fs.move(tmpFile, publicPath, {overwrite: true});
} else {
await fs.remove(extractedFile);
if (extractedFile)
await fs.remove(extractedFile);
await utils.touchFile(publicPath);
}
@@ -506,9 +519,8 @@ class WebWorker {
while (this.myState != ssNormal)
await utils.sleep(1000);
if (this.config.remoteLib) {
const remoteLib = new RemoteLib(this.config);
await remoteLib.getInpxFile(60*1000);
if (this.remoteLib) {
await this.remoteLib.downloadInpxFile(60*1000);
}
const newInpxHash = await inpxHashCreator.getHash();