Улучшена работа с inpx, теперь понимает файлы в каталогах (без zip-архива)

This commit is contained in:
Book Pauk
2023-04-12 17:14:12 +07:00
parent 4b4f7bd697
commit 24d609d8f1

View File

@@ -372,17 +372,28 @@ class WebWorker {
async extractBook(bookPath) { async extractBook(bookPath) {
const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`; const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
const folder = `${this.config.libDir}/${path.dirname(bookPath)}`; bookPath = bookPath.replace(/\\/g, '/').replace(/\/\//g, '/');
const file = path.basename(bookPath);
const zipReader = new ZipReader(); const i = bookPath.indexOf('/');
await zipReader.open(folder); const folder = `${this.config.libDir}/${(i >= 0 ? bookPath.substring(0, i) : bookPath )}`;
const file = (i >= 0 ? bookPath.substring(i + 1) : '' );
try { const fullPath = `${folder}/${file}`;
await zipReader.extractToFile(file, outFile);
if (!file || await fs.pathExists(fullPath)) {// файл есть на диске
await fs.copy(fullPath, outFile);
return outFile; return outFile;
} finally { } else {// файл в zip-архиве
await zipReader.close(); const zipReader = new ZipReader();
await zipReader.open(folder);
try {
await zipReader.extractToFile(file, outFile);
return outFile;
} finally {
await zipReader.close();
}
} }
} }