book-index-ui 0.65.0 → 0.65.2
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.cjs +65 -65
- package/dist/index.d.ts +22 -21
- package/dist/index.js +6228 -6223
- package/dist/{storage-entry-DZmVSoZe.js → storage-entry-DuObqdka.js} +268 -256
- package/dist/storage-entry-h5vhXs0r.cjs +2 -0
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +15 -14
- package/dist/storage.js +5 -5
- package/package.json +1 -1
- package/dist/storage-entry-B6014X77.cjs +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { VARIANT_SUPPLEMENT as
|
|
2
|
-
const
|
|
1
|
+
import { VARIANT_SUPPLEMENT as ft } from "./variant-supplement.js";
|
|
2
|
+
const yt = { official: 0, draft: 1 }, gt = { 0: "official", 1: "draft" }, mt = { book: 0, collection: 2, work: 3, entity: 4 }, pt = { 0: "book", 2: "collection", 3: "work", 4: "entity" }, st = 62n, nt = 59n, ot = 19n, it = 8n, rt = (1n << 40n) - 1n, wt = (1n << 3n) - 1n, _t = (1n << 11n) - 1n, bt = (1n << 8n) - 1n, $ = "0123456789abcdefghijklmnopqrstuvwxyz", at = /* @__PURE__ */ new Map();
|
|
3
3
|
for (let i = 0; i < $.length; i++)
|
|
4
|
-
|
|
4
|
+
at.set($[i], BigInt(i));
|
|
5
5
|
function A(i) {
|
|
6
6
|
if (i === 0n) return $[0];
|
|
7
7
|
let t = "";
|
|
@@ -9,23 +9,23 @@ function A(i) {
|
|
|
9
9
|
t = $[Number(i % 36n)] + t, i = i / 36n;
|
|
10
10
|
return t;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function ct(i) {
|
|
13
13
|
let t = 0n;
|
|
14
14
|
for (const e of i) {
|
|
15
|
-
const s =
|
|
15
|
+
const s = at.get(e);
|
|
16
16
|
if (s === void 0)
|
|
17
17
|
throw new Error(`Invalid Base36 character: ${e}`);
|
|
18
18
|
t = t * 36n + s;
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
for (let i = 0; i <
|
|
24
|
-
|
|
25
|
-
function
|
|
22
|
+
const q = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", lt = /* @__PURE__ */ new Map();
|
|
23
|
+
for (let i = 0; i < q.length; i++)
|
|
24
|
+
lt.set(q[i], BigInt(i));
|
|
25
|
+
function It(i) {
|
|
26
26
|
let t = 0n;
|
|
27
27
|
for (const e of i) {
|
|
28
|
-
const s =
|
|
28
|
+
const s = lt.get(e);
|
|
29
29
|
if (s === void 0)
|
|
30
30
|
throw new Error(`Invalid Base58 character: ${e}`);
|
|
31
31
|
t = t * 58n + s;
|
|
@@ -33,39 +33,51 @@ function _t(i) {
|
|
|
33
33
|
return t;
|
|
34
34
|
}
|
|
35
35
|
function _(i) {
|
|
36
|
-
return /[A-Z]/.test(i) ?
|
|
36
|
+
return /[A-Z]/.test(i) ? It(i) : ct(i);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const Kt = A, Yt = ct;
|
|
39
39
|
function k(i) {
|
|
40
|
-
const t = Number(i >>
|
|
40
|
+
const t = Number(i >> st & 1n), e = Number(i >> nt & wt), s = i >> ot & rt, n = Number(i >> it & _t), o = Number(i & bt);
|
|
41
41
|
return {
|
|
42
|
-
status:
|
|
43
|
-
type:
|
|
42
|
+
status: gt[t] ?? "draft",
|
|
43
|
+
type: pt[e] ?? "book",
|
|
44
44
|
timestamp: s,
|
|
45
45
|
machineId: n,
|
|
46
46
|
sequence: o
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
return BigInt(
|
|
49
|
+
function z(i, t, e, s, n) {
|
|
50
|
+
return BigInt(yt[i]) << st | BigInt(mt[t]) << nt | (e & rt) << ot | BigInt(s) << it | BigInt(n);
|
|
51
51
|
}
|
|
52
52
|
function E(i) {
|
|
53
53
|
return k(_(i));
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function kt(i) {
|
|
56
56
|
return E(i).type;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function Vt(i) {
|
|
59
59
|
return E(i).status;
|
|
60
60
|
}
|
|
61
|
-
const j = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" },
|
|
61
|
+
const j = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" }, St = { Book: "book", Collection: "collection", Work: "work", Entity: "entity" }, S = 16, Et = "附刻";
|
|
62
|
+
function L(i) {
|
|
63
|
+
const t = (n) => typeof n == "string" ? n : (n == null ? void 0 : n.book_title) ?? "", e = [], s = [];
|
|
64
|
+
for (const n of Array.isArray(i) ? i : [])
|
|
65
|
+
if (n && typeof n == "object" && n.type === Et) {
|
|
66
|
+
const o = t(n);
|
|
67
|
+
o && e.push(o);
|
|
68
|
+
} else {
|
|
69
|
+
const o = t(n);
|
|
70
|
+
o && s.push(o);
|
|
71
|
+
}
|
|
72
|
+
return { aliases: s, attached: e };
|
|
73
|
+
}
|
|
62
74
|
function P(i, t = S) {
|
|
63
75
|
let e = 0;
|
|
64
76
|
for (let s = 0; s < i.length; s++)
|
|
65
77
|
e = Math.imul(e, 31) + i.charCodeAt(s) >>> 0;
|
|
66
78
|
return e % t;
|
|
67
79
|
}
|
|
68
|
-
function
|
|
80
|
+
function vt(i) {
|
|
69
81
|
const t = {}, e = i.dating;
|
|
70
82
|
if (typeof e != "object" || e === null) return t;
|
|
71
83
|
const s = e.era;
|
|
@@ -83,7 +95,7 @@ function w(...i) {
|
|
|
83
95
|
const t = i.join("/");
|
|
84
96
|
return t.startsWith("//") ? "//" + t.slice(2).replace(/\/+/g, "/") : t.replace(/\/+/g, "/");
|
|
85
97
|
}
|
|
86
|
-
function
|
|
98
|
+
function xt(i) {
|
|
87
99
|
if (!Array.isArray(i)) return "";
|
|
88
100
|
for (const t of i)
|
|
89
101
|
if (typeof t == "object" && t !== null) {
|
|
@@ -92,70 +104,70 @@ function St(i) {
|
|
|
92
104
|
}
|
|
93
105
|
return "";
|
|
94
106
|
}
|
|
95
|
-
function
|
|
96
|
-
var
|
|
107
|
+
function K(i, t, e) {
|
|
108
|
+
var G;
|
|
97
109
|
const s = i.id || "";
|
|
98
110
|
let n = "", o = "", r = "";
|
|
99
111
|
const c = i.authors;
|
|
100
112
|
if (Array.isArray(c) && c.length > 0) {
|
|
101
|
-
const
|
|
102
|
-
typeof
|
|
113
|
+
const g = c[0];
|
|
114
|
+
typeof g == "object" && g !== null ? (n = g.name || "", r = g.role || "") : n = String(g);
|
|
103
115
|
} else typeof c == "string" && (n = c);
|
|
104
|
-
o =
|
|
116
|
+
o = xt(c) || (typeof i.dynasty == "string" ? i.dynasty : "");
|
|
105
117
|
let a = "";
|
|
106
118
|
const l = i.current_location;
|
|
107
119
|
if (typeof l == "object" && l !== null ? a = l.name || "" : typeof l == "string" && (a = l), !a && Array.isArray(i.provenance) && i.provenance.length > 0) {
|
|
108
|
-
const
|
|
109
|
-
typeof
|
|
110
|
-
}
|
|
111
|
-
const
|
|
112
|
-
let
|
|
113
|
-
const
|
|
114
|
-
if (typeof
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
const
|
|
119
|
-
let
|
|
120
|
-
const
|
|
121
|
-
if (Array.isArray(
|
|
122
|
-
for (const
|
|
123
|
-
if (typeof
|
|
124
|
-
const I =
|
|
125
|
-
Array.isArray(I) && (I.includes("text") && (
|
|
126
|
-
}
|
|
127
|
-
const
|
|
120
|
+
const g = (G = i.provenance[0]) == null ? void 0 : G.institution;
|
|
121
|
+
typeof g == "string" && (a = g);
|
|
122
|
+
}
|
|
123
|
+
const h = L(i.additional_titles), u = Array.isArray(i.additional_titles) ? h.aliases : void 0, d = h.attached.length > 0 ? h.attached : void 0;
|
|
124
|
+
let f;
|
|
125
|
+
const m = i.juan_count;
|
|
126
|
+
if (typeof m == "number" ? f = m : typeof m == "object" && m !== null && (f = m.number || void 0), !f && Array.isArray(i.measures)) {
|
|
127
|
+
const g = i.measures.find((I) => I && I.unit === "卷" && typeof I.number == "number" && I.number > 0);
|
|
128
|
+
g && (f = g.number);
|
|
129
|
+
}
|
|
130
|
+
const b = typeof i.measure_info == "string" ? i.measure_info : "";
|
|
131
|
+
let R = !1, B = !1;
|
|
132
|
+
const M = i.resources;
|
|
133
|
+
if (Array.isArray(M))
|
|
134
|
+
for (const g of M) {
|
|
135
|
+
if (typeof g != "object" || g === null) continue;
|
|
136
|
+
const I = g.types;
|
|
137
|
+
Array.isArray(I) && (I.includes("text") && (R = !0), I.includes("image") && (B = !0));
|
|
138
|
+
}
|
|
139
|
+
const y = {
|
|
128
140
|
id: s,
|
|
129
141
|
title: i.title || "未命名",
|
|
130
142
|
type: j[t],
|
|
131
143
|
path: e,
|
|
132
|
-
...
|
|
144
|
+
...vt(i)
|
|
133
145
|
};
|
|
134
|
-
n && (
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
return
|
|
146
|
+
n && (y.author = n), a && (y.holder = a), u && u.length > 0 && (y.additional_titles = u), d && d.length > 0 && (y.attached_texts = d), f && (y.juan_count = f), b && (y.measure_info = b);
|
|
147
|
+
const D = typeof i.edition == "string" ? i.edition : "";
|
|
148
|
+
D && (y.edition = D), R && (y.has_text = !0), B && (y.has_image = !0), o && (y.dynasty = o), r && (y.role = r);
|
|
149
|
+
const O = typeof i.subtype == "string" ? i.subtype : "";
|
|
150
|
+
O && (y.subtype = O);
|
|
151
|
+
const U = typeof i.period == "string" ? i.period : "";
|
|
152
|
+
U && (y.period = U);
|
|
153
|
+
const N = typeof i.loss_status == "string" ? i.loss_status : "";
|
|
154
|
+
N && (y.loss_status = N);
|
|
155
|
+
const J = typeof i.original_title == "string" ? i.original_title : "";
|
|
156
|
+
J && (y.original_title = J);
|
|
157
|
+
const W = typeof i.work_id == "string" ? i.work_id : "";
|
|
158
|
+
W && (y.work_id = W);
|
|
159
|
+
const H = typeof i._promoted_to == "string" ? i._promoted_to : "";
|
|
160
|
+
return H && (y.promoted_to = H), y;
|
|
149
161
|
}
|
|
150
|
-
const
|
|
151
|
-
function
|
|
162
|
+
const $t = 60;
|
|
163
|
+
function At(i) {
|
|
152
164
|
const t = i.replace(
|
|
153
165
|
/[^㐀-䶿一-鿿豈-a-zA-Z0-9\u{20000}-\u{3134f}]/gu,
|
|
154
166
|
""
|
|
155
167
|
);
|
|
156
|
-
return Array.from(t).slice(0,
|
|
168
|
+
return Array.from(t).slice(0, $t).join("") || "Undefined";
|
|
157
169
|
}
|
|
158
|
-
class
|
|
170
|
+
class ht {
|
|
159
171
|
constructor(t, e) {
|
|
160
172
|
this.fs = t, this.officialRoot = w(e, "book-index"), this.draftRoot = w(e, "book-index-draft");
|
|
161
173
|
}
|
|
@@ -171,7 +183,7 @@ class ct {
|
|
|
171
183
|
*/
|
|
172
184
|
getPath(t, e, s) {
|
|
173
185
|
const n = this.getRootById(e), o = e.padEnd(3, "_").substring(0, 3), [r, c, a] = [o[0], o[1], o[2]], l = j[t];
|
|
174
|
-
return w(n, l, r, c, a, `${e}-${
|
|
186
|
+
return w(n, l, r, c, a, `${e}-${At(s)}.json`);
|
|
175
187
|
}
|
|
176
188
|
/**
|
|
177
189
|
* 保存条目并更新索引
|
|
@@ -184,9 +196,9 @@ class ct {
|
|
|
184
196
|
} catch {
|
|
185
197
|
}
|
|
186
198
|
const l = c.substring(0, c.lastIndexOf("/"));
|
|
187
|
-
await this.fs.mkdir(l), s.id = e, s.type = t, await this.fs.writeFile(c, JSON.stringify(s,
|
|
188
|
-
const
|
|
189
|
-
return await this.updateIndexEntry(
|
|
199
|
+
await this.fs.mkdir(l), s.id = e, s.type = t, await this.fs.writeFile(c, JSON.stringify(s, Pt, 2));
|
|
200
|
+
const h = this.getRootById(e), u = c.substring(h.length + 1);
|
|
201
|
+
return await this.updateIndexEntry(h, s, t, u), c;
|
|
190
202
|
}
|
|
191
203
|
/**
|
|
192
204
|
* 更新索引分片中的条目
|
|
@@ -194,7 +206,7 @@ class ct {
|
|
|
194
206
|
async updateIndexEntry(t, e, s, n) {
|
|
195
207
|
const o = e.id || "";
|
|
196
208
|
if (!o) return;
|
|
197
|
-
const r = `${s}s`, c = await this.loadShard(t, r, o), a =
|
|
209
|
+
const r = `${s}s`, c = await this.loadShard(t, r, o), a = K(e, s, n);
|
|
198
210
|
c[o] = a, await this.saveShard(t, r, o, c);
|
|
199
211
|
}
|
|
200
212
|
/**
|
|
@@ -216,8 +228,8 @@ class ct {
|
|
|
216
228
|
const a = w(r, c, s, n, o);
|
|
217
229
|
if (await this.fs.exists(a))
|
|
218
230
|
try {
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
231
|
+
const h = (await this.fs.readdir(a)).find((u) => u.startsWith(`${t}-`) && u.endsWith(".json"));
|
|
232
|
+
if (h) return w(a, h);
|
|
221
233
|
} catch {
|
|
222
234
|
}
|
|
223
235
|
}
|
|
@@ -313,26 +325,26 @@ class ct {
|
|
|
313
325
|
for (const n of ["Book", "Collection", "Work"]) {
|
|
314
326
|
const o = w(e, n);
|
|
315
327
|
if (!await this.fs.exists(o)) continue;
|
|
316
|
-
const r =
|
|
328
|
+
const r = St[n], c = `${r}s`, a = await this.fs.glob(o, "**/*.json");
|
|
317
329
|
for (const l of a)
|
|
318
330
|
if (!l.includes("/index/"))
|
|
319
331
|
try {
|
|
320
|
-
const
|
|
321
|
-
let
|
|
322
|
-
if (!
|
|
332
|
+
const h = await this.loadMetadata(l);
|
|
333
|
+
let u = h.id || h.ID || "";
|
|
334
|
+
if (!u) {
|
|
323
335
|
const b = l.substring(l.lastIndexOf("/") + 1);
|
|
324
|
-
b.includes("-") && (
|
|
336
|
+
b.includes("-") && (u = b.split("-")[0]);
|
|
325
337
|
}
|
|
326
|
-
if (!
|
|
327
|
-
const d = l.substring(e.length + 1), f =
|
|
328
|
-
s[c][m][
|
|
338
|
+
if (!u) continue;
|
|
339
|
+
const d = l.substring(e.length + 1), f = K({ ...h, id: u }, r, d), m = c === "collections" ? 0 : P(u);
|
|
340
|
+
s[c][m][u] = f;
|
|
329
341
|
} catch {
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
for (const [n, o] of Object.entries(s))
|
|
333
345
|
for (const [r, c] of Object.entries(o)) {
|
|
334
346
|
const a = this.shardPath(e, n, Number(r)), l = a.substring(0, a.lastIndexOf("/"));
|
|
335
|
-
await this.fs.mkdir(l), await this.fs.writeFile(a, JSON.stringify(
|
|
347
|
+
await this.fs.mkdir(l), await this.fs.writeFile(a, JSON.stringify(Y(c), null, await this.detectShardIndent(a)));
|
|
336
348
|
}
|
|
337
349
|
}
|
|
338
350
|
// ── Asset Directory ──
|
|
@@ -341,8 +353,8 @@ class ct {
|
|
|
341
353
|
* 与 JSON 文件同级,以 ID 命名
|
|
342
354
|
*/
|
|
343
355
|
getAssetDir(t) {
|
|
344
|
-
const e = this.getRootById(t), s = _(t), o = k(s).type, r = t.padEnd(3, "_").substring(0, 3), [c, a, l] = [r[0], r[1], r[2]],
|
|
345
|
-
return w(e,
|
|
356
|
+
const e = this.getRootById(t), s = _(t), o = k(s).type, r = t.padEnd(3, "_").substring(0, 3), [c, a, l] = [r[0], r[1], r[2]], h = j[o];
|
|
357
|
+
return w(e, h, c, a, l, t);
|
|
346
358
|
}
|
|
347
359
|
/**
|
|
348
360
|
* 初始化资源目录:创建 {ID}/ 文件夹
|
|
@@ -397,7 +409,7 @@ class ct {
|
|
|
397
409
|
const o = P(s), r = this.shardPath(t, e, o), c = r.substring(0, r.lastIndexOf("/"));
|
|
398
410
|
await this.fs.mkdir(c);
|
|
399
411
|
const a = await this.detectShardIndent(r);
|
|
400
|
-
await this.fs.writeFile(r, JSON.stringify(
|
|
412
|
+
await this.fs.writeFile(r, JSON.stringify(Y(n), null, a));
|
|
401
413
|
}
|
|
402
414
|
async loadAllShards(t, e) {
|
|
403
415
|
const s = {};
|
|
@@ -432,8 +444,8 @@ function C(i, t) {
|
|
|
432
444
|
n === e ? s = 200 : n.startsWith(e) ? s = 150 : n.includes(e) && (s = 100);
|
|
433
445
|
const o = [...i.additional_titles || [], ...i.attached_texts || []];
|
|
434
446
|
for (const l of o) {
|
|
435
|
-
const
|
|
436
|
-
|
|
447
|
+
const h = l.toLowerCase();
|
|
448
|
+
h === e ? s = Math.max(s, 120) : h.startsWith(e) ? s = Math.max(s, 90) : h.includes(e) && (s = Math.max(s, 60));
|
|
437
449
|
}
|
|
438
450
|
let r = 0;
|
|
439
451
|
if (i.author) {
|
|
@@ -445,19 +457,19 @@ function C(i, t) {
|
|
|
445
457
|
let a = s;
|
|
446
458
|
return a === 0 && (a = Math.max(r, c)), a === 0 ? 0 : (a += Math.max(0, 20 - n.length), i.type === "work" ? a = Math.round(a * 1.05) : i.type === "collection" && (a = Math.round(a * 1.02)), i.has_text && (a += 3), i.has_image && (a += 2), a);
|
|
447
459
|
}
|
|
448
|
-
function
|
|
460
|
+
function Y(i) {
|
|
449
461
|
const t = {};
|
|
450
462
|
for (const e of Object.keys(i).sort()) t[e] = i[e];
|
|
451
463
|
return t;
|
|
452
464
|
}
|
|
453
|
-
function
|
|
465
|
+
function Pt(i, t) {
|
|
454
466
|
return t === null ? void 0 : t;
|
|
455
467
|
}
|
|
456
468
|
function T(i, t) {
|
|
457
469
|
const e = i.map((s) => ({ entry: s, score: C(s, t) })).filter((s) => s.score > 0);
|
|
458
470
|
return e.sort((s, n) => n.score !== s.score ? n.score - s.score : s.entry.title.length - n.entry.title.length), e.map((s) => s.entry);
|
|
459
471
|
}
|
|
460
|
-
function
|
|
472
|
+
function V(i, t, e, s) {
|
|
461
473
|
const n = i.map((o) => {
|
|
462
474
|
const r = C(o, t);
|
|
463
475
|
let c = 0;
|
|
@@ -476,7 +488,7 @@ function K(i, t, e, s) {
|
|
|
476
488
|
}).filter((o) => o.score > 0);
|
|
477
489
|
return n.sort((o, r) => r.score !== o.score ? r.score - o.score : o.entry.title.length - r.entry.title.length), n.map((o) => o.entry);
|
|
478
490
|
}
|
|
479
|
-
function
|
|
491
|
+
function jt(i) {
|
|
480
492
|
const t = i.volumes ?? [];
|
|
481
493
|
let e, s;
|
|
482
494
|
if (t.length === 0)
|
|
@@ -516,24 +528,24 @@ function $t(i) {
|
|
|
516
528
|
n[o] === void 0 && delete n[o];
|
|
517
529
|
return n;
|
|
518
530
|
}
|
|
519
|
-
function
|
|
531
|
+
function Ct(i) {
|
|
520
532
|
const t = {
|
|
521
533
|
total_books: i.total_books ?? 0
|
|
522
534
|
};
|
|
523
535
|
return i.processed_volumes != null && (t.processed_volumes = i.processed_volumes), i.matched_works != null && (t.matched_works = i.matched_works), i.unmatched_works != null && (t.unmatched_works = i.unmatched_works), i.total_found_volumes != null && (t.total_found_volumes = i.total_found_volumes), t;
|
|
524
536
|
}
|
|
525
|
-
function
|
|
537
|
+
function ut(i) {
|
|
526
538
|
var n;
|
|
527
|
-
const t = i, e = (t.books ?? []).map(
|
|
539
|
+
const t = i, e = (t.books ?? []).map(jt), s = {
|
|
528
540
|
collection_id: t.collection_id ?? "",
|
|
529
541
|
title: t.title ?? "",
|
|
530
542
|
total_volumes: t.total_volumes ?? 0,
|
|
531
|
-
stats:
|
|
543
|
+
stats: Ct(t.stats ?? {}),
|
|
532
544
|
books: e
|
|
533
545
|
};
|
|
534
546
|
return t.source && (s.source = t.source), t.resource_id && (s.resource_id = t.resource_id), t.resource_name && (s.resource_name = t.resource_name), (n = t.sections) != null && n.length && (s.sections = t.sections), t.volume_index && Object.keys(t.volume_index).length > 0 && (s.volume_index = t.volume_index), s;
|
|
535
547
|
}
|
|
536
|
-
const
|
|
548
|
+
const X = 2;
|
|
537
549
|
function F(i) {
|
|
538
550
|
const t = /* @__PURE__ */ new Map();
|
|
539
551
|
if (!i || typeof i != "object") return t;
|
|
@@ -548,7 +560,7 @@ function F(i) {
|
|
|
548
560
|
o && typeof o == "object" && typeof o.production_id == "string" && t.set(n, o.production_id);
|
|
549
561
|
return t;
|
|
550
562
|
}
|
|
551
|
-
const
|
|
563
|
+
const Tt = {
|
|
552
564
|
㐫: "凶",
|
|
553
565
|
㐮: "襄",
|
|
554
566
|
㐲: "伏",
|
|
@@ -1302,29 +1314,29 @@ const Pt = {
|
|
|
1302
1314
|
"𫝊": "傳",
|
|
1303
1315
|
"𬒳": "被",
|
|
1304
1316
|
"兔": "兔"
|
|
1305
|
-
},
|
|
1306
|
-
function
|
|
1317
|
+
}, Ft = Tt;
|
|
1318
|
+
function Lt(i) {
|
|
1307
1319
|
if (!i) return i;
|
|
1308
1320
|
let t = !1, e = "";
|
|
1309
1321
|
for (const s of i) {
|
|
1310
|
-
const n =
|
|
1322
|
+
const n = Ft[s] ?? ft[s];
|
|
1311
1323
|
n !== void 0 ? (e += n, t = !0) : e += s;
|
|
1312
1324
|
}
|
|
1313
1325
|
return t ? e : i;
|
|
1314
1326
|
}
|
|
1315
|
-
const
|
|
1327
|
+
const Rt = "https://raw.githubusercontent.com", Bt = [
|
|
1316
1328
|
"https://fastly.jsdelivr.net/gh",
|
|
1317
1329
|
"https://cdn.jsdelivr.net/gh"
|
|
1318
|
-
],
|
|
1319
|
-
class
|
|
1330
|
+
], Mt = 5e3;
|
|
1331
|
+
class Xt {
|
|
1320
1332
|
// null=未加载, false=不可用
|
|
1321
1333
|
constructor(t) {
|
|
1322
1334
|
this.cache = null, this.cacheLoading = null, this.pathMap = /* @__PURE__ */ new Map(), this.promotions = /* @__PURE__ */ new Map(), this.searchSCache = null, this.t2sConverter = null, this.config = {
|
|
1323
1335
|
org: t.org,
|
|
1324
1336
|
repos: t.repos,
|
|
1325
|
-
baseUrl: t.baseUrl ??
|
|
1326
|
-
cdnUrls: t.cdnUrls ??
|
|
1327
|
-
timeout: t.timeout ??
|
|
1337
|
+
baseUrl: t.baseUrl ?? Rt,
|
|
1338
|
+
cdnUrls: t.cdnUrls ?? Bt,
|
|
1339
|
+
timeout: t.timeout ?? Mt
|
|
1328
1340
|
};
|
|
1329
1341
|
}
|
|
1330
1342
|
/** 拉取 promotions.json(仅 draft repo 有);失败按空映射处理。 */
|
|
@@ -1457,41 +1469,40 @@ class Kt {
|
|
|
1457
1469
|
}
|
|
1458
1470
|
/** 解析 index.json 为 IndexEntry[] */
|
|
1459
1471
|
parseIndexResponse(t, e) {
|
|
1460
|
-
var o, r;
|
|
1461
1472
|
const s = [], n = [
|
|
1462
1473
|
["books", "book"],
|
|
1463
1474
|
["collections", "collection"],
|
|
1464
1475
|
["works", "work"],
|
|
1465
1476
|
["entities", "entity"]
|
|
1466
1477
|
];
|
|
1467
|
-
for (const [
|
|
1468
|
-
const
|
|
1469
|
-
if (
|
|
1470
|
-
for (const
|
|
1471
|
-
const h =
|
|
1478
|
+
for (const [o, r] of n) {
|
|
1479
|
+
const c = t[o];
|
|
1480
|
+
if (c)
|
|
1481
|
+
for (const a of Object.values(c)) {
|
|
1482
|
+
const l = a, h = L(l.additional_titles), u = r === "entity" ? l.primary_name || a.title || a.name || a.id : a.title || a.name || a.id;
|
|
1472
1483
|
s.push({
|
|
1473
|
-
id:
|
|
1474
|
-
title:
|
|
1475
|
-
type:
|
|
1484
|
+
id: a.id,
|
|
1485
|
+
title: u,
|
|
1486
|
+
type: r,
|
|
1476
1487
|
isDraft: e,
|
|
1477
|
-
author:
|
|
1478
|
-
dynasty:
|
|
1479
|
-
role:
|
|
1480
|
-
path:
|
|
1481
|
-
additional_titles:
|
|
1482
|
-
attached_texts:
|
|
1483
|
-
edition:
|
|
1484
|
-
juan_count:
|
|
1485
|
-
has_text:
|
|
1486
|
-
has_image:
|
|
1487
|
-
has_collated:
|
|
1488
|
-
subtype:
|
|
1489
|
-
primary_name:
|
|
1490
|
-
birth_year:
|
|
1491
|
-
death_year:
|
|
1492
|
-
cbdb_id:
|
|
1493
|
-
promoted_to:
|
|
1494
|
-
}), this.pathMap.set(
|
|
1488
|
+
author: a.author,
|
|
1489
|
+
dynasty: a.dynasty,
|
|
1490
|
+
role: a.role,
|
|
1491
|
+
path: a.path,
|
|
1492
|
+
additional_titles: l.additional_titles ? h.aliases : void 0,
|
|
1493
|
+
attached_texts: h.attached.length ? h.attached : void 0,
|
|
1494
|
+
edition: l.edition,
|
|
1495
|
+
juan_count: l.juan_count,
|
|
1496
|
+
has_text: l.has_text,
|
|
1497
|
+
has_image: l.has_image,
|
|
1498
|
+
has_collated: l.has_collated,
|
|
1499
|
+
subtype: l.subtype,
|
|
1500
|
+
primary_name: l.primary_name,
|
|
1501
|
+
birth_year: l.birth_year,
|
|
1502
|
+
death_year: l.death_year,
|
|
1503
|
+
cbdb_id: l.cbdb_id,
|
|
1504
|
+
promoted_to: l.promoted_to
|
|
1505
|
+
}), this.pathMap.set(a.id, { path: a.path, isDraft: e });
|
|
1495
1506
|
}
|
|
1496
1507
|
}
|
|
1497
1508
|
return s;
|
|
@@ -1509,7 +1520,7 @@ class Kt {
|
|
|
1509
1520
|
return { searchS: {}, converter: null };
|
|
1510
1521
|
try {
|
|
1511
1522
|
const c = (await import("opencc-js")).Converter({ from: "t", to: "cn" });
|
|
1512
|
-
this.t2sConverter = (a) => c(
|
|
1523
|
+
this.t2sConverter = (a) => c(Lt(a));
|
|
1513
1524
|
} catch {
|
|
1514
1525
|
return this.t2sConverter = !1, this.searchSCache = {}, { searchS: {}, converter: null };
|
|
1515
1526
|
}
|
|
@@ -1522,11 +1533,11 @@ class Kt {
|
|
|
1522
1533
|
}
|
|
1523
1534
|
if ((n = r.additional_titles) != null && n.length) {
|
|
1524
1535
|
const l = r.additional_titles.map(e);
|
|
1525
|
-
l.some((
|
|
1536
|
+
l.some((h, u) => h !== r.additional_titles[u]) && (c.at = l);
|
|
1526
1537
|
}
|
|
1527
1538
|
if ((o = r.attached_texts) != null && o.length) {
|
|
1528
1539
|
const l = r.attached_texts.map(e);
|
|
1529
|
-
l.some((
|
|
1540
|
+
l.some((h, u) => h !== r.attached_texts[u]) && (c.axt = l);
|
|
1530
1541
|
}
|
|
1531
1542
|
Object.keys(c).length > 0 && (s[r.id] = c);
|
|
1532
1543
|
}
|
|
@@ -1534,10 +1545,10 @@ class Kt {
|
|
|
1534
1545
|
}
|
|
1535
1546
|
// --- IndexStorage 实现 ---
|
|
1536
1547
|
async loadEntries(t, e) {
|
|
1537
|
-
let n = (await this.ensureLoaded()).filter((
|
|
1548
|
+
let n = (await this.ensureLoaded()).filter((u) => u.type === t);
|
|
1538
1549
|
const o = e.sortBy || "title", r = e.sortOrder || "asc";
|
|
1539
|
-
n.sort((
|
|
1540
|
-
const f = String(
|
|
1550
|
+
n.sort((u, d) => {
|
|
1551
|
+
const f = String(u[o] ?? ""), m = String(d[o] ?? ""), b = f.localeCompare(m, "zh");
|
|
1541
1552
|
return r === "asc" ? b : -b;
|
|
1542
1553
|
});
|
|
1543
1554
|
const c = e.page || 1, a = e.pageSize || 50, l = (c - 1) * a;
|
|
@@ -1549,18 +1560,18 @@ class Kt {
|
|
|
1549
1560
|
};
|
|
1550
1561
|
}
|
|
1551
1562
|
async search(t, e, s) {
|
|
1552
|
-
const n = await this.ensureLoaded(), { searchS: o, converter: r } = await this.ensureSearchSBuilt(), c = n.filter((m) => m.type === e), a = r ? r(t) : void 0,
|
|
1563
|
+
const n = await this.ensureLoaded(), { searchS: o, converter: r } = await this.ensureSearchSBuilt(), c = n.filter((m) => m.type === e), a = r ? r(t) : void 0, h = Object.keys(o).length > 0 ? V(c, t, a, o) : T(c, t), u = s.page || 1, d = s.pageSize || 50, f = (u - 1) * d;
|
|
1553
1564
|
return {
|
|
1554
|
-
entries:
|
|
1555
|
-
total:
|
|
1556
|
-
page:
|
|
1565
|
+
entries: h.slice(f, f + d),
|
|
1566
|
+
total: h.length,
|
|
1567
|
+
page: u,
|
|
1557
1568
|
pageSize: d
|
|
1558
1569
|
};
|
|
1559
1570
|
}
|
|
1560
1571
|
async searchAll(t, e = 5) {
|
|
1561
|
-
const s = await this.ensureLoaded(), { searchS: n, converter: o } = await this.ensureSearchSBuilt(), r = ["work", "book", "collection"], c = o ? o(t) : void 0, a = Object.keys(n).length > 0, l = r.map((
|
|
1562
|
-
const
|
|
1563
|
-
return a ?
|
|
1572
|
+
const s = await this.ensureLoaded(), { searchS: n, converter: o } = await this.ensureSearchSBuilt(), r = ["work", "book", "collection"], c = o ? o(t) : void 0, a = Object.keys(n).length > 0, l = r.map((h) => {
|
|
1573
|
+
const u = s.filter((d) => d.type === h);
|
|
1574
|
+
return a ? V(u, t, c, n) : T(u, t);
|
|
1564
1575
|
});
|
|
1565
1576
|
return {
|
|
1566
1577
|
works: l[0].slice(0, e),
|
|
@@ -1634,18 +1645,18 @@ class Kt {
|
|
|
1634
1645
|
const e = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" };
|
|
1635
1646
|
let s, n;
|
|
1636
1647
|
try {
|
|
1637
|
-
const
|
|
1638
|
-
s =
|
|
1648
|
+
const h = k(_(t));
|
|
1649
|
+
s = h.type, n = h.status;
|
|
1639
1650
|
} catch {
|
|
1640
1651
|
return null;
|
|
1641
1652
|
}
|
|
1642
1653
|
const o = n === "draft" ? this.config.repos.draft : this.config.repos.official, r = e[s], c = t.padEnd(3, "_").substring(0, 3), a = `${r}/${c[0]}/${c[1]}/${c[2]}`, l = `https://api.github.com/repos/${this.config.org}/${o}/contents/${a}`;
|
|
1643
1654
|
try {
|
|
1644
|
-
const
|
|
1655
|
+
const h = await fetch(l, {
|
|
1645
1656
|
signal: AbortSignal.timeout(this.config.timeout)
|
|
1646
1657
|
});
|
|
1647
|
-
if (!
|
|
1648
|
-
const d = (await
|
|
1658
|
+
if (!h.ok) return null;
|
|
1659
|
+
const d = (await h.json()).find((m) => m.name.startsWith(`${t}-`) && m.name.endsWith(".json"));
|
|
1649
1660
|
if (!d) return null;
|
|
1650
1661
|
const f = await this.fetchItemByPath(o, d.path);
|
|
1651
1662
|
return f && this.pathMap.set(t, { path: d.path, isDraft: n === "draft" }), f;
|
|
@@ -1720,7 +1731,7 @@ class Kt {
|
|
|
1720
1731
|
a && o.push({
|
|
1721
1732
|
resource_id: r.id,
|
|
1722
1733
|
short_name: r.short_name,
|
|
1723
|
-
data:
|
|
1734
|
+
data: ut(a)
|
|
1724
1735
|
});
|
|
1725
1736
|
}
|
|
1726
1737
|
return o.length > 0 ? o : null;
|
|
@@ -1756,8 +1767,8 @@ class Kt {
|
|
|
1756
1767
|
this.cache = null, this.pathMap.clear(), this.searchSCache = null, this.t2sConverter = null;
|
|
1757
1768
|
}
|
|
1758
1769
|
}
|
|
1759
|
-
const
|
|
1760
|
-
class
|
|
1770
|
+
const Q = 255;
|
|
1771
|
+
class dt {
|
|
1761
1772
|
constructor(t) {
|
|
1762
1773
|
if (this.lastTimestamp = -1, this.lastStatus = null, this.sequence = 0, t < 0 || t > 2047)
|
|
1763
1774
|
throw new Error("Machine ID must be between 0 and 2047");
|
|
@@ -1770,8 +1781,8 @@ class ht {
|
|
|
1770
1781
|
let s = this._getCurrentTimestamp(t);
|
|
1771
1782
|
if (s < this.lastTimestamp && t === this.lastStatus)
|
|
1772
1783
|
throw new Error("Clock moved backwards. Refusing to generate ID.");
|
|
1773
|
-
s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 &
|
|
1774
|
-
const n =
|
|
1784
|
+
s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & Q, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t;
|
|
1785
|
+
const n = z(t, e, BigInt(s), this.machineId, this.sequence);
|
|
1775
1786
|
return A(n);
|
|
1776
1787
|
}
|
|
1777
1788
|
/**
|
|
@@ -1781,7 +1792,7 @@ class ht {
|
|
|
1781
1792
|
let s = this._getCurrentTimestamp(t);
|
|
1782
1793
|
if (s < this.lastTimestamp && t === this.lastStatus)
|
|
1783
1794
|
throw new Error("Clock moved backwards. Refusing to generate ID.");
|
|
1784
|
-
return s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 &
|
|
1795
|
+
return s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & Q, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t, z(t, e, BigInt(s), this.machineId, this.sequence);
|
|
1785
1796
|
}
|
|
1786
1797
|
_getCurrentTimestamp(t) {
|
|
1787
1798
|
const e = Date.now();
|
|
@@ -1794,9 +1805,9 @@ class ht {
|
|
|
1794
1805
|
return s;
|
|
1795
1806
|
}
|
|
1796
1807
|
}
|
|
1797
|
-
class
|
|
1808
|
+
class Qt {
|
|
1798
1809
|
constructor(t) {
|
|
1799
|
-
this.recentEntities = [], this.storage = new
|
|
1810
|
+
this.recentEntities = [], this.storage = new ht(t.fs, t.workspaceRoot), this.idGen = new dt(t.machineId ?? 0), this.fs = t.fs, this.workspaceRoot = t.workspaceRoot;
|
|
1800
1811
|
}
|
|
1801
1812
|
async loadEntries(t, e) {
|
|
1802
1813
|
const s = await this.storage.loadEntries(t);
|
|
@@ -2012,8 +2023,8 @@ class Yt {
|
|
|
2012
2023
|
const s = e.page ?? 1, n = e.pageSize ?? 50;
|
|
2013
2024
|
if (e.sortBy) {
|
|
2014
2025
|
const a = e.sortBy, l = e.sortOrder === "desc" ? -1 : 1;
|
|
2015
|
-
t.sort((
|
|
2016
|
-
const d =
|
|
2026
|
+
t.sort((h, u) => {
|
|
2027
|
+
const d = h[a] ?? "", f = u[a] ?? "";
|
|
2017
2028
|
return d < f ? -l : d > f ? l : 0;
|
|
2018
2029
|
});
|
|
2019
2030
|
}
|
|
@@ -2021,33 +2032,33 @@ class Yt {
|
|
|
2021
2032
|
return { entries: t.slice(r, r + n), total: o, page: s, pageSize: n };
|
|
2022
2033
|
}
|
|
2023
2034
|
}
|
|
2024
|
-
function
|
|
2035
|
+
function Zt(i) {
|
|
2025
2036
|
return i === "collated" || i === "self_collated";
|
|
2026
2037
|
}
|
|
2027
|
-
const
|
|
2028
|
-
function
|
|
2029
|
-
return typeof i != "string" ? !1 : i === "default" ? !0 :
|
|
2038
|
+
const Dt = ["default", "manifest", "fragments", "sources", "extra"], Ot = /^[a-z][a-z0-9-]*$/;
|
|
2039
|
+
function Z(i) {
|
|
2040
|
+
return typeof i != "string" ? !1 : i === "default" ? !0 : Ot.test(i) && !Dt.includes(i);
|
|
2030
2041
|
}
|
|
2031
|
-
function
|
|
2042
|
+
function te(i) {
|
|
2032
2043
|
return /^\d+$/.test(i);
|
|
2033
2044
|
}
|
|
2034
2045
|
function x(i) {
|
|
2035
2046
|
return i.length > 0 && !i.includes("..") && !/[\\/?#%\s\u0000-\u001f\u007f]/.test(i);
|
|
2036
2047
|
}
|
|
2037
|
-
const
|
|
2038
|
-
function
|
|
2048
|
+
const Ut = /^(整理本|整理|转录全文|轉錄全文|转录|轉錄|全文|文本)$/;
|
|
2049
|
+
function ee(i) {
|
|
2039
2050
|
var s;
|
|
2040
|
-
const t =
|
|
2051
|
+
const t = Nt(i), e = (s = i.edition_label) == null ? void 0 : s.trim();
|
|
2041
2052
|
return e && e !== t ? `${e} · ${t}` : t;
|
|
2042
2053
|
}
|
|
2043
|
-
function
|
|
2054
|
+
function Nt(i) {
|
|
2044
2055
|
for (const t of [i.label, i.source_name]) {
|
|
2045
2056
|
const e = t == null ? void 0 : t.trim();
|
|
2046
|
-
if (e && !
|
|
2057
|
+
if (e && !Ut.test(e)) return e;
|
|
2047
2058
|
}
|
|
2048
2059
|
return i.label || i.source_name || i.key;
|
|
2049
2060
|
}
|
|
2050
|
-
function
|
|
2061
|
+
function se(i, t) {
|
|
2051
2062
|
const e = (t == null ? void 0 : t.chapters) ?? [];
|
|
2052
2063
|
if (e.length === 0) return null;
|
|
2053
2064
|
if (i) {
|
|
@@ -2060,15 +2071,15 @@ function Zt(i, t) {
|
|
|
2060
2071
|
}
|
|
2061
2072
|
return e[0].file;
|
|
2062
2073
|
}
|
|
2063
|
-
function
|
|
2074
|
+
function ne(i, t) {
|
|
2064
2075
|
const e = i == null ? void 0 : i.versions;
|
|
2065
2076
|
if (!(!e || e.length === 0))
|
|
2066
2077
|
return (t != null ? e.find((s) => s.key === t) : void 0) ?? e.find((s) => s.key === "default") ?? e[0];
|
|
2067
2078
|
}
|
|
2068
|
-
const
|
|
2069
|
-
class
|
|
2079
|
+
const Jt = "/data", Wt = 1e4;
|
|
2080
|
+
class oe {
|
|
2070
2081
|
constructor(t = {}) {
|
|
2071
|
-
this.hubsLoading = null, this.chunkCache = /* @__PURE__ */ new Map(), this.chunkLoading = /* @__PURE__ */ new Map(), this.manifest = null, this.manifestLoading = null, this.entryFileCache = /* @__PURE__ */ new Map(), this.tiyaoCache = /* @__PURE__ */ new Map(), this.tiyaoLoading = /* @__PURE__ */ new Map(), this.metaCache = null, this.metaLoading = null, this.promotions = null, this.promotionsLoading = null, this.promotionsLoadFailed = !1, this.promotionShards = /* @__PURE__ */ new Map(), this.versionPromise = null, this.versionInjected = !1, this.basePath = t.basePath ??
|
|
2082
|
+
this.hubsLoading = null, this.chunkCache = /* @__PURE__ */ new Map(), this.chunkLoading = /* @__PURE__ */ new Map(), this.manifest = null, this.manifestLoading = null, this.entryFileCache = /* @__PURE__ */ new Map(), this.tiyaoCache = /* @__PURE__ */ new Map(), this.tiyaoLoading = /* @__PURE__ */ new Map(), this.metaCache = null, this.metaLoading = null, this.promotions = null, this.promotionsLoading = null, this.promotionsLoadFailed = !1, this.promotionShards = /* @__PURE__ */ new Map(), this.versionPromise = null, this.versionInjected = !1, this.basePath = t.basePath ?? Jt, this.timeout = t.timeout ?? Wt, this.hubsPath = t.hubsPath ?? "_hubs.json", this.detailLayout = t.detailLayout ?? "auto", t.version !== void 0 && (this.version = t.version ?? null, this.versionInjected = !0);
|
|
2072
2083
|
}
|
|
2073
2084
|
// ─── 内部工具 ───
|
|
2074
2085
|
/**
|
|
@@ -2121,7 +2132,7 @@ class ee {
|
|
|
2121
2132
|
}
|
|
2122
2133
|
/** 取草稿 id 所在的一片 `promotions/<末2位>.json`(几 KB);取不到返回 null,调用方退回整档 */
|
|
2123
2134
|
promotionShard(t) {
|
|
2124
|
-
const e = t.slice(-
|
|
2135
|
+
const e = t.slice(-X);
|
|
2125
2136
|
let s = this.promotionShards.get(e);
|
|
2126
2137
|
return s || (s = this.fetchJson(`${this.basePath}/promotions/${e}.json`).then((n) => {
|
|
2127
2138
|
const o = F(n);
|
|
@@ -2134,7 +2145,7 @@ class ee {
|
|
|
2134
2145
|
*/
|
|
2135
2146
|
async canonicalIdFor(t) {
|
|
2136
2147
|
if (this.promotions && !this.promotionsLoadFailed) return this.promotions.get(t) ?? t;
|
|
2137
|
-
if (t.length >=
|
|
2148
|
+
if (t.length >= X) {
|
|
2138
2149
|
const e = await this.promotionShard(t);
|
|
2139
2150
|
if (e) return e.get(t) ?? t;
|
|
2140
2151
|
}
|
|
@@ -2284,32 +2295,32 @@ class ee {
|
|
|
2284
2295
|
}
|
|
2285
2296
|
/** 从 chunk 读取详情构造 IndexEntry。chunk miss 即返回 null(无 fallback)。 */
|
|
2286
2297
|
async getEntry(t) {
|
|
2287
|
-
var e, s
|
|
2298
|
+
var e, s;
|
|
2288
2299
|
try {
|
|
2289
|
-
const
|
|
2290
|
-
if (!
|
|
2291
|
-
const
|
|
2300
|
+
const n = await this.canonicalIdFor(t), o = n !== t ? t : void 0, r = await this.loadDetail(n);
|
|
2301
|
+
if (!r) return null;
|
|
2302
|
+
const c = kt(n), a = L(r.additional_titles), l = c === "entity" ? r.primary_name || r.title || r.name || n : r.title || r.name || n;
|
|
2292
2303
|
return {
|
|
2293
|
-
id:
|
|
2294
|
-
title:
|
|
2295
|
-
type:
|
|
2304
|
+
id: n,
|
|
2305
|
+
title: l,
|
|
2306
|
+
type: c,
|
|
2296
2307
|
isDraft: !0,
|
|
2297
|
-
author:
|
|
2298
|
-
dynasty:
|
|
2299
|
-
role:
|
|
2300
|
-
additional_titles:
|
|
2301
|
-
attached_texts:
|
|
2302
|
-
edition:
|
|
2303
|
-
juan_count:
|
|
2304
|
-
has_text:
|
|
2305
|
-
has_image:
|
|
2306
|
-
has_collated:
|
|
2307
|
-
subtype:
|
|
2308
|
-
primary_name:
|
|
2309
|
-
birth_year: ((
|
|
2310
|
-
death_year: ((
|
|
2311
|
-
cbdb_id:
|
|
2312
|
-
...
|
|
2308
|
+
author: r.author,
|
|
2309
|
+
dynasty: r.dynasty,
|
|
2310
|
+
role: r.role,
|
|
2311
|
+
additional_titles: r.additional_titles ? a.aliases : void 0,
|
|
2312
|
+
attached_texts: a.attached.length ? a.attached : void 0,
|
|
2313
|
+
edition: r.edition,
|
|
2314
|
+
juan_count: r.juan_count,
|
|
2315
|
+
has_text: r.has_text,
|
|
2316
|
+
has_image: r.has_image,
|
|
2317
|
+
has_collated: r.has_collated,
|
|
2318
|
+
subtype: r.subtype,
|
|
2319
|
+
primary_name: r.primary_name,
|
|
2320
|
+
birth_year: ((e = r.dates) == null ? void 0 : e.birth) ?? void 0,
|
|
2321
|
+
death_year: ((s = r.dates) == null ? void 0 : s.death) ?? void 0,
|
|
2322
|
+
cbdb_id: r.cbdb_id,
|
|
2323
|
+
...o ? { redirected_from: o } : {}
|
|
2313
2324
|
};
|
|
2314
2325
|
} catch {
|
|
2315
2326
|
return null;
|
|
@@ -2344,7 +2355,7 @@ class ee {
|
|
|
2344
2355
|
r && n.push({
|
|
2345
2356
|
resource_id: o.id,
|
|
2346
2357
|
short_name: o.short_name,
|
|
2347
|
-
data:
|
|
2358
|
+
data: ut(r)
|
|
2348
2359
|
});
|
|
2349
2360
|
} catch {
|
|
2350
2361
|
}
|
|
@@ -2369,7 +2380,7 @@ class ee {
|
|
|
2369
2380
|
}
|
|
2370
2381
|
}
|
|
2371
2382
|
async getTextIndex(t, e) {
|
|
2372
|
-
if (!x(t) || !
|
|
2383
|
+
if (!x(t) || !Z(e)) return null;
|
|
2373
2384
|
try {
|
|
2374
2385
|
const s = await this.fetchJson(`${this.basePath}/items/${t}/${e}/index.json`);
|
|
2375
2386
|
return s && Array.isArray(s.chapters) ? s : null;
|
|
@@ -2378,9 +2389,9 @@ class ee {
|
|
|
2378
2389
|
}
|
|
2379
2390
|
}
|
|
2380
2391
|
async getChapter(t, e, s, n) {
|
|
2381
|
-
if (!x(t) || !
|
|
2382
|
-
const o = `${this.basePath}/items/${t}/${e}/${s}`, r = await this.ensureVersion(), c = r ? `${o}.txt?v=${r}` : `${o}.txt`, a = fetch(c, { cache: "no-cache", signal: AbortSignal.timeout(this.timeout) }).then((d) => d.ok ? d.text() : null).catch(() => null), l = n != null && n.json ? this.fetchJson(`${o}.json`).catch(() => null) : Promise.resolve(null), [
|
|
2383
|
-
return
|
|
2392
|
+
if (!x(t) || !Z(e) || !x(s)) return null;
|
|
2393
|
+
const o = `${this.basePath}/items/${t}/${e}/${s}`, r = await this.ensureVersion(), c = r ? `${o}.txt?v=${r}` : `${o}.txt`, a = fetch(c, { cache: "no-cache", signal: AbortSignal.timeout(this.timeout) }).then((d) => d.ok ? d.text() : null).catch(() => null), l = n != null && n.json ? this.fetchJson(`${o}.json`).catch(() => null) : Promise.resolve(null), [h, u] = await Promise.all([a, l]);
|
|
2394
|
+
return h != null || u ? { md: h, json: u } : null;
|
|
2384
2395
|
}
|
|
2385
2396
|
// ─── 版本传承 ───
|
|
2386
2397
|
async getLineageGraph(t) {
|
|
@@ -2436,29 +2447,29 @@ class v extends Error {
|
|
|
2436
2447
|
super(t), this.name = "BookIndexError";
|
|
2437
2448
|
}
|
|
2438
2449
|
}
|
|
2439
|
-
class
|
|
2450
|
+
class ie extends v {
|
|
2440
2451
|
constructor(t) {
|
|
2441
2452
|
super(t), this.name = "StorageError";
|
|
2442
2453
|
}
|
|
2443
2454
|
}
|
|
2444
|
-
class
|
|
2455
|
+
class re extends v {
|
|
2445
2456
|
constructor(t) {
|
|
2446
2457
|
super(t), this.name = "IdGenerationError";
|
|
2447
2458
|
}
|
|
2448
2459
|
}
|
|
2449
|
-
class
|
|
2460
|
+
class ae extends v {
|
|
2450
2461
|
constructor(t) {
|
|
2451
2462
|
super(t), this.name = "ConfigError";
|
|
2452
2463
|
}
|
|
2453
2464
|
}
|
|
2454
|
-
class
|
|
2465
|
+
class ce extends v {
|
|
2455
2466
|
constructor(t) {
|
|
2456
2467
|
super(t), this.name = "MigrationError";
|
|
2457
2468
|
}
|
|
2458
2469
|
}
|
|
2459
|
-
class
|
|
2470
|
+
class le {
|
|
2460
2471
|
constructor(t, e, s = 1) {
|
|
2461
|
-
this.storage = new
|
|
2472
|
+
this.storage = new ht(t, e), this.idGen = new dt(s);
|
|
2462
2473
|
}
|
|
2463
2474
|
/** Generate a new unique ID (returns raw bigint). */
|
|
2464
2475
|
generateId(t = "book", e = "draft") {
|
|
@@ -2544,7 +2555,7 @@ class re {
|
|
|
2544
2555
|
return this.storage;
|
|
2545
2556
|
}
|
|
2546
2557
|
}
|
|
2547
|
-
const
|
|
2558
|
+
const Ht = {
|
|
2548
2559
|
wikisource: "wikisource",
|
|
2549
2560
|
shidianguji: "shidianguji",
|
|
2550
2561
|
archive: "archive",
|
|
@@ -2554,16 +2565,16 @@ const Nt = {
|
|
|
2554
2565
|
"db.sido": "sido",
|
|
2555
2566
|
"guji.artx": "guji-artx",
|
|
2556
2567
|
"digital.library": "digital-library"
|
|
2557
|
-
},
|
|
2558
|
-
function
|
|
2568
|
+
}, tt = /* @__PURE__ */ new Set(["text", "image", "physical", "catalog", "annotated"]), Gt = /* @__PURE__ */ new Set(["catalog", "search"]), qt = /* @__PURE__ */ new Set(["com", "org", "net", "cn", "edu", "gov", "io", "jp", "tw", "hk"]);
|
|
2569
|
+
function he(i) {
|
|
2559
2570
|
if (!i) return "";
|
|
2560
2571
|
try {
|
|
2561
2572
|
const e = new URL(i).hostname;
|
|
2562
|
-
for (const [n, o] of Object.entries(
|
|
2573
|
+
for (const [n, o] of Object.entries(Ht))
|
|
2563
2574
|
if (e.includes(n)) return o;
|
|
2564
2575
|
const s = e.split(".");
|
|
2565
2576
|
if (s.length >= 2) {
|
|
2566
|
-
const n = s.filter((o) => !
|
|
2577
|
+
const n = s.filter((o) => !qt.has(o) && o.length > 2);
|
|
2567
2578
|
return n.length > 0 ? n[n.length - 1] : s[s.length - 2];
|
|
2568
2579
|
}
|
|
2569
2580
|
return e;
|
|
@@ -2571,7 +2582,7 @@ function ae(i) {
|
|
|
2571
2582
|
return "";
|
|
2572
2583
|
}
|
|
2573
2584
|
}
|
|
2574
|
-
function
|
|
2585
|
+
function ue(i) {
|
|
2575
2586
|
const t = [];
|
|
2576
2587
|
i.name || t.push("name is required");
|
|
2577
2588
|
let e = !1;
|
|
@@ -2580,12 +2591,12 @@ function ce(i) {
|
|
|
2580
2591
|
t.push("types must be a non-empty array when present");
|
|
2581
2592
|
else {
|
|
2582
2593
|
for (const s of i.types)
|
|
2583
|
-
|
|
2594
|
+
tt.has(s) || t.push(`invalid types atom '${s}', must be one of ${[...tt].join(", ")}`);
|
|
2584
2595
|
e = i.types.length === 1 && i.types[0] === "physical";
|
|
2585
2596
|
}
|
|
2586
2597
|
else
|
|
2587
2598
|
t.push("types is required");
|
|
2588
|
-
return i.root_type && !
|
|
2599
|
+
return i.root_type && !Gt.has(i.root_type) && t.push(`invalid root_type '${i.root_type}'`), !e && !i.url && t.push("url is required for non-physical resources"), t;
|
|
2589
2600
|
}
|
|
2590
2601
|
const p = class p {
|
|
2591
2602
|
constructor(t, e = "") {
|
|
@@ -2630,44 +2641,45 @@ const p = class p {
|
|
|
2630
2641
|
}
|
|
2631
2642
|
};
|
|
2632
2643
|
p.PROTOCOL = "bid:\\\\", p.PREFIX = "bid:\\\\";
|
|
2633
|
-
let
|
|
2644
|
+
let et = p;
|
|
2634
2645
|
export {
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2646
|
+
ut as A,
|
|
2647
|
+
et as B,
|
|
2648
|
+
ae as C,
|
|
2649
|
+
k as D,
|
|
2650
|
+
P as E,
|
|
2651
|
+
_ as F,
|
|
2652
|
+
Xt as G,
|
|
2653
|
+
ue as H,
|
|
2654
|
+
re as I,
|
|
2655
|
+
Qt as L,
|
|
2656
|
+
ce as M,
|
|
2657
|
+
ie as S,
|
|
2658
|
+
Ft as V,
|
|
2659
|
+
Zt as a,
|
|
2660
|
+
kt as b,
|
|
2649
2661
|
v as c,
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2662
|
+
le as d,
|
|
2663
|
+
Vt as e,
|
|
2664
|
+
ht as f,
|
|
2665
|
+
oe as g,
|
|
2666
|
+
dt as h,
|
|
2655
2667
|
x as i,
|
|
2656
|
-
|
|
2668
|
+
ct as j,
|
|
2657
2669
|
A as k,
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2670
|
+
It as l,
|
|
2671
|
+
se as m,
|
|
2672
|
+
Lt as n,
|
|
2673
|
+
z as o,
|
|
2674
|
+
ne as p,
|
|
2663
2675
|
F as q,
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2676
|
+
At as r,
|
|
2677
|
+
L as s,
|
|
2678
|
+
ee as t,
|
|
2679
|
+
Yt as u,
|
|
2680
|
+
E as v,
|
|
2681
|
+
Kt as w,
|
|
2682
|
+
he as x,
|
|
2683
|
+
te as y,
|
|
2684
|
+
Z as z
|
|
2673
2685
|
};
|