1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-02 14:49:16 +02:00
This commit is contained in:
Anees Ijaz 2023-05-17 11:24:01 -07:00 committed by GitHub
commit 07b6b4373f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
import EventEmitter from "event-emitter"; import EventEmitter from "event-emitter";
import {extend, defer} from "./utils/core"; import { extend, defer } from "./utils/core";
import Url from "./utils/url"; import Url from "./utils/url";
import Path from "./utils/path"; import Path from "./utils/path";
import Spine from "./spine"; import Spine from "./spine";
@ -50,10 +50,10 @@ const INPUT_TYPE = {
class Book { class Book {
constructor(url, options) { constructor(url, options) {
// Allow passing just options to the Book // Allow passing just options to the Book
if (typeof(options) === "undefined" && if (typeof (options) === "undefined" &&
typeof(url) !== "string" && typeof (url) !== "string" &&
url instanceof Blob === false && url instanceof Blob === false &&
url instanceof ArrayBuffer === false) { url instanceof ArrayBuffer === false) {
options = url; options = url;
url = undefined; url = undefined;
} }
@ -229,9 +229,9 @@ class Book {
this.store(this.settings.store); this.store(this.settings.store);
} }
if(url) { if (url) {
this.open(url, this.settings.openAs).catch((error) => { this.open(url, this.settings.openAs).catch((error) => {
var err = new Error("Cannot load book at "+ url ); var err = new Error("Cannot load book at " + url);
this.emit(EVENTS.BOOK.OPEN_FAILED, err); this.emit(EVENTS.BOOK.OPEN_FAILED, err);
}); });
} }
@ -261,10 +261,10 @@ class Book {
this.url = new Url("/", ""); this.url = new Url("/", "");
opening = this.request(input, "binary", this.settings.requestCredentials, this.settings.requestHeaders) opening = this.request(input, "binary", this.settings.requestCredentials, this.settings.requestHeaders)
.then(this.openEpub.bind(this)); .then(this.openEpub.bind(this));
} else if(type == INPUT_TYPE.OPF) { } else if (type == INPUT_TYPE.OPF) {
this.url = new Url(input); this.url = new Url(input);
opening = this.openPackaging(this.url.Path.toString()); opening = this.openPackaging(this.url.Path.toString());
} else if(type == INPUT_TYPE.MANIFEST) { } else if (type == INPUT_TYPE.MANIFEST) {
this.url = new Url(input); this.url = new Url(input);
opening = this.openManifest(this.url.Path.toString()); opening = this.openManifest(this.url.Path.toString());
} else { } else {
@ -345,7 +345,7 @@ class Book {
*/ */
load(path) { load(path) {
var resolved = this.resolve(path); var resolved = this.resolve(path);
if(this.archived) { if (this.archived) {
return this.archive.request(resolved); return this.archive.request(resolved);
} else { } else {
return this.request(resolved, null, this.settings.requestCredentials, this.settings.requestHeaders); return this.request(resolved, null, this.settings.requestCredentials, this.settings.requestHeaders);
@ -373,7 +373,7 @@ class Book {
resolved = this.path.resolve(path); resolved = this.path.resolve(path);
} }
if(absolute != false && this.url) { if (absolute != false && this.url) {
resolved = this.url.resolve(resolved); resolved = this.url.resolve(resolved);
} }
@ -416,7 +416,7 @@ class Book {
return INPUT_TYPE.BASE64; return INPUT_TYPE.BASE64;
} }
if(typeof(input) != "string") { if (typeof (input) != "string") {
return INPUT_TYPE.BINARY; return INPUT_TYPE.BINARY;
} }
@ -433,15 +433,15 @@ class Book {
return INPUT_TYPE.DIRECTORY; return INPUT_TYPE.DIRECTORY;
} }
if(extension === "epub"){ if (extension === "epub") {
return INPUT_TYPE.EPUB; return INPUT_TYPE.EPUB;
} }
if(extension === "opf"){ if (extension === "opf") {
return INPUT_TYPE.OPF; return INPUT_TYPE.OPF;
} }
if(extension === "json"){ if (extension === "json") {
return INPUT_TYPE.MANIFEST; return INPUT_TYPE.MANIFEST;
} }
} }
@ -496,15 +496,15 @@ class Book {
this.isOpen = true; this.isOpen = true;
if(this.archived || this.settings.replacements && this.settings.replacements != "none") { if (this.archived || this.settings.replacements && this.settings.replacements != "none") {
this.replacements().then(() => { this.replacements().then(() => {
this.loaded.displayOptions.then(() => { this.loaded.displayOptions.then(() => {
this.opening.resolve(this); this.opening.resolve(this);
}); });
}) })
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);
}); });
} else { } else {
// Resolve book opened promise // Resolve book opened promise
this.loaded.displayOptions.then(() => { this.loaded.displayOptions.then(() => {
@ -670,7 +670,7 @@ class Book {
} }
if (this.archived) { if (this.archived) {
return this.archive.createUrl(this.cover); return this.archive.createUrl(this.cover, { "base64": (this.settings.replacements === "base64") });
} else { } else {
return this.cover; return this.cover;
} }