Поправки для поддержки reverse-proxy, рефакторинг

This commit is contained in:
Book Pauk
2022-12-04 17:12:24 +07:00
parent 105680e38a
commit 409befce5e
6 changed files with 123 additions and 82 deletions

View File

@@ -60,7 +60,7 @@ class WebWorker {
const dirConfig = [
{
dir: config.filesDir,
dir: config.bookDir,
maxSize: config.maxFilesDirSize,
},
];
@@ -380,8 +380,8 @@ class WebWorker {
hash = await this.remoteLib.downloadBook(bookUid);
}
const link = `${this.config.filesPathStatic}/${hash}`;
const bookFile = `${this.config.filesDir}/${hash}`;
const link = `${this.config.bookPathStatic}/${hash}`;
const bookFile = `${this.config.bookDir}/${hash}`;
const bookFileDesc = `${bookFile}.d.json`;
if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) {
@@ -447,11 +447,11 @@ class WebWorker {
rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
if (rows.length) {//хеш найден по bookPath
const hash = rows[0].hash;
const bookFile = `${this.config.filesDir}/${hash}`;
const bookFile = `${this.config.bookDir}/${hash}`;
const bookFileDesc = `${bookFile}.d.json`;
if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) {
link = `${this.config.filesPathStatic}/${hash}`;
link = `${this.config.bookPathStatic}/${hash}`;
}
}
@@ -479,7 +479,7 @@ class WebWorker {
let bookInfo = await this.getBookLink(bookUid);
const hash = path.basename(bookInfo.link);
const bookFile = `${this.config.filesDir}/${hash}`;
const bookFile = `${this.config.bookDir}/${hash}`;
const bookFileInfo = `${bookFile}.i.json`;
let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`});
@@ -501,7 +501,7 @@ class WebWorker {
result.fb2 = fb2.rawNodes;
if (cover) {
result.cover = `${this.config.filesPathStatic}/${hash}${coverExt}`;
result.cover = `${this.config.bookPathStatic}/${hash}${coverExt}`;
await fs.writeFile(`${bookFile}${coverExt}`, cover);
}
}