mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Allow loading epub from container xml url
This commit is contained in:
parent
dce1d943a9
commit
9e13f62a89
2 changed files with 18 additions and 6 deletions
|
@ -5,7 +5,7 @@ import Packaging from "./packaging.js";
|
||||||
import Navigation from "./navigation.js";
|
import Navigation from "./navigation.js";
|
||||||
import PageList from "./pagelist.js";
|
import PageList from "./pagelist.js";
|
||||||
import Spine from "./spine.js";
|
import Spine from "./spine.js";
|
||||||
import { extension } from "../utils/url.js";
|
import { extension, resolve } from "../utils/url.js";
|
||||||
import EpubCFI from "../utils/epubcfi.js";
|
import EpubCFI from "../utils/epubcfi.js";
|
||||||
|
|
||||||
const CONTAINER_PATH = "META-INF/container.xml";
|
const CONTAINER_PATH = "META-INF/container.xml";
|
||||||
|
@ -13,7 +13,8 @@ const IBOOKS_DISPLAY_OPTIONS_PATH = "META-INF/com.apple.ibooks.display-options.x
|
||||||
const INPUT_TYPE = {
|
const INPUT_TYPE = {
|
||||||
EPUB: "epub",
|
EPUB: "epub",
|
||||||
OPF: "opf",
|
OPF: "opf",
|
||||||
DIRECTORY: "directory"
|
DIRECTORY: "directory",
|
||||||
|
CONTAINER: "container"
|
||||||
};
|
};
|
||||||
|
|
||||||
class Epub extends Publication {
|
class Epub extends Publication {
|
||||||
|
@ -45,6 +46,10 @@ class Epub extends Publication {
|
||||||
if (ext === "opf") {
|
if (ext === "opf") {
|
||||||
return INPUT_TYPE.OPF;
|
return INPUT_TYPE.OPF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ext === "xml") {
|
||||||
|
return INPUT_TYPE.CONTAINER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +62,7 @@ class Epub extends Publication {
|
||||||
const xml = await this.load(url);
|
const xml = await this.load(url);
|
||||||
|
|
||||||
this.container = new Container(xml);
|
this.container = new Container(xml);
|
||||||
return this.container.packagePath;
|
return this.container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,16 +175,21 @@ class Epub extends Publication {
|
||||||
const type = what || this.determineType(url);
|
const type = what || this.determineType(url);
|
||||||
let packaging;
|
let packaging;
|
||||||
|
|
||||||
this.url = url;
|
|
||||||
|
|
||||||
if (type === INPUT_TYPE.EPUB) {
|
if (type === INPUT_TYPE.EPUB) {
|
||||||
throw new Error("Epub must be unarchived");
|
throw new Error("Epub must be unarchived");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === INPUT_TYPE.DIRECTORY) {
|
if (type === INPUT_TYPE.DIRECTORY) {
|
||||||
const container = await this.loadContainer(CONTAINER_PATH);
|
const container = await this.loadContainer(CONTAINER_PATH);
|
||||||
|
this.url = url + container.packagePath;
|
||||||
packaging = await this.loadPackaging(container.packagePath);
|
packaging = await this.loadPackaging(container.packagePath);
|
||||||
|
} else if (type === INPUT_TYPE.CONTAINER) {
|
||||||
|
const container = await this.loadContainer(url);
|
||||||
|
const packageUrl = resolve(url, "../" + container.packagePath);
|
||||||
|
this.url = packageUrl;
|
||||||
|
packaging = await this.loadPackaging(packageUrl);
|
||||||
} else {
|
} else {
|
||||||
|
this.url = url;
|
||||||
packaging = await this.loadPackaging(url);
|
packaging = await this.loadPackaging(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ export function createUrl(inputUrl, base) {
|
||||||
if (typeof(window) !== "undefined" &&
|
if (typeof(window) !== "undefined" &&
|
||||||
typeof(window.location) !== "undefined") {
|
typeof(window.location) !== "undefined") {
|
||||||
locationBase = window.location.href;
|
locationBase = window.location.href;
|
||||||
|
} else {
|
||||||
|
locationBase = "http://example.com"; // Prevent URL error
|
||||||
}
|
}
|
||||||
return new URL(inputUrl, locationBase);
|
return new URL(inputUrl, locationBase);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue