Улучшена работа с inpx, теперь понимает файлы в каталогах (без zip-архива)
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user