@prose-reader/streamer 1.281.0 → 1.282.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +342 -321
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +13 -13
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,96 +1,117 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { detectMimeTypeFromName as x, Report as se, isXmlBasedMimeType as ie, parseContentType as ae, urlJoin as T } from "@prose-reader/shared";
|
|
2
2
|
import { XmlDocument as y, XmlTextNode as ce, XmlElement as de } from "xmldoc";
|
|
3
|
-
import { Subject as
|
|
4
|
-
const D = (n,
|
|
5
|
-
const s = n.split(/(\d+)/), r =
|
|
6
|
-
for (let
|
|
7
|
-
if (s[
|
|
8
|
-
return s[
|
|
3
|
+
import { Subject as R, mergeMap as O, EMPTY as B, pairwise as le, filter as P, startWith as pe, from as W, tap as j, catchError as S, switchMap as I, merge as X, first as V, takeUntil as me, map as $, ignoreElements as ue, BehaviorSubject as fe, distinctUntilChanged as he, shareReplay as ge, NEVER as H, timer as ye, finalize as _, of as G, lastValueFrom as q } from "rxjs";
|
|
4
|
+
const D = (n, t) => {
|
|
5
|
+
const s = n.split(/(\d+)/), r = t.split(/(\d+)/);
|
|
6
|
+
for (let e = 0, o = s.length; e < o; e++)
|
|
7
|
+
if (s[e] !== r[e])
|
|
8
|
+
return s[e]?.match(/\d/) ? +(s[e] || "") - +(r[e] || "") : (s[e] || "").localeCompare(r[e] || "");
|
|
9
9
|
return 1;
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
-
}, it = async (n, { orderByAlpha:
|
|
10
|
+
}, w = (n) => n.substring(n.lastIndexOf("/") + 1) || n, J = (n) => n.endsWith("/") ? n.slice(0, -1) : n, be = (n) => {
|
|
11
|
+
const t = n.lastIndexOf("/");
|
|
12
|
+
return t >= 0 ? n.substring(0, t) : "";
|
|
13
|
+
}, it = async (n, { orderByAlpha: t, name: s } = {}) => {
|
|
14
14
|
let r = n;
|
|
15
|
-
return
|
|
15
|
+
return t && (r = r.slice().sort((e, o) => D(e.name, o.name))), {
|
|
16
16
|
filename: s || "",
|
|
17
|
-
records: r.map((
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
records: r.map((e) => {
|
|
18
|
+
const o = e.size, i = w(e.name);
|
|
19
|
+
return e.isDir ? {
|
|
20
|
+
dir: !0,
|
|
21
|
+
basename: i,
|
|
22
|
+
uri: e.name,
|
|
23
|
+
size: o
|
|
24
|
+
} : {
|
|
25
|
+
dir: e.isDir,
|
|
26
|
+
basename: i,
|
|
27
|
+
encodingFormat: x(e.name),
|
|
28
|
+
uri: e.name,
|
|
29
|
+
blob: async () => new Blob([await e.data()], {
|
|
30
|
+
type: x(e.name) ?? ""
|
|
31
|
+
}),
|
|
32
|
+
string: async () => {
|
|
33
|
+
const a = await e.data();
|
|
34
|
+
return String.fromCharCode.apply(
|
|
35
|
+
null,
|
|
36
|
+
Array.from(new Uint16Array(a))
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
size: o
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
31
42
|
close: () => Promise.resolve()
|
|
32
43
|
};
|
|
33
44
|
}, we = "@prose-reader/streamer", m = se.namespace(we, !1, {
|
|
34
45
|
color: "#ffae42"
|
|
35
46
|
}), ve = (n) => {
|
|
36
|
-
const
|
|
47
|
+
const t = {};
|
|
37
48
|
for (const r of n) {
|
|
38
|
-
const
|
|
39
|
-
let o =
|
|
40
|
-
for (let i = 0; i <
|
|
41
|
-
const a =
|
|
49
|
+
const e = r.split("/");
|
|
50
|
+
let o = t;
|
|
51
|
+
for (let i = 0; i < e.length; i++) {
|
|
52
|
+
const a = e[i];
|
|
42
53
|
a !== void 0 && (o[a] || (o[a] = {}), o = o[a]);
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
|
-
const s = (r,
|
|
46
|
-
const l = i === a.length - 1, c =
|
|
56
|
+
const s = (r, e = "") => Object.keys(r).sort().map((o, i, a) => {
|
|
57
|
+
const l = i === a.length - 1, c = e + (l ? "└── " : "├── "), d = e + (l ? " " : "│ "), p = r[o];
|
|
47
58
|
return p && Object.keys(p).length > 0 ? `${c}${o}/
|
|
48
59
|
${s(p, d)}` : `${c}${o}`;
|
|
49
60
|
}).join(`
|
|
50
61
|
`);
|
|
51
|
-
return s(
|
|
52
|
-
}, at = async (n, { orderByAlpha:
|
|
62
|
+
return s(t);
|
|
63
|
+
}, at = async (n, { orderByAlpha: t, name: s } = {}) => {
|
|
53
64
|
let r = Object.values(n.files);
|
|
54
|
-
|
|
55
|
-
const
|
|
65
|
+
t && (r = r.slice().sort((o, i) => D(o.name, i.name)));
|
|
66
|
+
const e = {
|
|
56
67
|
filename: s || "",
|
|
57
|
-
records: r.map((o) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
records: r.map((o) => {
|
|
69
|
+
const i = o._data.uncompressedSize, a = w(o.name);
|
|
70
|
+
return o.dir ? {
|
|
71
|
+
dir: !0,
|
|
72
|
+
basename: a,
|
|
73
|
+
uri: o.name,
|
|
74
|
+
size: i
|
|
75
|
+
} : {
|
|
76
|
+
dir: !1,
|
|
77
|
+
basename: w(o.name),
|
|
78
|
+
uri: o.name,
|
|
79
|
+
encodingFormat: x(o.name),
|
|
80
|
+
blob: () => o.async("blob"),
|
|
81
|
+
string: () => o.async("string"),
|
|
82
|
+
...o.internalStream && {
|
|
83
|
+
stream: o.internalStream
|
|
84
|
+
},
|
|
85
|
+
// this is private API
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
size: o._data.uncompressedSize
|
|
88
|
+
};
|
|
89
|
+
}),
|
|
70
90
|
close: () => Promise.resolve()
|
|
71
91
|
};
|
|
72
|
-
if (m.log("Generated archive",
|
|
92
|
+
if (m.log("Generated archive", e), process.env.NODE_ENV === "development" && m.isEnabled()) {
|
|
73
93
|
const o = ve(r.map((i) => i.name));
|
|
74
94
|
m.groupCollapsed(...m.getGroupArgs("Archive folder structure")), m.log(`
|
|
75
95
|
${o}`), m.groupEnd();
|
|
76
96
|
}
|
|
77
|
-
return
|
|
78
|
-
}, ct = async (n, { name:
|
|
97
|
+
return e;
|
|
98
|
+
}, ct = async (n, { name: t } = {}) => {
|
|
79
99
|
const s = await n.getFilesArray(), r = {
|
|
80
100
|
close: () => n.close(),
|
|
81
|
-
filename:
|
|
82
|
-
records: s.map((
|
|
101
|
+
filename: t ?? "",
|
|
102
|
+
records: s.map((e) => ({
|
|
83
103
|
dir: !1,
|
|
84
|
-
basename:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
basename: e.file.name,
|
|
105
|
+
encodingFormat: x(e.file.name),
|
|
106
|
+
size: e.file.size,
|
|
107
|
+
uri: `${e.path}${e.file.name}`,
|
|
108
|
+
blob: async () => await e.file.extract(),
|
|
109
|
+
string: async () => (await e.file.extract()).text()
|
|
89
110
|
}))
|
|
90
111
|
};
|
|
91
112
|
return m.log("Generated archive", r), r;
|
|
92
113
|
}, dt = async (n, {
|
|
93
|
-
mimeType:
|
|
114
|
+
mimeType: t,
|
|
94
115
|
direction: s
|
|
95
116
|
} = { mimeType: "text/plain" }) => {
|
|
96
117
|
const r = `
|
|
@@ -114,7 +135,7 @@ ${o}`), m.groupEnd();
|
|
|
114
135
|
records: [
|
|
115
136
|
{
|
|
116
137
|
dir: !1,
|
|
117
|
-
basename:
|
|
138
|
+
basename: w("generated.opf"),
|
|
118
139
|
uri: "generated.opf",
|
|
119
140
|
blob: async () => new Blob([r]),
|
|
120
141
|
string: async () => r,
|
|
@@ -122,38 +143,38 @@ ${o}`), m.groupEnd();
|
|
|
122
143
|
},
|
|
123
144
|
{
|
|
124
145
|
dir: !1,
|
|
125
|
-
basename:
|
|
146
|
+
basename: w("p01.txt"),
|
|
126
147
|
uri: "p01.txt",
|
|
127
148
|
blob: async () => typeof n == "string" ? new Blob([n]) : n,
|
|
128
149
|
string: async () => typeof n == "string" ? n : n.text(),
|
|
129
150
|
size: typeof n == "string" ? n.length : n.size,
|
|
130
|
-
encodingFormat:
|
|
151
|
+
encodingFormat: t
|
|
131
152
|
}
|
|
132
153
|
],
|
|
133
154
|
close: () => Promise.resolve()
|
|
134
155
|
};
|
|
135
|
-
}, lt = async (n,
|
|
156
|
+
}, lt = async (n, t) => {
|
|
136
157
|
const s = `
|
|
137
158
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
138
159
|
<metadata>
|
|
139
|
-
<meta property="rendition:layout">${
|
|
140
|
-
${
|
|
160
|
+
<meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
161
|
+
${t?.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
141
162
|
</metadata>
|
|
142
163
|
<manifest>
|
|
143
164
|
${n.map(
|
|
144
|
-
(o) => `<item id="${
|
|
165
|
+
(o) => `<item id="${w(o)}" href="${o}" media-type="${x(o)}"/>`
|
|
145
166
|
).join(`
|
|
146
167
|
`)}
|
|
147
168
|
</manifest>
|
|
148
169
|
<spine>
|
|
149
|
-
${n.map((o) => `<itemref idref="${
|
|
170
|
+
${n.map((o) => `<itemref idref="${w(o)}" />`).join(`
|
|
150
171
|
`)}
|
|
151
172
|
</spine>
|
|
152
173
|
</package>
|
|
153
174
|
`, r = n.map((o) => ({
|
|
154
175
|
dir: !1,
|
|
155
|
-
basename:
|
|
156
|
-
encodingFormat:
|
|
176
|
+
basename: w(o),
|
|
177
|
+
encodingFormat: x(o),
|
|
157
178
|
uri: o,
|
|
158
179
|
size: 100 / n.length,
|
|
159
180
|
blob: async () => (await fetch(o)).blob(),
|
|
@@ -175,7 +196,7 @@ ${o}`), m.groupEnd();
|
|
|
175
196
|
enableReport: n
|
|
176
197
|
} = {}) => {
|
|
177
198
|
m.enable(!!n);
|
|
178
|
-
},
|
|
199
|
+
}, E = (n) => {
|
|
179
200
|
const s = Object.values(n.records).filter(
|
|
180
201
|
(r) => !r.dir
|
|
181
202
|
).find((r) => r.uri.endsWith(".opf"));
|
|
@@ -183,45 +204,45 @@ ${o}`), m.groupEnd();
|
|
|
183
204
|
data: s,
|
|
184
205
|
basePath: s?.uri.substring(0, s.uri.lastIndexOf("/")) || ""
|
|
185
206
|
};
|
|
186
|
-
}, $e = ({ archive: n }) => async (
|
|
207
|
+
}, $e = ({ archive: n }) => async (t) => {
|
|
187
208
|
const s = n.records.find(
|
|
188
|
-
(
|
|
209
|
+
(e) => e.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
|
|
189
210
|
);
|
|
190
211
|
if (!s || s.dir)
|
|
191
|
-
return
|
|
212
|
+
return t;
|
|
192
213
|
const r = await (await s.blob()).text();
|
|
193
214
|
try {
|
|
194
215
|
const i = new y(r).childNamed("platform")?.childrenNamed("option")?.find((a) => a.attr.name === "fixed-layout")?.val || "false";
|
|
195
216
|
return {
|
|
196
|
-
...
|
|
197
|
-
renditionLayout: i === "true" ? "pre-paginated" :
|
|
217
|
+
...t,
|
|
218
|
+
renditionLayout: i === "true" ? "pre-paginated" : t.renditionLayout
|
|
198
219
|
};
|
|
199
|
-
} catch (
|
|
220
|
+
} catch (e) {
|
|
200
221
|
return console.error(
|
|
201
222
|
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
202
223
|
`,
|
|
203
224
|
r
|
|
204
|
-
), console.error(
|
|
225
|
+
), console.error(e), t;
|
|
205
226
|
}
|
|
206
227
|
}, xe = async (n) => {
|
|
207
|
-
const
|
|
228
|
+
const t = {
|
|
208
229
|
renditionLayout: void 0
|
|
209
230
|
};
|
|
210
231
|
return await Promise.all(
|
|
211
232
|
n.records.map(async (s) => {
|
|
212
233
|
if (s.uri.endsWith("com.kobobooks.display-options.xml") && !s.dir) {
|
|
213
|
-
const
|
|
214
|
-
|
|
234
|
+
const e = new y(await s.string()).childNamed("platform")?.childNamed("option");
|
|
235
|
+
e?.attr?.name === "fixed-layout" && e.val === "true" && (t.renditionLayout = "pre-paginated");
|
|
215
236
|
}
|
|
216
237
|
})
|
|
217
|
-
),
|
|
218
|
-
}, Fe = ({ archive: n }) => async (
|
|
238
|
+
), t;
|
|
239
|
+
}, Fe = ({ archive: n }) => async (t) => {
|
|
219
240
|
const s = await xe(n);
|
|
220
241
|
return {
|
|
221
|
-
...
|
|
222
|
-
renditionLayout:
|
|
242
|
+
...t,
|
|
243
|
+
renditionLayout: t.renditionLayout ?? s.renditionLayout
|
|
223
244
|
};
|
|
224
|
-
}, Ee = ({ archive: n, baseUrl:
|
|
245
|
+
}, Ee = ({ archive: n, baseUrl: t }) => async () => {
|
|
225
246
|
const s = Object.values(n.records).filter((r) => !r.dir);
|
|
226
247
|
return {
|
|
227
248
|
filename: n.filename,
|
|
@@ -229,14 +250,14 @@ ${o}`), m.groupEnd();
|
|
|
229
250
|
renditionLayout: void 0,
|
|
230
251
|
renditionSpread: "auto",
|
|
231
252
|
readingDirection: "ltr",
|
|
232
|
-
spineItems: s.filter((r) => !r.basename.endsWith(".db")).map((r,
|
|
233
|
-
const o =
|
|
253
|
+
spineItems: s.filter((r) => !r.basename.endsWith(".db")).map((r, e) => {
|
|
254
|
+
const o = t || (/^https?:\/\//.test(r.uri) ? "" : "file://");
|
|
234
255
|
return {
|
|
235
256
|
// some books such as cbz can have same basename inside different sub folder
|
|
236
257
|
// we need to make sure to have unique index
|
|
237
258
|
// /chap01/01.png, /chap02/01.png, etc
|
|
238
|
-
id: `${
|
|
239
|
-
index:
|
|
259
|
+
id: `${e}.${r.basename}`,
|
|
260
|
+
index: e,
|
|
240
261
|
href: encodeURI(`${o}${r.uri}`),
|
|
241
262
|
renditionLayout: void 0,
|
|
242
263
|
progressionWeight: 1 / s.length,
|
|
@@ -245,203 +266,203 @@ ${o}`), m.groupEnd();
|
|
|
245
266
|
mediaType: r.encodingFormat
|
|
246
267
|
};
|
|
247
268
|
}),
|
|
248
|
-
items: s.map((r,
|
|
249
|
-
id: `${
|
|
250
|
-
href: encodeURI(`${
|
|
269
|
+
items: s.map((r, e) => ({
|
|
270
|
+
id: `${e}.${r.basename}`,
|
|
271
|
+
href: encodeURI(`${t}${r.uri}`)
|
|
251
272
|
}))
|
|
252
273
|
};
|
|
253
274
|
}, Y = async ({
|
|
254
275
|
archive: n
|
|
255
276
|
}) => {
|
|
256
|
-
const { data:
|
|
277
|
+
const { data: t, basePath: s } = E(n) || {}, r = await t?.string();
|
|
257
278
|
if (!r) return [];
|
|
258
|
-
const
|
|
279
|
+
const e = new y(r), o = e.childNamed("manifest"), a = e.childNamed("spine")?.childrenNamed("itemref").map((d) => d.attr.idref), l = o?.childrenNamed("item").filter((d) => a.includes(d.attr.id || "")) || [];
|
|
259
280
|
return n.records.filter((d) => l.find((p) => s ? `${s}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
|
|
260
281
|
}, Ne = (n) => {
|
|
261
|
-
const
|
|
282
|
+
const t = n.attr.properties?.split(" ") || [];
|
|
262
283
|
let s;
|
|
263
|
-
return
|
|
284
|
+
return t.find((r) => r === "rendition:layout-reflowable") && (s = "reflowable"), t.find((r) => r === "rendition:layout-pre-paginated") && (s = "pre-paginated"), {
|
|
264
285
|
renditionLayout: s,
|
|
265
|
-
pageSpreadLeft:
|
|
266
|
-
pageSpreadRight:
|
|
286
|
+
pageSpreadLeft: t.some((r) => r === "page-spread-left") || void 0,
|
|
287
|
+
pageSpreadRight: t.some((r) => r === "page-spread-right") || void 0
|
|
267
288
|
};
|
|
268
|
-
}, Ae = (n,
|
|
269
|
-
const r = n.attr.href || "",
|
|
289
|
+
}, Ae = (n, t, s) => {
|
|
290
|
+
const r = n.attr.href || "", e = s?.(n);
|
|
270
291
|
return {
|
|
271
|
-
href:
|
|
292
|
+
href: t ? `${e}${t}/${r}` : `${e}${r}`,
|
|
272
293
|
id: n.attr.id || "",
|
|
273
294
|
mediaType: n.attr["media-type"]
|
|
274
295
|
};
|
|
275
|
-
}, Q = (n,
|
|
276
|
-
const r = n.childNamed("manifest"), { basePath:
|
|
277
|
-
return r?.childrenNamed("item")?.map((o) => Ae(o,
|
|
278
|
-
}, Ie = ({ archive: n, baseUrl:
|
|
279
|
-
const { data: r, basePath:
|
|
296
|
+
}, Q = (n, t, s) => {
|
|
297
|
+
const r = n.childNamed("manifest"), { basePath: e } = E(t) || {};
|
|
298
|
+
return r?.childrenNamed("item")?.map((o) => Ae(o, e, s)) || [];
|
|
299
|
+
}, Ie = ({ archive: n, baseUrl: t }) => async (s) => {
|
|
300
|
+
const { data: r, basePath: e } = E(n) || {};
|
|
280
301
|
if (!r)
|
|
281
302
|
return s;
|
|
282
303
|
const o = await r.string();
|
|
283
304
|
m.groupCollapsed(...m.getGroupArgs("OPF data")), m.log("data", o), m.groupEnd();
|
|
284
305
|
const i = new y(o), a = i.childNamed("metadata"), l = i.childNamed("manifest"), c = i.childNamed("spine"), d = i.childNamed("guide"), p = a?.childNamed("dc:title"), g = a?.childrenNamed("meta") || [], b = g.find(
|
|
285
|
-
(
|
|
286
|
-
),
|
|
287
|
-
(
|
|
288
|
-
),
|
|
289
|
-
(
|
|
290
|
-
), L = b?.val, h =
|
|
291
|
-
(
|
|
306
|
+
(u) => u.attr.property === "rendition:layout"
|
|
307
|
+
), N = g.find(
|
|
308
|
+
(u) => u.attr.property === "rendition:flow"
|
|
309
|
+
), f = g.find(
|
|
310
|
+
(u) => u.attr.property === "rendition:spread"
|
|
311
|
+
), L = b?.val, h = N?.val, F = f?.val, k = p?.val || n.records.find(({ dir: u }) => u)?.basename || "", ne = c?.attr["page-progression-direction"], re = (await Y({ archive: n })).reduce(
|
|
312
|
+
(u, A) => A.size + u,
|
|
292
313
|
0
|
|
293
314
|
);
|
|
294
315
|
return {
|
|
295
316
|
filename: n.filename,
|
|
296
317
|
renditionLayout: L,
|
|
297
318
|
renditionFlow: h || "auto",
|
|
298
|
-
renditionSpread:
|
|
299
|
-
title:
|
|
319
|
+
renditionSpread: F,
|
|
320
|
+
title: k,
|
|
300
321
|
readingDirection: ne || "ltr",
|
|
301
322
|
/**
|
|
302
323
|
* @see https://www.w3.org/TR/epub/#sec-itemref-elem
|
|
303
324
|
*/
|
|
304
|
-
spineItems: c?.childrenNamed("itemref").map((
|
|
305
|
-
const
|
|
325
|
+
spineItems: c?.childrenNamed("itemref").map((u, A) => {
|
|
326
|
+
const v = l?.childrenNamed("item").find((C) => C.attr.id === u?.attr.idref), z = v?.attr.href || "", oe = n.records.find((C) => C.uri.endsWith(z))?.size || 0, M = t || (/^https?:\/\//.test(z) ? "" : "file://"), U = Ne(u);
|
|
306
327
|
return {
|
|
307
|
-
...
|
|
308
|
-
id:
|
|
309
|
-
index:
|
|
310
|
-
href:
|
|
311
|
-
renditionLayout:
|
|
328
|
+
...U,
|
|
329
|
+
id: v?.attr.id || "",
|
|
330
|
+
index: A,
|
|
331
|
+
href: v?.attr.href?.startsWith("https://") ? v?.attr.href : e ? `${M}${e}/${v?.attr.href}` : `${M}${v?.attr.href}`,
|
|
332
|
+
renditionLayout: U.renditionLayout ?? L,
|
|
312
333
|
progressionWeight: oe / re,
|
|
313
334
|
// size: itemSize
|
|
314
|
-
mediaType:
|
|
335
|
+
mediaType: v?.attr["media-type"]
|
|
315
336
|
};
|
|
316
337
|
}) || [],
|
|
317
|
-
items: Q(i, n, (
|
|
318
|
-
const
|
|
319
|
-
return /^https?:\/\//.test(
|
|
338
|
+
items: Q(i, n, (u) => {
|
|
339
|
+
const A = u.attr.href || "";
|
|
340
|
+
return /^https?:\/\//.test(A) ? "" : t || "file://";
|
|
320
341
|
}),
|
|
321
|
-
guide: d?.childrenNamed("reference").map((
|
|
322
|
-
href:
|
|
323
|
-
title:
|
|
324
|
-
type:
|
|
342
|
+
guide: d?.childrenNamed("reference").map((u) => ({
|
|
343
|
+
href: u.attr.href || "",
|
|
344
|
+
title: u.attr.title || "",
|
|
345
|
+
type: u.attr.type
|
|
325
346
|
}))
|
|
326
347
|
};
|
|
327
348
|
}, Te = (n) => {
|
|
328
|
-
const
|
|
329
|
-
return !!(
|
|
330
|
-
}, We = (n) => n.reduce(async (
|
|
331
|
-
if (!await
|
|
349
|
+
const t = n.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "viewport");
|
|
350
|
+
return !!(t && t.attr.name === "viewport");
|
|
351
|
+
}, We = (n) => n.reduce(async (t, s) => {
|
|
352
|
+
if (!await t || !ie({
|
|
332
353
|
mimeType: s.encodingFormat,
|
|
333
354
|
uri: s.uri
|
|
334
355
|
}))
|
|
335
356
|
return !1;
|
|
336
|
-
const
|
|
337
|
-
return
|
|
338
|
-
}, Promise.resolve(!0)),
|
|
339
|
-
if (
|
|
357
|
+
const e = s.dir ? null : await s.string();
|
|
358
|
+
return e ? Te(new y(e)) : !1;
|
|
359
|
+
}, Promise.resolve(!0)), Se = ({ archive: n }) => async (t) => {
|
|
360
|
+
if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
340
361
|
const r = await Y({ archive: n });
|
|
341
362
|
if (await We(r))
|
|
342
363
|
return {
|
|
343
|
-
...
|
|
344
|
-
spineItems:
|
|
364
|
+
...t,
|
|
365
|
+
spineItems: t.spineItems.map((o) => ({
|
|
345
366
|
...o,
|
|
346
367
|
renditionLayout: "pre-paginated"
|
|
347
368
|
})),
|
|
348
369
|
renditionLayout: "pre-paginated"
|
|
349
370
|
};
|
|
350
371
|
}
|
|
351
|
-
return
|
|
352
|
-
},
|
|
372
|
+
return t;
|
|
373
|
+
}, Le = ({ archive: n }) => async (t) => {
|
|
353
374
|
const s = n.records.find(
|
|
354
375
|
(o) => o.basename.toLowerCase() === "comicinfo.xml" && !o.dir
|
|
355
376
|
);
|
|
356
377
|
if (!s || s.dir)
|
|
357
|
-
return
|
|
378
|
+
return t;
|
|
358
379
|
const r = {
|
|
359
|
-
...
|
|
360
|
-
spineItems:
|
|
380
|
+
...t,
|
|
381
|
+
spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, i, a) => ({
|
|
361
382
|
...o,
|
|
362
383
|
progressionWeight: 1 / a.length
|
|
363
384
|
}))
|
|
364
|
-
},
|
|
385
|
+
}, e = await s.string();
|
|
365
386
|
try {
|
|
366
|
-
const i = new y(
|
|
387
|
+
const i = new y(e).childNamed("Manga")?.val || "unknown";
|
|
367
388
|
return {
|
|
368
389
|
...r,
|
|
369
390
|
readingDirection: i === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
370
391
|
};
|
|
371
392
|
} catch (o) {
|
|
372
393
|
return console.error(`Unable to parse comicinfo.xml for content
|
|
373
|
-
`,
|
|
394
|
+
`, e), console.error(o), r;
|
|
374
395
|
}
|
|
375
|
-
}, ke = (n) => n.records.some((
|
|
376
|
-
...
|
|
377
|
-
spineItems:
|
|
378
|
-
const
|
|
396
|
+
}, ke = (n) => n.records.some((t) => t.basename.endsWith(".opf")), Ce = ({ archive: n }) => async (t) => ke(n) ? t : {
|
|
397
|
+
...t,
|
|
398
|
+
spineItems: t.spineItems.map((r) => {
|
|
399
|
+
const e = n.records.find(
|
|
379
400
|
(i) => decodeURI(r.href).endsWith(i.uri)
|
|
380
|
-
), o = ae(
|
|
401
|
+
), o = ae(e?.encodingFormat ?? "") || x(e?.basename ?? "");
|
|
381
402
|
return {
|
|
382
403
|
...r,
|
|
383
404
|
renditionLayout: o?.startsWith("image/") ? "pre-paginated" : r.renditionLayout
|
|
384
405
|
};
|
|
385
406
|
})
|
|
386
|
-
}, Z = (n) => n ? n.children.map((
|
|
407
|
+
}, Z = (n) => n ? n.children.map((t) => t instanceof ce ? t.text : t instanceof de ? Z(t) : "").join("").trim() : "", ee = (n, { basePath: t, baseUrl: s }) => {
|
|
387
408
|
const r = {
|
|
388
409
|
contents: [],
|
|
389
410
|
path: "",
|
|
390
411
|
href: "",
|
|
391
412
|
title: ""
|
|
392
413
|
};
|
|
393
|
-
let
|
|
394
|
-
r.title = (
|
|
395
|
-
let o =
|
|
396
|
-
o !== "a" && (
|
|
414
|
+
let e = n.childNamed("span") || n.childNamed("a");
|
|
415
|
+
r.title = (e?.attr.title || e?.val.trim() || Z(e)) ?? "";
|
|
416
|
+
let o = e?.name;
|
|
417
|
+
o !== "a" && (e = n.descendantWithPath(`${o}.a`), e && (o = e.name.toLowerCase())), o === "a" && e?.attr.href && (r.path = T(t, e.attr.href), r.href = T(s, t, e.attr.href));
|
|
397
418
|
const i = n.childNamed("ol");
|
|
398
419
|
if (i) {
|
|
399
420
|
const a = i.childrenNamed("li");
|
|
400
421
|
a && a.length > 0 && (r.contents = a.map(
|
|
401
|
-
(l) => ee(l, { basePath:
|
|
422
|
+
(l) => ee(l, { basePath: t, baseUrl: s })
|
|
402
423
|
));
|
|
403
424
|
}
|
|
404
425
|
return r;
|
|
405
|
-
}, Re = (n, { basePath:
|
|
426
|
+
}, Re = (n, { basePath: t, baseUrl: s }) => {
|
|
406
427
|
const r = [];
|
|
407
|
-
let
|
|
408
|
-
return n.descendantWithPath("body.nav.ol") ?
|
|
409
|
-
r.push(ee(o, { basePath:
|
|
428
|
+
let e;
|
|
429
|
+
return n.descendantWithPath("body.nav.ol") ? e = n.descendantWithPath("body.nav.ol")?.children : n.descendantWithPath("body.section.nav.ol") && (e = n.descendantWithPath("body.section.nav.ol")?.children), e && e.length > 0 && e.filter((o) => o.name === "li").forEach((o) => {
|
|
430
|
+
r.push(ee(o, { basePath: t, baseUrl: s }));
|
|
410
431
|
}), r;
|
|
411
|
-
}, Pe = async (n,
|
|
412
|
-
const r = n.childNamed("manifest")?.childrenNamed("item").find((
|
|
432
|
+
}, Pe = async (n, t, { baseUrl: s }) => {
|
|
433
|
+
const r = n.childNamed("manifest")?.childrenNamed("item").find((e) => e.attr.properties === "nav");
|
|
413
434
|
if (r) {
|
|
414
|
-
const
|
|
435
|
+
const e = Object.values(t.records).find(
|
|
415
436
|
(o) => o.uri.endsWith(r.attr.href || "")
|
|
416
437
|
);
|
|
417
|
-
if (
|
|
418
|
-
const o = new y(await
|
|
438
|
+
if (e && !e.dir) {
|
|
439
|
+
const o = new y(await e.string()), i = be(e.uri);
|
|
419
440
|
return Re(o, { basePath: i, baseUrl: s });
|
|
420
441
|
}
|
|
421
442
|
}
|
|
422
443
|
}, te = (n, {
|
|
423
|
-
opfBasePath:
|
|
444
|
+
opfBasePath: t,
|
|
424
445
|
baseUrl: s,
|
|
425
446
|
prefix: r
|
|
426
447
|
}) => {
|
|
427
|
-
const
|
|
448
|
+
const e = n?.childNamed(`${r}content`)?.attr.src || "", o = {
|
|
428
449
|
title: n?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
|
|
429
|
-
path:
|
|
430
|
-
href:
|
|
450
|
+
path: T(t, e),
|
|
451
|
+
href: T(s, t, e),
|
|
431
452
|
contents: []
|
|
432
453
|
}, i = n.childrenNamed(`${r}navPoint`);
|
|
433
454
|
return i && i.length > 0 && (o.contents = i.map(
|
|
434
|
-
(a) => te(a, { opfBasePath:
|
|
455
|
+
(a) => te(a, { opfBasePath: t, baseUrl: s, prefix: r })
|
|
435
456
|
)), o;
|
|
436
|
-
}, je = (n, { opfBasePath:
|
|
437
|
-
const r = [],
|
|
457
|
+
}, je = (n, { opfBasePath: t, baseUrl: s }) => {
|
|
458
|
+
const r = [], e = n.name;
|
|
438
459
|
let o = "";
|
|
439
|
-
return
|
|
440
|
-
r.push(te(i, { opfBasePath:
|
|
460
|
+
return e.indexOf(":") !== -1 && (o = `${e.split(":")[0]}:`), n.childNamed(`${o}navMap`)?.childrenNamed(`${o}navPoint`).forEach((i) => {
|
|
461
|
+
r.push(te(i, { opfBasePath: t, baseUrl: s, prefix: o }));
|
|
441
462
|
}), r;
|
|
442
463
|
}, Oe = async ({
|
|
443
464
|
opfData: n,
|
|
444
|
-
opfBasePath:
|
|
465
|
+
opfBasePath: t,
|
|
445
466
|
baseUrl: s,
|
|
446
467
|
archive: r
|
|
447
468
|
}) => {
|
|
@@ -449,36 +470,36 @@ ${o}`), m.groupEnd();
|
|
|
449
470
|
if (o) {
|
|
450
471
|
const i = n.childNamed("manifest")?.childrenNamed("item").find((a) => a.attr.id === o);
|
|
451
472
|
if (i) {
|
|
452
|
-
const a = `${
|
|
473
|
+
const a = `${t}${t === "" ? "" : "/"}${i.attr.href}`, l = Object.values(r.records).find(
|
|
453
474
|
(c) => c.uri.endsWith(a)
|
|
454
475
|
);
|
|
455
476
|
if (l && !l.dir) {
|
|
456
477
|
const c = new y(await l.string());
|
|
457
|
-
return je(c, { opfBasePath:
|
|
478
|
+
return je(c, { opfBasePath: t, baseUrl: s });
|
|
458
479
|
}
|
|
459
480
|
}
|
|
460
481
|
}
|
|
461
|
-
}, De = async (n,
|
|
462
|
-
const { basePath: r } =
|
|
482
|
+
}, De = async (n, t, { baseUrl: s }) => {
|
|
483
|
+
const { basePath: r } = E(t) || {}, e = await Pe(n, t, {
|
|
463
484
|
baseUrl: s
|
|
464
485
|
});
|
|
465
|
-
if (
|
|
466
|
-
return
|
|
486
|
+
if (e)
|
|
487
|
+
return e;
|
|
467
488
|
const o = await Oe({
|
|
468
489
|
opfData: n,
|
|
469
490
|
opfBasePath: r,
|
|
470
|
-
archive:
|
|
491
|
+
archive: t,
|
|
471
492
|
baseUrl: s
|
|
472
493
|
});
|
|
473
494
|
if (o)
|
|
474
495
|
return o;
|
|
475
|
-
},
|
|
496
|
+
}, ze = (n, { baseUrl: t }) => {
|
|
476
497
|
const s = [...n.records].sort(
|
|
477
|
-
(
|
|
478
|
-
), r = (
|
|
479
|
-
const c =
|
|
498
|
+
(e, o) => D(e.uri, o.uri)
|
|
499
|
+
), r = (e, o, i, a, l) => {
|
|
500
|
+
const c = e.find((g) => g.title === o), [d, ...p] = i;
|
|
480
501
|
return c ? d ? [
|
|
481
|
-
...
|
|
502
|
+
...e.filter((b) => b !== c),
|
|
482
503
|
{
|
|
483
504
|
...c,
|
|
484
505
|
contents: [
|
|
@@ -493,14 +514,14 @@ ${o}`), m.groupEnd();
|
|
|
493
514
|
]
|
|
494
515
|
}
|
|
495
516
|
] : c.path.split("/").length > l.split("/").length ? [
|
|
496
|
-
...
|
|
517
|
+
...e.filter((b) => b !== c),
|
|
497
518
|
{
|
|
498
519
|
...c,
|
|
499
520
|
path: l,
|
|
500
521
|
href: a
|
|
501
522
|
}
|
|
502
|
-
] :
|
|
503
|
-
...
|
|
523
|
+
] : e : d ? [
|
|
524
|
+
...e,
|
|
504
525
|
{
|
|
505
526
|
contents: r(
|
|
506
527
|
[],
|
|
@@ -514,7 +535,7 @@ ${o}`), m.groupEnd();
|
|
|
514
535
|
title: o
|
|
515
536
|
}
|
|
516
537
|
] : [
|
|
517
|
-
...
|
|
538
|
+
...e,
|
|
518
539
|
{
|
|
519
540
|
contents: [],
|
|
520
541
|
href: a,
|
|
@@ -523,63 +544,63 @@ ${o}`), m.groupEnd();
|
|
|
523
544
|
}
|
|
524
545
|
];
|
|
525
546
|
};
|
|
526
|
-
return s.reduce((
|
|
527
|
-
if (o.dir) return
|
|
547
|
+
return s.reduce((e, o) => {
|
|
548
|
+
if (o.dir) return e;
|
|
528
549
|
const i = o.uri.split("/").slice(0, -1), [a, ...l] = i;
|
|
529
|
-
if (!a) return
|
|
530
|
-
const c =
|
|
531
|
-
return r(
|
|
550
|
+
if (!a) return e;
|
|
551
|
+
const c = T(t, encodeURI(o.uri)).replace(/\/$/, ""), d = o.uri.replace(/\/$/, "");
|
|
552
|
+
return r(e, a, l, c, d);
|
|
532
553
|
}, []);
|
|
533
|
-
},
|
|
534
|
-
const { data: s } =
|
|
554
|
+
}, Me = async (n, { baseUrl: t }) => {
|
|
555
|
+
const { data: s } = E(n) || {};
|
|
535
556
|
if (s && !s.dir) {
|
|
536
|
-
const
|
|
537
|
-
return await De(
|
|
557
|
+
const e = new y(await s.string());
|
|
558
|
+
return await De(e, n, { baseUrl: t }) || [];
|
|
538
559
|
}
|
|
539
|
-
const r =
|
|
560
|
+
const r = ze(n, { baseUrl: t });
|
|
540
561
|
if (r.length !== 0)
|
|
541
562
|
return r;
|
|
542
|
-
},
|
|
563
|
+
}, Ue = ({ archive: n, baseUrl: t }) => async (s) => {
|
|
543
564
|
if (s.nav) return s;
|
|
544
|
-
const r = await
|
|
565
|
+
const r = await Me(n, { baseUrl: t });
|
|
545
566
|
return r ? {
|
|
546
567
|
...s,
|
|
547
568
|
nav: {
|
|
548
569
|
toc: r
|
|
549
570
|
}
|
|
550
571
|
} : s;
|
|
551
|
-
}, Be = async (n, { baseUrl:
|
|
572
|
+
}, Be = async (n, { baseUrl: t = "" } = {}) => {
|
|
552
573
|
const s = [
|
|
553
|
-
Ie({ archive: n, baseUrl:
|
|
554
|
-
|
|
574
|
+
Ie({ archive: n, baseUrl: t }),
|
|
575
|
+
Le({ archive: n }),
|
|
555
576
|
$e({ archive: n }),
|
|
556
577
|
Ce({ archive: n }),
|
|
557
|
-
|
|
578
|
+
Se({ archive: n }),
|
|
558
579
|
Fe({ archive: n }),
|
|
559
|
-
|
|
580
|
+
Ue({ archive: n, baseUrl: t })
|
|
560
581
|
];
|
|
561
582
|
try {
|
|
562
|
-
const r = Ee({ archive: n, baseUrl:
|
|
563
|
-
if (m.log("Generated manifest",
|
|
564
|
-
const o = JSON.stringify(
|
|
583
|
+
const r = Ee({ archive: n, baseUrl: t })(), e = await s.reduce(async (o, i) => await i(await o), r);
|
|
584
|
+
if (m.log("Generated manifest", e), process.env.NODE_ENV === "development" && m.isEnabled()) {
|
|
585
|
+
const o = JSON.stringify(e, null, 2);
|
|
565
586
|
m.groupCollapsed(...m.getGroupArgs("Generated manifest")), m.log(`
|
|
566
587
|
${o}`), m.groupEnd();
|
|
567
588
|
}
|
|
568
|
-
return
|
|
589
|
+
return e;
|
|
569
590
|
} catch (r) {
|
|
570
591
|
throw m.error(r), r;
|
|
571
592
|
}
|
|
572
593
|
}, Xe = (n) => {
|
|
573
|
-
const
|
|
574
|
-
return !!(
|
|
594
|
+
const t = n.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
|
|
595
|
+
return !!(t && t.attr.name === "calibre:cover");
|
|
575
596
|
}, Ve = (n) => n.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
|
|
576
|
-
(
|
|
577
|
-
), He = ({ archive: n, resourcePath:
|
|
597
|
+
(t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
|
|
598
|
+
), He = ({ archive: n, resourcePath: t }) => async (s) => {
|
|
578
599
|
const r = Object.values(n.records).find(
|
|
579
|
-
(
|
|
600
|
+
(e) => e.uri === t && !e.dir
|
|
580
601
|
);
|
|
581
602
|
if (r && !r.dir && r.basename.endsWith(".xhtml")) {
|
|
582
|
-
const
|
|
603
|
+
const e = s.body ?? await r.string(), o = new y(e);
|
|
583
604
|
if (Xe(o)) {
|
|
584
605
|
const i = Ve(o);
|
|
585
606
|
return i && delete i.attr.preserveAspectRatio, {
|
|
@@ -589,9 +610,9 @@ ${o}`), m.groupEnd();
|
|
|
589
610
|
}
|
|
590
611
|
}
|
|
591
612
|
return s;
|
|
592
|
-
}, _e = ({ archive: n, resourcePath:
|
|
613
|
+
}, _e = ({ archive: n, resourcePath: t }) => async (s) => He({ archive: n, resourcePath: t })(s), Ge = ({ archive: n, resourcePath: t }) => async (s) => {
|
|
593
614
|
const r = Object.values(n.records).find(
|
|
594
|
-
(
|
|
615
|
+
(e) => e.uri === t && !e.dir
|
|
595
616
|
);
|
|
596
617
|
if (r && !r.dir && r.basename.endsWith(".css")) {
|
|
597
618
|
const o = (s.body ?? await r.string()).replaceAll(
|
|
@@ -604,19 +625,19 @@ ${o}`), m.groupEnd();
|
|
|
604
625
|
};
|
|
605
626
|
}
|
|
606
627
|
return s;
|
|
607
|
-
}, qe = async (n,
|
|
608
|
-
const r = await
|
|
628
|
+
}, qe = async (n, t) => {
|
|
629
|
+
const r = await E(n).data?.string();
|
|
609
630
|
if (r) {
|
|
610
|
-
const
|
|
631
|
+
const e = new y(r), o = Q(e, n, () => "");
|
|
611
632
|
if (o.find(
|
|
612
|
-
(a) =>
|
|
633
|
+
(a) => t.endsWith(a.href)
|
|
613
634
|
)?.mediaType)
|
|
614
635
|
return {
|
|
615
|
-
mediaType: o.find((a) =>
|
|
636
|
+
mediaType: o.find((a) => t.endsWith(a.href))?.mediaType
|
|
616
637
|
};
|
|
617
638
|
}
|
|
618
639
|
return {
|
|
619
|
-
mediaType: Je(
|
|
640
|
+
mediaType: Je(t)
|
|
620
641
|
};
|
|
621
642
|
}, Je = (n) => {
|
|
622
643
|
if (n.endsWith(".css"))
|
|
@@ -629,12 +650,12 @@ ${o}`), m.groupEnd();
|
|
|
629
650
|
return "video/mp4";
|
|
630
651
|
if (n.endsWith(".svg"))
|
|
631
652
|
return "image/svg+xml";
|
|
632
|
-
}, Ke = ({ archive: n, resourcePath:
|
|
653
|
+
}, Ke = ({ archive: n, resourcePath: t }) => async (s) => {
|
|
633
654
|
const r = Object.values(n.records).find(
|
|
634
|
-
(o) => o.uri ===
|
|
655
|
+
(o) => o.uri === t && !o.dir
|
|
635
656
|
);
|
|
636
657
|
if (!r || r.dir) return s;
|
|
637
|
-
const
|
|
658
|
+
const e = await qe(n, t);
|
|
638
659
|
return {
|
|
639
660
|
...s,
|
|
640
661
|
params: {
|
|
@@ -642,8 +663,8 @@ ${o}`), m.groupEnd();
|
|
|
642
663
|
...r?.encodingFormat && {
|
|
643
664
|
contentType: r.encodingFormat
|
|
644
665
|
},
|
|
645
|
-
...
|
|
646
|
-
contentType:
|
|
666
|
+
...e.mediaType && {
|
|
667
|
+
contentType: e.mediaType
|
|
647
668
|
}
|
|
648
669
|
}
|
|
649
670
|
};
|
|
@@ -698,21 +719,21 @@ ${o}`), m.groupEnd();
|
|
|
698
719
|
"canvas",
|
|
699
720
|
"script",
|
|
700
721
|
"style"
|
|
701
|
-
], Ye = ({ archive: n, resourcePath:
|
|
722
|
+
], Ye = ({ archive: n, resourcePath: t }) => async (s) => {
|
|
702
723
|
const r = Object.values(n.records).find(
|
|
703
|
-
(
|
|
724
|
+
(e) => e.uri === t && !e.dir
|
|
704
725
|
);
|
|
705
726
|
if (r && !r.dir && r.basename.endsWith(".xhtml")) {
|
|
706
|
-
const
|
|
727
|
+
const e = s.body ?? await r.string();
|
|
707
728
|
if (!new RegExp(
|
|
708
729
|
`<(${K.join("|")})[\\s/>]`,
|
|
709
730
|
"i"
|
|
710
|
-
).test(
|
|
731
|
+
).test(e))
|
|
711
732
|
return s;
|
|
712
733
|
const i = new RegExp(
|
|
713
734
|
`<(${K.join("|")})(\\s[^>]*)?\\s*/>`,
|
|
714
735
|
"gi"
|
|
715
|
-
), a =
|
|
736
|
+
), a = e.replace(
|
|
716
737
|
i,
|
|
717
738
|
(l, c, d = "") => `<${c} ${d.trim()}></${c}>`
|
|
718
739
|
);
|
|
@@ -722,23 +743,23 @@ ${o}`), m.groupEnd();
|
|
|
722
743
|
};
|
|
723
744
|
}
|
|
724
745
|
return s;
|
|
725
|
-
}, Qe = async (n,
|
|
746
|
+
}, Qe = async (n, t) => {
|
|
726
747
|
const s = Object.values(n.records).find(
|
|
727
|
-
(o) => o.uri ===
|
|
748
|
+
(o) => o.uri === t && !o.dir
|
|
728
749
|
);
|
|
729
750
|
if (!s || s.dir)
|
|
730
|
-
throw new Error(`no file found for resourcePath:${
|
|
751
|
+
throw new Error(`no file found for resourcePath:${t}`);
|
|
731
752
|
const r = {
|
|
732
753
|
params: {}
|
|
733
|
-
},
|
|
734
|
-
Ke({ archive: n, resourcePath:
|
|
735
|
-
Ye({ archive: n, resourcePath:
|
|
736
|
-
Ge({ archive: n, resourcePath:
|
|
737
|
-
_e({ archive: n, resourcePath:
|
|
754
|
+
}, e = [
|
|
755
|
+
Ke({ archive: n, resourcePath: t }),
|
|
756
|
+
Ye({ archive: n, resourcePath: t }),
|
|
757
|
+
Ge({ archive: n, resourcePath: t }),
|
|
758
|
+
_e({ archive: n, resourcePath: t })
|
|
738
759
|
];
|
|
739
760
|
try {
|
|
740
|
-
const o = await
|
|
741
|
-
return m.log("Generated resource",
|
|
761
|
+
const o = await e.reduce(async (i, a) => await a(await i), Promise.resolve(r));
|
|
762
|
+
return m.log("Generated resource", t, o), {
|
|
742
763
|
...o,
|
|
743
764
|
body: o.body ?? await s.blob()
|
|
744
765
|
};
|
|
@@ -747,79 +768,79 @@ ${o}`), m.groupEnd();
|
|
|
747
768
|
}
|
|
748
769
|
};
|
|
749
770
|
class Ze {
|
|
750
|
-
constructor(
|
|
751
|
-
this.cleanArchiveAfter =
|
|
771
|
+
constructor(t) {
|
|
772
|
+
this.cleanArchiveAfter = t, this.state$ = new fe({
|
|
752
773
|
status: "idle",
|
|
753
774
|
locks: 0
|
|
754
775
|
});
|
|
755
776
|
}
|
|
756
|
-
update(
|
|
757
|
-
this.state$.next({ ...this.state$.getValue(), ...
|
|
777
|
+
update(t) {
|
|
778
|
+
this.state$.next({ ...this.state$.getValue(), ...t });
|
|
758
779
|
}
|
|
759
780
|
get locks$() {
|
|
760
|
-
return this.state$.pipe(
|
|
781
|
+
return this.state$.pipe($(({ locks: t }) => t));
|
|
761
782
|
}
|
|
762
783
|
get state() {
|
|
763
784
|
return this.state$.getValue();
|
|
764
785
|
}
|
|
765
786
|
get isUnlocked$() {
|
|
766
787
|
return this.locks$.pipe(
|
|
767
|
-
|
|
788
|
+
$((t) => t <= 0),
|
|
768
789
|
he(),
|
|
769
790
|
ge()
|
|
770
791
|
);
|
|
771
792
|
}
|
|
772
793
|
get overTTL$() {
|
|
773
794
|
return this.isUnlocked$.pipe(
|
|
774
|
-
|
|
775
|
-
(
|
|
795
|
+
I(
|
|
796
|
+
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? H : ye(this.cleanArchiveAfter) : H
|
|
776
797
|
)
|
|
777
798
|
);
|
|
778
799
|
}
|
|
779
800
|
}
|
|
780
801
|
const et = ({
|
|
781
802
|
getArchive: n,
|
|
782
|
-
cleanArchiveAfter:
|
|
803
|
+
cleanArchiveAfter: t = 300 * 1e3
|
|
783
804
|
// 5mn
|
|
784
805
|
}) => {
|
|
785
|
-
const s = new
|
|
806
|
+
const s = new R(), r = new R(), e = new R(), o = {}, i = s.pipe(
|
|
786
807
|
O((c) => {
|
|
787
808
|
const d = o[c];
|
|
788
809
|
if (!d || d.state.status !== "idle") return B;
|
|
789
810
|
let p = !1;
|
|
790
811
|
const g = (h) => {
|
|
791
812
|
m.debug(`Cleaning up archive with key: ${h}`);
|
|
792
|
-
const
|
|
793
|
-
delete o[h], p || (
|
|
813
|
+
const F = o[h];
|
|
814
|
+
delete o[h], p || (F?.state.archive?.close(), p = !0);
|
|
794
815
|
};
|
|
795
816
|
d.update({
|
|
796
817
|
status: "loading"
|
|
797
818
|
});
|
|
798
|
-
const b = d.locks$,
|
|
819
|
+
const b = d.locks$, N = d.isUnlocked$, f = b.pipe(
|
|
799
820
|
le(),
|
|
800
|
-
|
|
821
|
+
P(([h, F]) => F > h),
|
|
801
822
|
pe(!0)
|
|
802
823
|
);
|
|
803
|
-
return
|
|
804
|
-
|
|
824
|
+
return W(n(c)).pipe(
|
|
825
|
+
j((h) => {
|
|
805
826
|
d.update({
|
|
806
827
|
archive: h,
|
|
807
828
|
status: "success"
|
|
808
829
|
});
|
|
809
830
|
}),
|
|
810
|
-
|
|
831
|
+
S((h) => (g(c), d.update({
|
|
811
832
|
status: "error",
|
|
812
833
|
error: h
|
|
813
834
|
}), B)),
|
|
814
|
-
|
|
815
|
-
const h =
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
835
|
+
I(() => {
|
|
836
|
+
const h = f.pipe(
|
|
837
|
+
I(() => e),
|
|
838
|
+
I(() => N),
|
|
839
|
+
P((k) => k)
|
|
819
840
|
);
|
|
820
841
|
return X(h, d.overTTL$).pipe(
|
|
821
842
|
V(),
|
|
822
|
-
|
|
843
|
+
j(() => {
|
|
823
844
|
g(c);
|
|
824
845
|
})
|
|
825
846
|
);
|
|
@@ -829,7 +850,7 @@ const et = ({
|
|
|
829
850
|
me(r)
|
|
830
851
|
), a = (c) => {
|
|
831
852
|
let d = !1;
|
|
832
|
-
const p = o[c] ?? new Ze(
|
|
853
|
+
const p = o[c] ?? new Ze(t);
|
|
833
854
|
o[c] = p, p.update({
|
|
834
855
|
locks: p.state.locks + 1
|
|
835
856
|
});
|
|
@@ -840,24 +861,24 @@ const et = ({
|
|
|
840
861
|
};
|
|
841
862
|
s.next(c);
|
|
842
863
|
const b = p.state$.pipe(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
),
|
|
846
|
-
|
|
847
|
-
if (
|
|
848
|
-
throw
|
|
864
|
+
$(({ archive: f }) => f),
|
|
865
|
+
P((f) => !!f)
|
|
866
|
+
), N = p.state$.pipe(
|
|
867
|
+
j(({ error: f }) => {
|
|
868
|
+
if (f)
|
|
869
|
+
throw f;
|
|
849
870
|
}),
|
|
850
|
-
|
|
871
|
+
ue()
|
|
851
872
|
);
|
|
852
|
-
return X(b,
|
|
873
|
+
return X(b, N).pipe(
|
|
853
874
|
V(),
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
throw g(),
|
|
875
|
+
$((f) => ({ archive: f, release: g })),
|
|
876
|
+
S((f) => {
|
|
877
|
+
throw g(), f;
|
|
857
878
|
})
|
|
858
879
|
);
|
|
859
880
|
}, l = () => {
|
|
860
|
-
|
|
881
|
+
e.next();
|
|
861
882
|
};
|
|
862
883
|
return i.subscribe(), {
|
|
863
884
|
access: a,
|
|
@@ -867,32 +888,32 @@ const et = ({
|
|
|
867
888
|
};
|
|
868
889
|
class tt {
|
|
869
890
|
constructor({
|
|
870
|
-
onError:
|
|
891
|
+
onError: t,
|
|
871
892
|
onManifestSuccess: s,
|
|
872
893
|
...r
|
|
873
894
|
}) {
|
|
874
|
-
this.onError = (
|
|
895
|
+
this.onError = (e) => (console.error(e), new Response(String(e), { status: 500 })), this.epubLoader = et(r), this.onManifestSuccess = s ?? (({ manifest: e }) => Promise.resolve(e)), this.onError = t ?? this.onError;
|
|
875
896
|
}
|
|
876
897
|
prune() {
|
|
877
898
|
this.epubLoader.purge();
|
|
878
899
|
}
|
|
879
|
-
accessArchive(
|
|
880
|
-
return this.lastAccessedKey !== void 0 && this.lastAccessedKey !==
|
|
900
|
+
accessArchive(t) {
|
|
901
|
+
return this.lastAccessedKey !== void 0 && this.lastAccessedKey !== t && this.epubLoader.purge(), this.lastAccessedKey = t, this.epubLoader.access(t);
|
|
881
902
|
}
|
|
882
|
-
accessArchiveWithoutLock(
|
|
883
|
-
return this.accessArchive(
|
|
884
|
-
|
|
903
|
+
accessArchiveWithoutLock(t) {
|
|
904
|
+
return this.accessArchive(t).pipe(
|
|
905
|
+
$(({ archive: s, release: r }) => (r(), s))
|
|
885
906
|
);
|
|
886
907
|
}
|
|
887
|
-
fetchManifest({ key:
|
|
888
|
-
const r = this.accessArchive(
|
|
889
|
-
O(({ archive:
|
|
890
|
-
Be(
|
|
908
|
+
fetchManifest({ key: t, baseUrl: s }) {
|
|
909
|
+
const r = this.accessArchive(t).pipe(
|
|
910
|
+
O(({ archive: e, release: o }) => W(
|
|
911
|
+
Be(e, { baseUrl: s })
|
|
891
912
|
).pipe(
|
|
892
|
-
|
|
893
|
-
(a) =>
|
|
913
|
+
I(
|
|
914
|
+
(a) => W(this.onManifestSuccess({ manifest: a, archive: e }))
|
|
894
915
|
),
|
|
895
|
-
|
|
916
|
+
$(
|
|
896
917
|
(a) => new Response(JSON.stringify(a), {
|
|
897
918
|
status: 200
|
|
898
919
|
})
|
|
@@ -901,21 +922,21 @@ class tt {
|
|
|
901
922
|
o();
|
|
902
923
|
})
|
|
903
924
|
)),
|
|
904
|
-
|
|
925
|
+
S((e) => G(this.onError(e)))
|
|
905
926
|
);
|
|
906
927
|
return q(r);
|
|
907
928
|
}
|
|
908
929
|
fetchResource({
|
|
909
|
-
key:
|
|
930
|
+
key: t,
|
|
910
931
|
resourcePath: s
|
|
911
932
|
}) {
|
|
912
|
-
const r = this.accessArchive(
|
|
913
|
-
O(({ archive:
|
|
933
|
+
const r = this.accessArchive(t).pipe(
|
|
934
|
+
O(({ archive: e, release: o }) => {
|
|
914
935
|
const i = s.replaceAll("file://", "");
|
|
915
|
-
return
|
|
916
|
-
Qe(
|
|
936
|
+
return W(
|
|
937
|
+
Qe(e, i)
|
|
917
938
|
).pipe(
|
|
918
|
-
|
|
939
|
+
$(
|
|
919
940
|
(l) => new Response(l.body, {
|
|
920
941
|
status: 200,
|
|
921
942
|
headers: {
|
|
@@ -930,32 +951,32 @@ class tt {
|
|
|
930
951
|
})
|
|
931
952
|
);
|
|
932
953
|
}),
|
|
933
|
-
|
|
954
|
+
S((e) => G(this.onError(e)))
|
|
934
955
|
);
|
|
935
956
|
return q(r);
|
|
936
957
|
}
|
|
937
958
|
}
|
|
938
959
|
class mt extends tt {
|
|
939
960
|
constructor({
|
|
940
|
-
getUriInfo:
|
|
961
|
+
getUriInfo: t,
|
|
941
962
|
...s
|
|
942
963
|
}) {
|
|
943
|
-
super(s), this.getUriInfo =
|
|
964
|
+
super(s), this.getUriInfo = t, this.fetchEventListener = this.fetchEventListener.bind(this);
|
|
944
965
|
}
|
|
945
|
-
fetchEventListener(
|
|
966
|
+
fetchEventListener(t) {
|
|
946
967
|
try {
|
|
947
|
-
const s = this.getUriInfo(
|
|
968
|
+
const s = this.getUriInfo(t);
|
|
948
969
|
if (!s) return;
|
|
949
|
-
const r = J(s.baseUrl),
|
|
970
|
+
const r = J(s.baseUrl), e = t.request.url.substring(
|
|
950
971
|
r.length + 1
|
|
951
|
-
), [o = ""] =
|
|
952
|
-
J(
|
|
972
|
+
), [o = ""] = e.split("/"), i = decodeURIComponent(
|
|
973
|
+
J(e.substring(o.length + 1))
|
|
953
974
|
);
|
|
954
|
-
|
|
975
|
+
e.endsWith("/manifest") ? t.respondWith(
|
|
955
976
|
this.fetchManifest({ key: o, baseUrl: `${r}/${o}/` })
|
|
956
|
-
) :
|
|
977
|
+
) : t.respondWith(this.fetchResource({ key: o, resourcePath: i }));
|
|
957
978
|
} catch (s) {
|
|
958
|
-
|
|
979
|
+
t.respondWith(new Response(String(s), { status: 500 }));
|
|
959
980
|
}
|
|
960
981
|
}
|
|
961
982
|
}
|
|
@@ -970,9 +991,9 @@ export {
|
|
|
970
991
|
lt as createArchiveFromUrls,
|
|
971
992
|
Be as generateManifestFromArchive,
|
|
972
993
|
Qe as generateResourceFromArchive,
|
|
973
|
-
|
|
994
|
+
E as getArchiveOpfInfo,
|
|
974
995
|
be as getUriBasePath,
|
|
975
|
-
|
|
996
|
+
w as getUriBasename,
|
|
976
997
|
J as removeTrailingSlash,
|
|
977
998
|
D as sortByTitleComparator
|
|
978
999
|
};
|