mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Handle not replacing missing files in epub (#529)
* Handle not replacing missing files in epub * fix gitignore
This commit is contained in:
parent
ad9dd35fb5
commit
eeb566c6f8
2 changed files with 23 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "epubjs",
|
||||
"version": "0.3.7",
|
||||
"version": "0.3.8",
|
||||
"description": "Parse and Render Epubs",
|
||||
"main": "lib/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
|
|
|
@ -103,12 +103,17 @@ class Resources {
|
|||
map( (url) => {
|
||||
var absolute = resolver(url);
|
||||
|
||||
return archive.createUrl(absolute, {"base64": (this.settings.replacements === "base64")});
|
||||
return archive.createUrl(absolute, {"base64": (this.settings.replacements === "base64")}).
|
||||
catch((err) => {
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.all(replacements)
|
||||
.then( (replacementUrls) => {
|
||||
this.replacementUrls = replacementUrls;
|
||||
this.replacementUrls = replacementUrls.filter((url) => {
|
||||
return (typeof(url) === "string");
|
||||
});
|
||||
return replacementUrls;
|
||||
});
|
||||
}
|
||||
|
@ -132,7 +137,8 @@ class Resources {
|
|||
if (indexInUrls > -1) {
|
||||
this.replacementUrls[indexInUrls] = replacementUrl;
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
|
||||
|
||||
replaced.push(replacement);
|
||||
}.bind(this));
|
||||
|
@ -162,6 +168,7 @@ class Resources {
|
|||
|
||||
// Get the text of the css file from the archive
|
||||
var textResponse = archive.getText(absolute);
|
||||
|
||||
// Get asset links relative to css file
|
||||
var relUrls = this.urls.map( (assetHref) => {
|
||||
var resolved = resolver(assetHref);
|
||||
|
@ -170,6 +177,13 @@ class Resources {
|
|||
return relative;
|
||||
});
|
||||
|
||||
if (!textResponse) {
|
||||
// file not found, don't replace
|
||||
return new Promise(function(resolve){
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
return textResponse.then( (text) => {
|
||||
// Replacements in the css text
|
||||
text = substitute(text, relUrls, this.replacementUrls);
|
||||
|
@ -182,6 +196,11 @@ class Resources {
|
|||
}
|
||||
|
||||
return newUrl;
|
||||
}, (err) => {
|
||||
// handle response errors
|
||||
return new Promise(function(resolve){
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue