Zipping book.json

This commit is contained in:
Vahagn Khachatryan
2018-11-26 15:41:50 +00:00
parent 68f43a2a50
commit fcf688e946

View File

@@ -1,5 +1,3 @@
document.body.style.border = "5px solid red";
function onError(error) { function onError(error) {
console.error(`Error: ${error}`); console.error(`Error: ${error}`);
$('#error-message').text(`Error: ${error}`); $('#error-message').text(`Error: ${error}`);
@@ -46,33 +44,6 @@ function extractBookId(url){
} }
} }
// class MiniWebServer{
// constructor() {
// this.url = "http://127.0.0.1:8080/test.zip"
// }
// downloadTestZip(){
// console.info(`Downloading ${this.url}`)
// return fetch(this.url, {
// credentials: 'include'
// }).then((res) => {
// console.log(`Getting blob.`)
// return res.blob()
// }).then(JSZip.loadAsync)
// .then((zip) => {
// this.zip = zip
// })
// }
// fetchUrl(url){
// let name = "meta/"+url.replace(/[^a-z0-9]/gi, '_').toLowerCase()
// this.zip.file(name)
// .
// }
// }
class Book{ class Book{
constructor(book_id, epub) { constructor(book_id, epub) {
@@ -162,30 +133,6 @@ class Book{
return Promise.all(downloads) return Promise.all(downloads)
} }
downloadMetaContent(){
let downloads = []
// downloads.push(this.downloadResource(this.book_info.cover))
downloads.push(
this.downloadJson(this.book_info.toc)
.then((json)=>{
this.book_toc=json
}))
downloads.push(
this.downloadJson(this.book_info.flat_toc)
.then((json)=>{
this.book_flattoc=json
}))
downloads.push(
Promise.map(this.book_info.chapters, (chapter) => {
return this.downloadJson(chapter)
.then((json) => {
return this.extractChapterAssets(json)
})
},{concurrency: 1}))
return Promise.all(downloads)
}
extractChapterAssets(json){ extractChapterAssets(json){
if (!json.asset_base_url if (!json.asset_base_url
@@ -198,7 +145,8 @@ class Book{
url: json.content, url: json.content,
file: json.full_path, file: json.full_path,
context: null, context: null,
mime: null mime: null,
content: null,
}) })
// List of images. // List of images.
for (let idx in json.images){ for (let idx in json.images){
@@ -272,7 +220,8 @@ function onDownloadBookClicked(){
.then(() => { renderInfo(book); }) .then(() => { renderInfo(book); })
.then(() => { return book.downloadChapterList(); }) .then(() => { return book.downloadChapterList(); })
.then(() => { return renderChapterList(book); }) .then(() => { return renderChapterList(book); })
.then(() => { return book.downloadContent(); }) .then(() => { return book.downloadMetaContent(); })
// .then(() => { return book.downloadContent(); })
.then(() => { return createEpub(book, epub); }) .then(() => { return createEpub(book, epub); })
.then(() => { return epub.generateAsync(); }) .then(() => { return epub.generateAsync(); })
.then((file) => { .then((file) => {