Добавлено формирование zip-файла (#4)

This commit is contained in:
Book Pauk
2022-12-05 18:06:20 +07:00
parent de9471c2d5
commit b3ed9ea89c
3 changed files with 100 additions and 54 deletions

View File

@@ -128,7 +128,19 @@ class BookPage extends BasePage {
if (bookInfo) {
const {genreMap} = await this.getGenres();
const fileFormat = `${bookInfo.book.ext}+zip`;
//format
const ext = bookInfo.book.ext;
let fileFormat = `${ext}+zip`;
let downHref = bookInfo.link;
if (ext === 'mobi') {
fileFormat = 'x-mobipocket-ebook';
} else if (ext == 'epub') {
//
} else {
downHref = `${bookInfo.link}/zip`;
}
//entry
const e = this.makeEntry({
@@ -183,7 +195,7 @@ class BookPage extends BasePage {
}
//links
e.link = [ this.downLink({href: bookInfo.link, type: `application/${fileFormat}`}) ];
e.link = [ this.downLink({href: downHref, type: `application/${fileFormat}`}) ];
if (bookInfo.cover) {
let coverType = 'image/jpeg';
if (path.extname(bookInfo.cover) == '.png')

View File

@@ -109,9 +109,10 @@ function gzipFile(inputFile, outputFile, level = 1) {
.pipe(gzip).on('error', reject)
.pipe(output).on('error', reject)
.on('finish', (err) => {
if (err) reject(err);
else resolve();
});
if (err) reject(err);
else resolve();
}
);
});
}
@@ -125,9 +126,10 @@ function gunzipFile(inputFile, outputFile) {
.pipe(gzip).on('error', reject)
.pipe(output).on('error', reject)
.on('finish', (err) => {
if (err) reject(err);
else resolve();
});
if (err) reject(err);
else resolve();
}
);
});
}