@blocklet/pages-kit-inner-components 0.7.11 → 0.7.12
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/lib/cjs/chunks/site-state-Cffe1l1P.js +1 -0
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/chunks/{site-state-BR3S4pMJ.js → site-state-BfM2FqNf.js} +513 -535
- package/lib/es/resources.js +1 -1
- package/lib/es/site-state.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/chunks/site-state-DlfM55ST.js +0 -1
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { getYjsValue as
|
|
1
|
+
import { d as ze, l as p, m as it, b as ct, I as lt, c as pt } from "./components-D4ywfyMi.js";
|
|
2
|
+
import { getYjsValue as W, syncedStore as ut } from "@syncedstore/core";
|
|
3
3
|
import * as F from "yjs";
|
|
4
|
-
import { setPageDataSource as
|
|
5
|
-
import { getRouteMetaDataByOptionIds as
|
|
4
|
+
import { setPageDataSource as dt } from "@blocklet/pages-kit/utils/data-source";
|
|
5
|
+
import { getRouteMetaDataByOptionIds as ft, generateParamCombinations as be } from "@blocklet/pages-kit/utils/route";
|
|
6
6
|
import Ae from "lodash/cloneDeep";
|
|
7
|
-
import { DataTypes as P, Sequelize as
|
|
7
|
+
import { DataTypes as P, Sequelize as mt, Model as Ee, Op as Z } from "sequelize";
|
|
8
8
|
import "sqlite3";
|
|
9
9
|
import E from "@blocklet/sdk/lib/config";
|
|
10
|
-
import { withoutTrailingSlash as
|
|
11
|
-
import { union as
|
|
12
|
-
import
|
|
13
|
-
import z, { mkdtempSync as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { Worker as
|
|
17
|
-
import { nextId as
|
|
18
|
-
import { unzipSection as
|
|
19
|
-
import { getComponentDependencies as
|
|
20
|
-
import { getComponentWebEndpoint as
|
|
21
|
-
import { reactive as
|
|
22
|
-
import { rename as
|
|
23
|
-
import { globSync as
|
|
10
|
+
import { withoutTrailingSlash as je, withLeadingSlash as qe, joinURL as x } from "ufo";
|
|
11
|
+
import { union as gt, debounce as ht } from "lodash";
|
|
12
|
+
import "crypto";
|
|
13
|
+
import z, { mkdtempSync as yt, existsSync as St, readFileSync as wt, createWriteStream as It } from "fs";
|
|
14
|
+
import Oe from "p-limit";
|
|
15
|
+
import Le, { join as A, basename as $, dirname as M } from "path";
|
|
16
|
+
import { Worker as Pt } from "worker_threads";
|
|
17
|
+
import { nextId as $e } from "@blocklet/pages-kit/utils/common";
|
|
18
|
+
import { unzipSection as bt } from "@blocklet/pages-kit/utils/page-model";
|
|
19
|
+
import { getComponentDependencies as At } from "@blocklet/pages-kit/utils/property";
|
|
20
|
+
import { getComponentWebEndpoint as Et, getResources as jt, call as Ot } from "@blocklet/sdk/lib/component";
|
|
21
|
+
import { reactive as Rt } from "@reactivedata/reactive";
|
|
22
|
+
import { rename as Ue, mkdir as B, rm as We, writeFile as re, lstat as oe, readFile as te, copyFile as Ct, readdir as Dt } from "fs/promises";
|
|
23
|
+
import { globSync as vt, glob as ye } from "glob";
|
|
24
24
|
import * as fe from "lib0/decoding";
|
|
25
|
-
import * as
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import { LRUCache as
|
|
32
|
-
import { pipeline as
|
|
33
|
-
import { x as
|
|
34
|
-
import
|
|
35
|
-
import { Awareness as
|
|
36
|
-
import { writeUpdate as
|
|
25
|
+
import * as k from "lib0/encoding";
|
|
26
|
+
import Re from "lodash/debounce";
|
|
27
|
+
import Ce from "lodash/get";
|
|
28
|
+
import De from "lodash/isEmpty";
|
|
29
|
+
import Ne from "lodash/set";
|
|
30
|
+
import kt from "lodash/union";
|
|
31
|
+
import { LRUCache as Je } from "lru-cache";
|
|
32
|
+
import { pipeline as Tt } from "stream/promises";
|
|
33
|
+
import { x as Lt } from "tar";
|
|
34
|
+
import $t from "wait-on";
|
|
35
|
+
import { Awareness as Ut, encodeAwarenessUpdate as Me, removeAwarenessStates as Nt, applyAwarenessUpdate as Mt } from "y-protocols/awareness";
|
|
36
|
+
import { writeUpdate as _t, writeSyncStep1 as Ft, readSyncMessage as xt } from "y-protocols/sync";
|
|
37
37
|
import * as q from "yaml";
|
|
38
|
-
import { m as
|
|
38
|
+
import { m as _e } from "./html-CNFwwbdj.js";
|
|
39
39
|
import "@blocklet/pages-kit/types/state";
|
|
40
|
-
const
|
|
41
|
-
P.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) :
|
|
42
|
-
const _ = new
|
|
40
|
+
const Bt = P.sqlite.DATE.parse;
|
|
41
|
+
P.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Bt(t, e);
|
|
42
|
+
const _ = new mt({
|
|
43
43
|
dialect: "sqlite",
|
|
44
|
-
storage:
|
|
44
|
+
storage: ze,
|
|
45
45
|
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
46
46
|
retry: {
|
|
47
47
|
match: [/SQLITE_BUSY/],
|
|
@@ -62,7 +62,7 @@ process.on("SIGINT", async () => {
|
|
|
62
62
|
process.on("SIGTERM", async () => {
|
|
63
63
|
await _.close(), process.exit(0);
|
|
64
64
|
});
|
|
65
|
-
async function
|
|
65
|
+
async function Gt(t, e) {
|
|
66
66
|
try {
|
|
67
67
|
if (t.getDialect() !== "sqlite")
|
|
68
68
|
return;
|
|
@@ -80,16 +80,16 @@ let Se = null;
|
|
|
80
80
|
Se && clearInterval(Se);
|
|
81
81
|
Se = setInterval(
|
|
82
82
|
async () => {
|
|
83
|
-
p.info("Start cleanupSqliteMemory"), await
|
|
83
|
+
p.info("Start cleanupSqliteMemory"), await Gt(_, ze), p.info("End cleanupSqliteMemory");
|
|
84
84
|
},
|
|
85
85
|
60 * 1e3 * 10
|
|
86
86
|
// 10 minutes
|
|
87
87
|
);
|
|
88
|
-
const
|
|
89
|
-
class
|
|
88
|
+
const Vt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Fe = "page", we = "trigger-reload-project-resource", Ke = Vt, zt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", qt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
|
|
89
|
+
class ve extends Ee {
|
|
90
90
|
// Foreign key to Component
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
ve.init(
|
|
93
93
|
{
|
|
94
94
|
id: {
|
|
95
95
|
type: P.UUID,
|
|
@@ -108,22 +108,22 @@ De.init(
|
|
|
108
108
|
},
|
|
109
109
|
{ sequelize: _, tableName: "ProjectComponents", timestamps: !1 }
|
|
110
110
|
);
|
|
111
|
-
const Wt = "SLUG_INVALID",
|
|
111
|
+
const Wt = "SLUG_INVALID", K = (t) => ({
|
|
112
112
|
error: "slugInvalid",
|
|
113
113
|
code: Wt,
|
|
114
114
|
field: "slug",
|
|
115
115
|
message: t
|
|
116
|
-
}),
|
|
116
|
+
}), Jt = {
|
|
117
117
|
error: "slugRequired",
|
|
118
118
|
code: "SLUG_REQUIRED",
|
|
119
119
|
field: "slug",
|
|
120
120
|
message: () => "Project slug is required"
|
|
121
|
-
},
|
|
121
|
+
}, Kt = {
|
|
122
122
|
error: "slugAlreadyExists",
|
|
123
123
|
code: "SLUG_EXISTS",
|
|
124
124
|
field: "slug",
|
|
125
125
|
message: (t) => `Project slug "${t}" already exists`
|
|
126
|
-
},
|
|
126
|
+
}, Ht = [
|
|
127
127
|
/\.\./,
|
|
128
128
|
// Directory traversal
|
|
129
129
|
/<[^>]*>/,
|
|
@@ -139,12 +139,12 @@ const Wt = "SLUG_INVALID", W = (t) => ({
|
|
|
139
139
|
// Control characters
|
|
140
140
|
/[^a-zA-Z0-9-_@/\\:]/
|
|
141
141
|
// Only allow specific characters
|
|
142
|
-
],
|
|
142
|
+
], xe = (t) => {
|
|
143
143
|
if (!t) return "";
|
|
144
144
|
if (t === "/") return "/";
|
|
145
|
-
const e =
|
|
146
|
-
return
|
|
147
|
-
},
|
|
145
|
+
const e = je(t);
|
|
146
|
+
return qe(e) || "/";
|
|
147
|
+
}, Yt = (t) => t.did === qt;
|
|
148
148
|
class U extends Ee {
|
|
149
149
|
static async getProjectByIdOrSlug(e, s) {
|
|
150
150
|
return e ? U.findOne({
|
|
@@ -161,22 +161,22 @@ class U extends Ee {
|
|
|
161
161
|
if (e == null)
|
|
162
162
|
return null;
|
|
163
163
|
if (e === "")
|
|
164
|
-
return
|
|
165
|
-
const a = e === "/" ? "/" :
|
|
164
|
+
return Jt;
|
|
165
|
+
const a = e === "/" ? "/" : je(qe(e)), o = xe(a);
|
|
166
166
|
if (a !== "/" && a.endsWith("/"))
|
|
167
|
-
return
|
|
167
|
+
return K((n) => `Project slug "${n}" cannot end with /`);
|
|
168
168
|
if (/\/{2,}/.test(a))
|
|
169
|
-
return
|
|
169
|
+
return K((n) => `Project slug "${n}" cannot contain consecutive /`);
|
|
170
170
|
if (/\s/.test(a))
|
|
171
|
-
return
|
|
172
|
-
if (
|
|
173
|
-
return
|
|
174
|
-
if (E.components?.filter((n) => n.mountPoint && !
|
|
175
|
-
return
|
|
171
|
+
return K((n) => `Project slug "${n}" cannot contain whitespace`);
|
|
172
|
+
if (Ht.some((n) => n.test(a)))
|
|
173
|
+
return K((n) => `Project slug "${n}" contains invalid characters`);
|
|
174
|
+
if (E.components?.filter((n) => n.mountPoint && !Yt(n)).some((n) => xe(n.mountPoint) === o))
|
|
175
|
+
return K((n) => `Project slug "${n}" conflicts with existing blocklet`);
|
|
176
176
|
const l = await U.findOne({
|
|
177
177
|
where: { slug: a }
|
|
178
178
|
});
|
|
179
|
-
return l && l?.id !== s ?
|
|
179
|
+
return l && l?.id !== s ? Kt : null;
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
U.init(
|
|
@@ -283,7 +283,7 @@ U.init(
|
|
|
283
283
|
]
|
|
284
284
|
}
|
|
285
285
|
);
|
|
286
|
-
U.hasMany(
|
|
286
|
+
U.hasMany(ve, {
|
|
287
287
|
foreignKey: "projectId",
|
|
288
288
|
as: "components"
|
|
289
289
|
});
|
|
@@ -294,22 +294,22 @@ async function G(t) {
|
|
|
294
294
|
return !1;
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function He(t, e) {
|
|
298
298
|
return new Promise((s, a) => {
|
|
299
299
|
const o = z.createReadStream(t), r = z.createWriteStream(e);
|
|
300
300
|
o.on("error", a), r.on("error", a), r.on("finish", s), o.pipe(r);
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
-
async function
|
|
303
|
+
async function Ye(t, e) {
|
|
304
304
|
await z.promises.mkdir(e, { recursive: !0 });
|
|
305
305
|
const s = await z.promises.readdir(t, { withFileTypes: !0 });
|
|
306
306
|
for (const a of s) {
|
|
307
|
-
const o =
|
|
308
|
-
a.isDirectory() ? await
|
|
307
|
+
const o = Le.join(t, a.name), r = Le.join(e, a.name);
|
|
308
|
+
a.isDirectory() ? await Ye(o, r) : await He(o, r);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
async function
|
|
312
|
-
(await z.promises.stat(t)).isDirectory() ? await
|
|
311
|
+
async function sa(t, e) {
|
|
312
|
+
(await z.promises.stat(t)).isDirectory() ? await Ye(t, e) : await He(t, e);
|
|
313
313
|
}
|
|
314
314
|
class ee extends Ee {
|
|
315
315
|
}
|
|
@@ -411,44 +411,44 @@ ee.init(
|
|
|
411
411
|
]
|
|
412
412
|
}
|
|
413
413
|
);
|
|
414
|
-
function
|
|
415
|
-
const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r =
|
|
414
|
+
function Xt(t) {
|
|
415
|
+
const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r = gt(
|
|
416
416
|
E.env.languages?.map((c) => c.code) || [],
|
|
417
417
|
a.supportedLocales?.map((c) => c.locale) || []
|
|
418
|
-
), l = {}, n = (c,
|
|
418
|
+
), l = {}, n = (c, h) => {
|
|
419
419
|
o && (l[x("/", o, c)] = {
|
|
420
|
-
...
|
|
420
|
+
...h,
|
|
421
421
|
shouldRedirect: !0,
|
|
422
422
|
mainPage: !0
|
|
423
423
|
}), l[x("/", e, c)] = {
|
|
424
|
-
...
|
|
424
|
+
...h,
|
|
425
425
|
shouldRedirect: !0,
|
|
426
426
|
mainPage: !0
|
|
427
427
|
};
|
|
428
428
|
for (const b of r) {
|
|
429
|
-
const
|
|
430
|
-
l[x("/", b, e, c)] =
|
|
429
|
+
const O = { ...h, locale: b };
|
|
430
|
+
l[x("/", b, e, c)] = O, o && (l[x("/", b, o, c)] = O);
|
|
431
431
|
}
|
|
432
432
|
};
|
|
433
433
|
for (const c of a.pageIds || []) {
|
|
434
|
-
const
|
|
435
|
-
if (!
|
|
434
|
+
const h = a.pages?.[c];
|
|
435
|
+
if (!h || !h.isPublic)
|
|
436
436
|
continue;
|
|
437
437
|
const b = {
|
|
438
438
|
projectId: e,
|
|
439
439
|
projectSlug: o,
|
|
440
|
-
pageSlug:
|
|
440
|
+
pageSlug: h.slug,
|
|
441
441
|
pageId: c,
|
|
442
442
|
defaultLocale: r?.[0],
|
|
443
443
|
locales: r,
|
|
444
444
|
publishedAt: a.config?.publishedAt,
|
|
445
|
-
isPublic:
|
|
445
|
+
isPublic: h.isPublic
|
|
446
446
|
};
|
|
447
|
-
n(
|
|
447
|
+
n(h.slug, b);
|
|
448
448
|
}
|
|
449
449
|
return l;
|
|
450
450
|
}
|
|
451
|
-
async function
|
|
451
|
+
async function Qt(t, e, s) {
|
|
452
452
|
const a = t.map((r) => r.urlPath), o = await ee.findAll({
|
|
453
453
|
where: {
|
|
454
454
|
urlPath: {
|
|
@@ -480,14 +480,14 @@ async function es(t, e, s) {
|
|
|
480
480
|
);
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
|
-
async function
|
|
483
|
+
async function Zt(t) {
|
|
484
484
|
const { projectId: e, transaction: s } = t;
|
|
485
485
|
try {
|
|
486
486
|
await ee.destroy({
|
|
487
487
|
where: { projectId: e },
|
|
488
488
|
transaction: s
|
|
489
489
|
});
|
|
490
|
-
const a =
|
|
490
|
+
const a = Xt(t), o = Object.entries(a).map(([r, l]) => ({
|
|
491
491
|
projectId: e,
|
|
492
492
|
urlPath: r,
|
|
493
493
|
projectSlug: l.projectSlug,
|
|
@@ -503,7 +503,7 @@ async function ts(t) {
|
|
|
503
503
|
locales: l.locales
|
|
504
504
|
}));
|
|
505
505
|
if (o.length > 0) {
|
|
506
|
-
await
|
|
506
|
+
await Qt(o, e, s);
|
|
507
507
|
const r = 100, l = [];
|
|
508
508
|
for (let n = 0; n < o.length; n += r) {
|
|
509
509
|
const c = o.slice(n, n + r);
|
|
@@ -527,8 +527,8 @@ function ne(t) {
|
|
|
527
527
|
e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
528
528
|
});
|
|
529
529
|
}
|
|
530
|
-
function
|
|
531
|
-
return
|
|
530
|
+
function Xe() {
|
|
531
|
+
return yt(A(E.env.dataDir, "tmp-"));
|
|
532
532
|
}
|
|
533
533
|
function ie(t, e, s = []) {
|
|
534
534
|
return Array.isArray(t) ? t.flatMap((a, o) => ie(a, e, [...s, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([a, o]) => ie(o, e, [...s, a])) : e(t) ? [s] : [];
|
|
@@ -536,11 +536,11 @@ function ie(t, e, s = []) {
|
|
|
536
536
|
function L(t) {
|
|
537
537
|
return t.filter((e) => e != null);
|
|
538
538
|
}
|
|
539
|
-
function
|
|
539
|
+
function es(t) {
|
|
540
540
|
return new Promise((e, s) => {
|
|
541
541
|
let a;
|
|
542
542
|
process.env.NODE_ENV === "development" ? a = A(__dirname, "yaml-worker.js") : a = A(__dirname, "api/dist/utils/yaml-worker.js");
|
|
543
|
-
const o = new
|
|
543
|
+
const o = new Pt(a);
|
|
544
544
|
o.postMessage({ payload: t }), o.on("message", (r) => {
|
|
545
545
|
r.status === "success" ? e(r.result) : s(new Error(`YAML stringify failed in worker: ${r.message}`)), o.terminate();
|
|
546
546
|
}), o.on("error", (r) => {
|
|
@@ -550,54 +550,37 @@ function ss(t) {
|
|
|
550
550
|
});
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
function
|
|
554
|
-
if (t === e) return !0;
|
|
555
|
-
if (!t || !e) return t === e;
|
|
556
|
-
const s = Object.keys(t), a = Object.keys(e);
|
|
557
|
-
if (s.length !== a.length) return !1;
|
|
558
|
-
if (s.length < 10) {
|
|
559
|
-
for (const l of s) {
|
|
560
|
-
if (!(l in e)) return !1;
|
|
561
|
-
const n = t[l], c = e[l];
|
|
562
|
-
if (n?.blockletId !== c?.blockletId || n?.page?.id !== c?.page?.id || n?.page?.updatedAt !== c?.page?.updatedAt || n?.component?.id !== c?.component?.id || n?.component?.updatedAt !== c?.component?.updatedAt)
|
|
563
|
-
return !1;
|
|
564
|
-
}
|
|
565
|
-
return !0;
|
|
566
|
-
}
|
|
567
|
-
const o = Le.createHash("md5").update(JSON.stringify(t, Object.keys(t).sort())).digest("hex"), r = Le.createHash("md5").update(JSON.stringify(e, Object.keys(e).sort())).digest("hex");
|
|
568
|
-
return o === r;
|
|
569
|
-
}
|
|
570
|
-
function as(t) {
|
|
553
|
+
function ts(t) {
|
|
571
554
|
t.pages && Object.keys(t.pages).forEach((s) => {
|
|
572
|
-
const a =
|
|
555
|
+
const a = W(t.pages[s]);
|
|
573
556
|
a && a instanceof F.Map && ne(a);
|
|
574
557
|
});
|
|
575
|
-
const e =
|
|
558
|
+
const e = W(t.pages);
|
|
576
559
|
e && e instanceof F.Map && e.observe((s) => {
|
|
577
560
|
s.changes.keys.forEach((a, o) => {
|
|
578
561
|
if (a.action === "add") {
|
|
579
|
-
const r =
|
|
562
|
+
const r = W(t.pages[o]);
|
|
580
563
|
r && r instanceof F.Map && ne(r);
|
|
581
564
|
}
|
|
582
565
|
});
|
|
583
566
|
});
|
|
584
567
|
}
|
|
585
|
-
function
|
|
568
|
+
function ss(t) {
|
|
586
569
|
t.routes && Object.keys(t.routes).forEach((s) => {
|
|
587
|
-
const a =
|
|
570
|
+
const a = W(t.routes?.[s]);
|
|
588
571
|
a && a instanceof F.Map && ne(a);
|
|
589
572
|
});
|
|
590
|
-
const e =
|
|
573
|
+
const e = W(t.routes);
|
|
591
574
|
e && e instanceof F.Map && e.observe((s) => {
|
|
592
575
|
s.changes.keys.forEach((a, o) => {
|
|
593
576
|
if (a.action === "add") {
|
|
594
|
-
const r =
|
|
577
|
+
const r = W(t.routes?.[o]);
|
|
595
578
|
r && r instanceof F.Map && ne(r);
|
|
596
579
|
}
|
|
597
580
|
});
|
|
598
581
|
});
|
|
599
582
|
}
|
|
600
|
-
function
|
|
583
|
+
function as(t, e) {
|
|
601
584
|
for (const s of e || Object.keys(t.routes || {})) {
|
|
602
585
|
let a = s, o = [];
|
|
603
586
|
if (s.includes("-")) {
|
|
@@ -610,7 +593,7 @@ function rs(t, e) {
|
|
|
610
593
|
if (!r || !r.params || r.params.length === 0)
|
|
611
594
|
continue;
|
|
612
595
|
if (s.includes("-") && o.length > 0) {
|
|
613
|
-
const l =
|
|
596
|
+
const l = ft(o, r);
|
|
614
597
|
l && (l.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
615
598
|
}
|
|
616
599
|
if (!e) {
|
|
@@ -656,48 +639,48 @@ function me({
|
|
|
656
639
|
const c = e.dataSource.pathDataMappings?.[n]?.dataCache?.[l.locale] ?? e.dataSource.pathDataMappings?.[n]?.dataCache?.[s.config.defaultLocale || "en"];
|
|
657
640
|
if (!c)
|
|
658
641
|
continue;
|
|
659
|
-
|
|
642
|
+
dt(r, s, l.locale, c);
|
|
660
643
|
}
|
|
661
644
|
o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
662
645
|
}
|
|
663
646
|
return r;
|
|
664
647
|
}
|
|
665
648
|
["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
|
|
666
|
-
const
|
|
649
|
+
const os = 60 * 60 * 1e3, Y = new Je({
|
|
667
650
|
max: 300,
|
|
668
|
-
ttl:
|
|
651
|
+
ttl: os,
|
|
669
652
|
ttlResolution: 10 * 1e3,
|
|
670
653
|
// 10 seconds
|
|
671
654
|
allowStale: !0
|
|
672
655
|
});
|
|
673
|
-
function
|
|
656
|
+
function rs(t, e = []) {
|
|
674
657
|
let s = 0;
|
|
675
|
-
const a = Array.from(Y.keys()), o = t.map((r) =>
|
|
658
|
+
const a = Array.from(Y.keys()), o = t.map((r) => je(r));
|
|
676
659
|
for (const r of a)
|
|
677
660
|
for (const l of o) {
|
|
678
|
-
if (
|
|
661
|
+
if (_e(r, { currentPath: l })) {
|
|
679
662
|
Y.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
|
|
680
663
|
break;
|
|
681
664
|
}
|
|
682
665
|
for (const n of e)
|
|
683
|
-
if (
|
|
666
|
+
if (_e(r, { currentPath: `/${n}${l}` })) {
|
|
684
667
|
Y.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
|
|
685
668
|
break;
|
|
686
669
|
}
|
|
687
670
|
}
|
|
688
671
|
return p.info(`[Cache CLEAR] cleared ${s} entries for paths:`, o), s;
|
|
689
672
|
}
|
|
690
|
-
function
|
|
673
|
+
function ns() {
|
|
691
674
|
const t = Y.size;
|
|
692
675
|
return Y.clear(), p.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
|
|
693
676
|
}
|
|
694
|
-
const
|
|
695
|
-
E.events.on(E.Events.envUpdate,
|
|
696
|
-
const { uploadToMediaKit:
|
|
677
|
+
const is = ht(ns, 300);
|
|
678
|
+
E.events.on(E.Events.envUpdate, is);
|
|
679
|
+
const { uploadToMediaKit: cs } = require("@blocklet/uploader-server"), ke = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, X = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, Be = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, ls = 1e4, ps = 3e4, se = 0, ge = 1, us = 0, ds = 1, Ie = E, H = A(process.env.BLOCKLET_DATA_DIR, "site-state"), aa = ["production", "draft"], oa = ["production"];
|
|
697
680
|
function ce(t) {
|
|
698
681
|
return t?.replace(/\//g, "|") || "";
|
|
699
682
|
}
|
|
700
|
-
function
|
|
683
|
+
function fs() {
|
|
701
684
|
const t = Ie.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
|
|
702
685
|
return {
|
|
703
686
|
pageIds: [],
|
|
@@ -712,10 +695,10 @@ function gs() {
|
|
|
712
695
|
resources: {}
|
|
713
696
|
};
|
|
714
697
|
}
|
|
715
|
-
class
|
|
698
|
+
class D extends F.Doc {
|
|
716
699
|
constructor(e) {
|
|
717
|
-
super(), this.options = e,
|
|
718
|
-
|
|
700
|
+
super(), this.options = e, St(this.draftYjsFilePath) && F.applyUpdate(this, wt(this.draftYjsFilePath)), this.syncedStore = Rt(
|
|
701
|
+
ut(
|
|
719
702
|
{
|
|
720
703
|
pages: {},
|
|
721
704
|
pageIds: [],
|
|
@@ -730,7 +713,7 @@ class k extends F.Doc {
|
|
|
730
713
|
},
|
|
731
714
|
this
|
|
732
715
|
)
|
|
733
|
-
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new
|
|
716
|
+
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Ut(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
|
|
734
717
|
}
|
|
735
718
|
// 延迟释放时间:5 分钟
|
|
736
719
|
static RELEASE_DELAY = 5 * 60 * 1e3;
|
|
@@ -745,8 +728,8 @@ class k extends F.Doc {
|
|
|
745
728
|
if (!e)
|
|
746
729
|
throw new Error("Should provide project context");
|
|
747
730
|
try {
|
|
748
|
-
const s = A(
|
|
749
|
-
await
|
|
731
|
+
const s = A(H, e), a = A(H, `@del-${e}`);
|
|
732
|
+
await Ue(s, a);
|
|
750
733
|
} catch (s) {
|
|
751
734
|
p.error("Failed to safe delete project state dir:", s);
|
|
752
735
|
}
|
|
@@ -756,31 +739,31 @@ class k extends F.Doc {
|
|
|
756
739
|
}
|
|
757
740
|
/** @deprecated 不再使用这个 getter 了,仅作为兼容性处理,请使用 getProjectIds 代替 */
|
|
758
741
|
static get projectIds() {
|
|
759
|
-
return
|
|
760
|
-
cwd:
|
|
742
|
+
return vt("*/", {
|
|
743
|
+
cwd: H,
|
|
761
744
|
ignore: ["@del-*", "@tmp-*", ".*", "staging", "production", "@backup-*", "undefined"]
|
|
762
745
|
// Ignore temp directories and hidden files
|
|
763
746
|
});
|
|
764
747
|
}
|
|
765
748
|
/** @deprecated 不再使用这个 getter 了,仅作为兼容性处理 */
|
|
766
749
|
static get allShared() {
|
|
767
|
-
return this.projectIds.map((e) =>
|
|
750
|
+
return this.projectIds.map((e) => D.shared(e));
|
|
768
751
|
}
|
|
769
752
|
static shared(e) {
|
|
770
753
|
if (!e)
|
|
771
754
|
throw new Error("Should provide project context");
|
|
772
|
-
let s =
|
|
773
|
-
return s || (s = new
|
|
774
|
-
path: A(
|
|
775
|
-
}),
|
|
755
|
+
let s = D.sharedInstances[e];
|
|
756
|
+
return s || (s = new D({
|
|
757
|
+
path: A(H, e)
|
|
758
|
+
}), D.sharedInstances[e] = s, s);
|
|
776
759
|
}
|
|
777
760
|
// 轻量级 production 状态获取,不加载 draft 数据
|
|
778
761
|
static async getProductionState(e) {
|
|
779
762
|
const s = await U.findByPk(e, {
|
|
780
763
|
attributes: ["productionState"]
|
|
781
764
|
});
|
|
782
|
-
if (
|
|
783
|
-
const a = A(
|
|
765
|
+
if (De(s?.productionState)) {
|
|
766
|
+
const a = A(H, e, "production"), o = await Ze(a, { includeResources: !0 }) ?? fs();
|
|
784
767
|
if (!o?.config?.defaultLocale) {
|
|
785
768
|
o.config ??= {};
|
|
786
769
|
const r = Ie.env.languages?.map((l) => ({ locale: l.code, name: l.name })) || [];
|
|
@@ -793,10 +776,10 @@ class k extends F.Doc {
|
|
|
793
776
|
destroy() {
|
|
794
777
|
this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
|
|
795
778
|
const e = $(this.options.path);
|
|
796
|
-
delete
|
|
779
|
+
delete D.sharedInstances[e], super.destroy();
|
|
797
780
|
}
|
|
798
781
|
initObserver() {
|
|
799
|
-
|
|
782
|
+
ts(this.syncedStore), ss(this.syncedStore);
|
|
800
783
|
}
|
|
801
784
|
get draftYjsFilePath() {
|
|
802
785
|
return A(this.options.path, "draft.yjs");
|
|
@@ -807,16 +790,16 @@ class k extends F.Doc {
|
|
|
807
790
|
clone: a = !0
|
|
808
791
|
}) {
|
|
809
792
|
if (s === "draft") {
|
|
810
|
-
const o =
|
|
793
|
+
const o = D.shared(e);
|
|
811
794
|
return a ? JSON.parse(JSON.stringify(o.syncedStore)) : o.syncedStore;
|
|
812
795
|
}
|
|
813
|
-
return
|
|
796
|
+
return D.getProductionState(e);
|
|
814
797
|
}
|
|
815
798
|
async getState(e) {
|
|
816
799
|
if (e === "draft")
|
|
817
800
|
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
818
801
|
const s = $(this.options.path);
|
|
819
|
-
return
|
|
802
|
+
return D.getProductionState(s);
|
|
820
803
|
}
|
|
821
804
|
async setState(e, s) {
|
|
822
805
|
if (e === "production") {
|
|
@@ -826,17 +809,17 @@ class k extends F.Doc {
|
|
|
826
809
|
const c = await U.findByPk(r, {
|
|
827
810
|
attributes: ["slug"],
|
|
828
811
|
transaction: n
|
|
829
|
-
}),
|
|
812
|
+
}), h = await Zt({
|
|
830
813
|
projectId: r,
|
|
831
814
|
projectSlug: c?.slug,
|
|
832
815
|
state: s,
|
|
833
816
|
transaction: n
|
|
834
817
|
});
|
|
835
|
-
p.info(`[SiteState] saved ${
|
|
818
|
+
p.info(`[SiteState] saved ${h} URL mappings for project ${r}`);
|
|
836
819
|
}), await this.clearPageCacheForRoutes(void 0, s);
|
|
837
820
|
}
|
|
838
|
-
const a = await
|
|
839
|
-
await B(M(o), { recursive: !0 }), await We(o, { force: !0, recursive: !0 }), await
|
|
821
|
+
const a = await ys(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
|
|
822
|
+
await B(M(o), { recursive: !0 }), await We(o, { force: !0, recursive: !0 }), await Ue(a, o);
|
|
840
823
|
}
|
|
841
824
|
getPublishDir(e) {
|
|
842
825
|
return A(this.options.path, e);
|
|
@@ -850,21 +833,21 @@ class k extends F.Doc {
|
|
|
850
833
|
const r = e.concat(s, a);
|
|
851
834
|
if (o !== null) {
|
|
852
835
|
const c = this.conns.get(o);
|
|
853
|
-
c && (e.forEach((
|
|
854
|
-
c.add(
|
|
855
|
-
}), a.forEach((
|
|
856
|
-
c.delete(
|
|
836
|
+
c && (e.forEach((h) => {
|
|
837
|
+
c.add(h);
|
|
838
|
+
}), a.forEach((h) => {
|
|
839
|
+
c.delete(h);
|
|
857
840
|
}));
|
|
858
841
|
}
|
|
859
|
-
const l =
|
|
860
|
-
|
|
861
|
-
const n =
|
|
862
|
-
this.conns.forEach((c,
|
|
842
|
+
const l = k.createEncoder();
|
|
843
|
+
k.writeVarUint(l, ge), k.writeVarUint8Array(l, Me(this.awareness, r));
|
|
844
|
+
const n = k.toUint8Array(l);
|
|
845
|
+
this.conns.forEach((c, h) => this.send(h, n));
|
|
863
846
|
};
|
|
864
847
|
updateHandler = (e) => {
|
|
865
|
-
const s =
|
|
866
|
-
|
|
867
|
-
const a =
|
|
848
|
+
const s = k.createEncoder();
|
|
849
|
+
k.writeVarUint(s, se), _t(s, e);
|
|
850
|
+
const a = k.toUint8Array(s);
|
|
868
851
|
this.conns.forEach((o, r) => this.send(r, a));
|
|
869
852
|
};
|
|
870
853
|
ensureDataStructure = () => {
|
|
@@ -874,16 +857,16 @@ class k extends F.Doc {
|
|
|
874
857
|
const n = new Set(Object.keys(s));
|
|
875
858
|
let c = 0;
|
|
876
859
|
for (; c < a.length; ) {
|
|
877
|
-
const
|
|
878
|
-
n.has(
|
|
860
|
+
const h = a[c];
|
|
861
|
+
n.has(h) ? (n.delete(h), c++) : a.splice(c, 1);
|
|
879
862
|
}
|
|
880
863
|
}
|
|
881
864
|
{
|
|
882
865
|
const n = new Set(Object.keys(r));
|
|
883
866
|
let c = 0;
|
|
884
867
|
for (; c < l.length; ) {
|
|
885
|
-
const
|
|
886
|
-
n.has(
|
|
868
|
+
const h = l[c];
|
|
869
|
+
n.has(h) ? (n.delete(h), c++) : l.splice(c, 1);
|
|
887
870
|
}
|
|
888
871
|
}
|
|
889
872
|
e.splice(0, e.length), e.push(...Ie.env.languages.map((n) => ({ locale: n.code, name: n.name }))), o.defaultLocale = e[0]?.locale;
|
|
@@ -891,14 +874,14 @@ class k extends F.Doc {
|
|
|
891
874
|
let n = 0;
|
|
892
875
|
const c = /* @__PURE__ */ new Set();
|
|
893
876
|
for (; n < e.length; ) {
|
|
894
|
-
const { locale:
|
|
895
|
-
c.has(
|
|
877
|
+
const { locale: h } = e[n];
|
|
878
|
+
c.has(h) ? e.splice(n, 1) : (n++, c.add(h));
|
|
896
879
|
}
|
|
897
880
|
}
|
|
898
881
|
});
|
|
899
882
|
};
|
|
900
883
|
send = (e, s) => {
|
|
901
|
-
e.readyState !==
|
|
884
|
+
e.readyState !== us && e.readyState !== ds && this.closeConn(e);
|
|
902
885
|
try {
|
|
903
886
|
e.send(s, (a) => {
|
|
904
887
|
a && this.closeConn(e);
|
|
@@ -910,7 +893,7 @@ class k extends F.Doc {
|
|
|
910
893
|
closeConn = (e) => {
|
|
911
894
|
if (e.removeAllListeners(), this.conns.has(e)) {
|
|
912
895
|
const s = this.conns.get(e);
|
|
913
|
-
this.conns.delete(e), s &&
|
|
896
|
+
this.conns.delete(e), s && Nt(this.awareness, Array.from(s), null);
|
|
914
897
|
}
|
|
915
898
|
e.close(), this.checkAndScheduleRelease();
|
|
916
899
|
};
|
|
@@ -924,7 +907,7 @@ class k extends F.Doc {
|
|
|
924
907
|
const e = $(this.options.path);
|
|
925
908
|
this.releaseTimer = setTimeout(() => {
|
|
926
909
|
p.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
|
|
927
|
-
},
|
|
910
|
+
}, D.RELEASE_DELAY), p.info(`[SiteState] scheduled release for project ${e} in ${D.RELEASE_DELAY / 1e3}s`);
|
|
928
911
|
}
|
|
929
912
|
// 取消延迟释放
|
|
930
913
|
cancelRelease() {
|
|
@@ -934,19 +917,19 @@ class k extends F.Doc {
|
|
|
934
917
|
p.info(`[SiteState] cancelled scheduled release for project ${e}`);
|
|
935
918
|
}
|
|
936
919
|
}
|
|
937
|
-
autoSave =
|
|
920
|
+
autoSave = Re(async () => {
|
|
938
921
|
await B(M(this.draftYjsFilePath), { recursive: !0 }), await re(this.draftYjsFilePath, F.encodeStateAsUpdate(this));
|
|
939
|
-
},
|
|
922
|
+
}, ls);
|
|
940
923
|
save = ({ flush: e = !1 } = {}) => {
|
|
941
924
|
this.autoSave(), e && this.autoSave.flush();
|
|
942
925
|
};
|
|
943
926
|
publish = async ({ mode: e, routes: s }) => {
|
|
944
927
|
const a = $(this.options.path);
|
|
945
|
-
await
|
|
928
|
+
await Is(a);
|
|
946
929
|
const o = await this.getState("draft"), r = await this.getState("production");
|
|
947
|
-
await
|
|
930
|
+
await Ve(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), setImmediate(() => {
|
|
948
931
|
this.transact(() => {
|
|
949
|
-
|
|
932
|
+
as(this.syncedStore, s);
|
|
950
933
|
});
|
|
951
934
|
}), await this.setState(e, r);
|
|
952
935
|
};
|
|
@@ -957,7 +940,7 @@ class k extends F.Doc {
|
|
|
957
940
|
e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((l, n) => {
|
|
958
941
|
this.transact(async () => {
|
|
959
942
|
try {
|
|
960
|
-
const c = await
|
|
943
|
+
const c = await Ve(e, s);
|
|
961
944
|
l(c);
|
|
962
945
|
} catch (c) {
|
|
963
946
|
n(c);
|
|
@@ -969,14 +952,14 @@ class k extends F.Doc {
|
|
|
969
952
|
const a = $(this.options.path), r = (await U.findByPk(a))?.slug || a;
|
|
970
953
|
let l = e;
|
|
971
954
|
(!l || l.length === 0) && (l = s.pageIds ?? []), p.info(`[SiteState] clearing page cache for project ${a}, routes:`, l || []);
|
|
972
|
-
const n = s.supportedLocales.map((b) => b.locale), c = [],
|
|
973
|
-
for (const b of
|
|
974
|
-
const
|
|
975
|
-
r && r !== a && (r === "/" ? c.push(
|
|
955
|
+
const n = s.supportedLocales.map((b) => b.locale), c = [], h = l.filter((b) => s.pageIds?.includes(b));
|
|
956
|
+
for (const b of h) {
|
|
957
|
+
const w = s.pages[b].slug;
|
|
958
|
+
r && r !== a && (r === "/" ? c.push(w) : c.push(`${r.startsWith("/") ? "" : "/"}${r}${w}`)), c.push(`/${a}${w}`);
|
|
976
959
|
}
|
|
977
960
|
if (c.length > 0)
|
|
978
961
|
try {
|
|
979
|
-
const b =
|
|
962
|
+
const b = rs(c, n);
|
|
980
963
|
p.info(`[SiteState] cleared ${b} page cache entries for project ${a}, routes:`, l);
|
|
981
964
|
} catch {
|
|
982
965
|
}
|
|
@@ -997,31 +980,31 @@ class k extends F.Doc {
|
|
|
997
980
|
this.closeConn(e), clearInterval(a);
|
|
998
981
|
}
|
|
999
982
|
}
|
|
1000
|
-
},
|
|
983
|
+
}, ps);
|
|
1001
984
|
e.on("close", () => {
|
|
1002
985
|
this.closeConn(e), clearInterval(a);
|
|
1003
986
|
}), e.on("pong", () => {
|
|
1004
987
|
s = !0;
|
|
1005
988
|
});
|
|
1006
989
|
{
|
|
1007
|
-
const o =
|
|
1008
|
-
|
|
990
|
+
const o = k.createEncoder();
|
|
991
|
+
k.writeVarUint(o, se), Ft(o, this), this.send(e, k.toUint8Array(o));
|
|
1009
992
|
const r = this.awareness.getStates();
|
|
1010
993
|
if (r.size > 0) {
|
|
1011
|
-
const l =
|
|
1012
|
-
|
|
994
|
+
const l = k.createEncoder();
|
|
995
|
+
k.writeVarUint(l, ge), k.writeVarUint8Array(l, Me(this.awareness, Array.from(r.keys()))), this.send(e, k.toUint8Array(l));
|
|
1013
996
|
}
|
|
1014
997
|
}
|
|
1015
998
|
};
|
|
1016
999
|
messageListener = (e, s) => {
|
|
1017
1000
|
try {
|
|
1018
|
-
const a =
|
|
1001
|
+
const a = k.createEncoder(), o = fe.createDecoder(s), r = fe.readVarUint(o);
|
|
1019
1002
|
switch (p.info(`[SiteState] messageListener, messageType: ${r}`), r) {
|
|
1020
1003
|
case se:
|
|
1021
|
-
|
|
1004
|
+
k.writeVarUint(a, se), xt(o, a, this, null), p.info(`[SiteState] messageListener, encoder length: ${k.length(a)}`), k.length(a) > 1 && (this.ensureDataStructure(), this.send(e, k.toUint8Array(a)));
|
|
1022
1005
|
break;
|
|
1023
1006
|
case ge: {
|
|
1024
|
-
|
|
1007
|
+
Mt(this.awareness, fe.readVarUint8Array(o), e);
|
|
1025
1008
|
break;
|
|
1026
1009
|
}
|
|
1027
1010
|
default:
|
|
@@ -1061,11 +1044,11 @@ class k extends F.Doc {
|
|
|
1061
1044
|
let o = {};
|
|
1062
1045
|
if (a?.length) {
|
|
1063
1046
|
p.info("[SiteState] find project infos from database, projectIds: ", a);
|
|
1064
|
-
const r = 30, l =
|
|
1047
|
+
const r = 30, l = Oe(5);
|
|
1065
1048
|
for (let n = 0; n < a.length; n += r) {
|
|
1066
1049
|
const c = a.slice(n, n + r);
|
|
1067
1050
|
p.info(`[SiteState] processing project batch ${n / r + 1}, ids: `, c);
|
|
1068
|
-
const
|
|
1051
|
+
const h = await U.findAll({
|
|
1069
1052
|
where: {
|
|
1070
1053
|
id: {
|
|
1071
1054
|
[Z.in]: c
|
|
@@ -1076,89 +1059,89 @@ class k extends F.Doc {
|
|
|
1076
1059
|
}
|
|
1077
1060
|
});
|
|
1078
1061
|
await Promise.all(
|
|
1079
|
-
|
|
1062
|
+
h?.map(
|
|
1080
1063
|
(b) => l(async () => {
|
|
1081
|
-
const
|
|
1082
|
-
E.env.languages?.map((
|
|
1083
|
-
u.supportedLocales?.map((
|
|
1084
|
-
),
|
|
1085
|
-
|
|
1086
|
-
...
|
|
1064
|
+
const O = b.id, w = b.slug || O, m = {}, u = await D.getStateByProjectId({ projectId: b.id, mode: e, clone: !1 }), I = kt(
|
|
1065
|
+
E.env.languages?.map((j) => j.code) || [],
|
|
1066
|
+
u.supportedLocales?.map((j) => j.locale) || []
|
|
1067
|
+
), R = (j, S) => {
|
|
1068
|
+
w && (m[x("/", w, j)] = {
|
|
1069
|
+
...S,
|
|
1087
1070
|
shouldRedirect: !0,
|
|
1088
1071
|
mainPage: !0
|
|
1089
|
-
}),
|
|
1090
|
-
...
|
|
1072
|
+
}), m[x("/", O, j)] = {
|
|
1073
|
+
...S,
|
|
1091
1074
|
shouldRedirect: !0,
|
|
1092
1075
|
mainPage: !0
|
|
1093
1076
|
};
|
|
1094
|
-
for (const
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1077
|
+
for (const v of I) {
|
|
1078
|
+
const g = { ...S, locale: v };
|
|
1079
|
+
m[x("/", v, O, j)] = g, w && (m[x("/", v, w, j)] = g);
|
|
1097
1080
|
}
|
|
1098
1081
|
};
|
|
1099
1082
|
if (e === "draft")
|
|
1100
|
-
for (const
|
|
1101
|
-
const
|
|
1102
|
-
if (!
|
|
1103
|
-
if (
|
|
1104
|
-
const
|
|
1105
|
-
basePath:
|
|
1106
|
-
params:
|
|
1107
|
-
routeId:
|
|
1108
|
-
paramsOptions:
|
|
1083
|
+
for (const j of u.routeIds || []) {
|
|
1084
|
+
const S = u?.routes?.[j];
|
|
1085
|
+
if (!S) continue;
|
|
1086
|
+
if (S.params && S.params.length > 0) {
|
|
1087
|
+
const y = be({
|
|
1088
|
+
basePath: S.path,
|
|
1089
|
+
params: S.params,
|
|
1090
|
+
routeId: S.id,
|
|
1091
|
+
paramsOptions: S.paramsOptions,
|
|
1109
1092
|
currentIndex: 0,
|
|
1110
1093
|
currentParams: [],
|
|
1111
1094
|
currentOptionIds: [],
|
|
1112
1095
|
result: []
|
|
1113
1096
|
});
|
|
1114
|
-
for (const i of
|
|
1115
|
-
const d = i.path,
|
|
1116
|
-
projectId:
|
|
1117
|
-
projectSlug:
|
|
1097
|
+
for (const i of y) {
|
|
1098
|
+
const d = i.path, f = {
|
|
1099
|
+
projectId: O,
|
|
1100
|
+
projectSlug: w,
|
|
1118
1101
|
pageSlug: d,
|
|
1119
|
-
pageId:
|
|
1120
|
-
routeId:
|
|
1102
|
+
pageId: S.displayTemplateId || "",
|
|
1103
|
+
routeId: j,
|
|
1121
1104
|
// default locale
|
|
1122
1105
|
defaultLocale: I?.[0],
|
|
1123
1106
|
locales: I,
|
|
1124
1107
|
publishedAt: u.config.publishedAt,
|
|
1125
|
-
isPublic:
|
|
1108
|
+
isPublic: S.isPublic && i?.routeMetaData?.isPublic
|
|
1126
1109
|
};
|
|
1127
|
-
|
|
1110
|
+
R(d, f);
|
|
1128
1111
|
}
|
|
1129
1112
|
}
|
|
1130
|
-
const
|
|
1131
|
-
projectId:
|
|
1132
|
-
projectSlug:
|
|
1133
|
-
pageSlug:
|
|
1134
|
-
pageId:
|
|
1135
|
-
routeId:
|
|
1113
|
+
const v = S.path, g = {
|
|
1114
|
+
projectId: O,
|
|
1115
|
+
projectSlug: w,
|
|
1116
|
+
pageSlug: v,
|
|
1117
|
+
pageId: S.displayTemplateId || "",
|
|
1118
|
+
routeId: j,
|
|
1136
1119
|
// default locale
|
|
1137
1120
|
defaultLocale: I?.[0],
|
|
1138
1121
|
locales: I,
|
|
1139
1122
|
publishedAt: u.config.publishedAt,
|
|
1140
|
-
isPublic:
|
|
1123
|
+
isPublic: S.isPublic
|
|
1141
1124
|
};
|
|
1142
|
-
|
|
1125
|
+
R(v, g);
|
|
1143
1126
|
}
|
|
1144
|
-
for (const
|
|
1145
|
-
const
|
|
1146
|
-
if (!
|
|
1147
|
-
const
|
|
1148
|
-
projectId:
|
|
1149
|
-
projectSlug:
|
|
1150
|
-
pageSlug:
|
|
1151
|
-
pageId:
|
|
1127
|
+
for (const j of u.pageIds || []) {
|
|
1128
|
+
const S = u.pages[j];
|
|
1129
|
+
if (!S) continue;
|
|
1130
|
+
const v = S.slug, g = b.slug || O, y = {
|
|
1131
|
+
projectId: O,
|
|
1132
|
+
projectSlug: g,
|
|
1133
|
+
pageSlug: v,
|
|
1134
|
+
pageId: j,
|
|
1152
1135
|
// default locale
|
|
1153
1136
|
defaultLocale: I?.[0],
|
|
1154
1137
|
locales: I,
|
|
1155
1138
|
publishedAt: u.config.publishedAt,
|
|
1156
|
-
isPublic:
|
|
1157
|
-
templateConfig:
|
|
1139
|
+
isPublic: S.isPublic,
|
|
1140
|
+
templateConfig: S.templateConfig
|
|
1158
1141
|
};
|
|
1159
|
-
|
|
1142
|
+
R(v, y);
|
|
1160
1143
|
}
|
|
1161
|
-
o = { ...o, ...
|
|
1144
|
+
o = { ...o, ...m };
|
|
1162
1145
|
})
|
|
1163
1146
|
)
|
|
1164
1147
|
);
|
|
@@ -1171,7 +1154,7 @@ class k extends F.Doc {
|
|
|
1171
1154
|
}
|
|
1172
1155
|
static getInstancesSizeInfo() {
|
|
1173
1156
|
const e = [];
|
|
1174
|
-
for (const [s, a] of Object.entries(
|
|
1157
|
+
for (const [s, a] of Object.entries(D.sharedInstances)) {
|
|
1175
1158
|
const o = a.getDocumentSize();
|
|
1176
1159
|
e.push({
|
|
1177
1160
|
projectId: s,
|
|
@@ -1196,8 +1179,8 @@ class k extends F.Doc {
|
|
|
1196
1179
|
}
|
|
1197
1180
|
// 执行定期检查
|
|
1198
1181
|
static performPeriodicCheck() {
|
|
1199
|
-
const e = Object.keys(
|
|
1200
|
-
for (const [o, r] of Object.entries(
|
|
1182
|
+
const e = Object.keys(D.sharedInstances).length, s = [], a = [];
|
|
1183
|
+
for (const [o, r] of Object.entries(D.sharedInstances))
|
|
1201
1184
|
r.conns.size === 0 ? s.push({ projectId: o, instance: r }) : a.push({ projectId: o, connections: r.conns.size });
|
|
1202
1185
|
if (p.info(
|
|
1203
1186
|
`[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
|
|
@@ -1219,13 +1202,13 @@ class k extends F.Doc {
|
|
|
1219
1202
|
} else e > 0 ? p.debug("[SiteState] periodic check: all instances have active connections") : p.debug("[SiteState] periodic check: no instances exist");
|
|
1220
1203
|
}
|
|
1221
1204
|
}
|
|
1222
|
-
async function
|
|
1205
|
+
async function ms(t, e, s) {
|
|
1223
1206
|
if (!t || !await G(t) || !(await oe(t)).isFile())
|
|
1224
1207
|
return null;
|
|
1225
1208
|
let o = s[t];
|
|
1226
1209
|
return o || (o = (async () => {
|
|
1227
1210
|
try {
|
|
1228
|
-
return (await
|
|
1211
|
+
return (await cs({
|
|
1229
1212
|
filePath: t,
|
|
1230
1213
|
fileName: e
|
|
1231
1214
|
}))?.data?.filename;
|
|
@@ -1234,68 +1217,68 @@ async function hs(t, e, s) {
|
|
|
1234
1217
|
}
|
|
1235
1218
|
})(), s[t] = o), o;
|
|
1236
1219
|
}
|
|
1237
|
-
const
|
|
1238
|
-
const s = $(t), a = await
|
|
1239
|
-
name:
|
|
1220
|
+
const gs = async (t, e) => {
|
|
1221
|
+
const s = $(t), a = await Ot({
|
|
1222
|
+
name: Ke,
|
|
1240
1223
|
path: x("/uploads", s),
|
|
1241
1224
|
responseType: "stream",
|
|
1242
1225
|
method: "GET"
|
|
1243
1226
|
});
|
|
1244
1227
|
if (a.status >= 200 && a.status < 400) {
|
|
1245
|
-
const o =
|
|
1246
|
-
await
|
|
1228
|
+
const o = It(e);
|
|
1229
|
+
await Tt(a.data, o);
|
|
1247
1230
|
} else
|
|
1248
1231
|
throw new Error(`download asset failed ${a.status}`);
|
|
1249
|
-
},
|
|
1232
|
+
}, hs = async (t, e) => {
|
|
1250
1233
|
await Promise.all(
|
|
1251
1234
|
t.map(async (s) => {
|
|
1252
1235
|
try {
|
|
1253
|
-
await
|
|
1236
|
+
await gs(s, A(e, $(s)));
|
|
1254
1237
|
} catch (a) {
|
|
1255
1238
|
p.error(`Failed to export assets: ${s}, ${a}`);
|
|
1256
1239
|
}
|
|
1257
1240
|
})
|
|
1258
1241
|
);
|
|
1259
1242
|
};
|
|
1260
|
-
function
|
|
1261
|
-
return
|
|
1243
|
+
function Qe(t) {
|
|
1244
|
+
return ke.test(t) ? [t] : X.test(t) ? (Be.lastIndex = 0, Array.from(t.matchAll(Be)).map((s) => s[1]).filter((s) => !!s)) : [];
|
|
1262
1245
|
}
|
|
1263
1246
|
async function ae(t, e, s) {
|
|
1264
1247
|
const { getFilename: a, exportAssets: o, useWorker: r } = s, l = A(e, a(t));
|
|
1265
1248
|
await B(M(l), { recursive: !0 });
|
|
1266
|
-
const n = r ? await
|
|
1249
|
+
const n = r ? await es(t) : q.stringify(t);
|
|
1267
1250
|
if (await re(l, n), o) {
|
|
1268
|
-
const
|
|
1251
|
+
const h = ie(
|
|
1269
1252
|
t,
|
|
1270
|
-
(b) => typeof b == "string" && (
|
|
1253
|
+
(b) => typeof b == "string" && (ke.test(b) || X.test(b))
|
|
1271
1254
|
).map((b) => {
|
|
1272
|
-
const
|
|
1273
|
-
return
|
|
1255
|
+
const O = Ce(t, b);
|
|
1256
|
+
return Qe(O);
|
|
1274
1257
|
}).flat().filter(Boolean);
|
|
1275
|
-
await
|
|
1258
|
+
await hs(h, M(l));
|
|
1276
1259
|
}
|
|
1277
1260
|
}
|
|
1278
|
-
const Pe = new
|
|
1261
|
+
const Pe = new Je({
|
|
1279
1262
|
max: 100,
|
|
1280
1263
|
ttl: 1 * 60 * 1e3
|
|
1281
1264
|
// 1 minute
|
|
1282
1265
|
});
|
|
1283
|
-
async function
|
|
1266
|
+
async function Ge(t, e, s) {
|
|
1284
1267
|
const a = ie(
|
|
1285
1268
|
t,
|
|
1286
|
-
(n) => typeof n == "string" && (
|
|
1287
|
-
), o =
|
|
1269
|
+
(n) => typeof n == "string" && (ke.test(n) || X.test(n))
|
|
1270
|
+
), o = Oe(2), r = a.map(
|
|
1288
1271
|
(n) => o(async () => {
|
|
1289
1272
|
try {
|
|
1290
|
-
const c =
|
|
1291
|
-
for (const b of
|
|
1292
|
-
const
|
|
1273
|
+
const c = Ce(t, n), h = Qe(c);
|
|
1274
|
+
for (const b of h) {
|
|
1275
|
+
const O = $(b), w = s.getFilePath(b, n), m = w ? `${w}:${O}` : O, u = Pe.get(m);
|
|
1293
1276
|
if (u) {
|
|
1294
|
-
X.test(c) ||
|
|
1277
|
+
X.test(c) || Ne(t, n, u);
|
|
1295
1278
|
return;
|
|
1296
1279
|
}
|
|
1297
|
-
const I = await
|
|
1298
|
-
I && (X.test(c) ||
|
|
1280
|
+
const I = await ms(w, O, e);
|
|
1281
|
+
I && (X.test(c) || Ne(t, n, I), Pe.set(m, I));
|
|
1299
1282
|
}
|
|
1300
1283
|
} catch (c) {
|
|
1301
1284
|
p.error(`Failed to process upload for path ${n.join(".")}:`, c.message || c.reason);
|
|
@@ -1304,7 +1287,7 @@ async function ze(t, e, s) {
|
|
|
1304
1287
|
), l = await Promise.allSettled(r);
|
|
1305
1288
|
s.onFinish?.(l);
|
|
1306
1289
|
}
|
|
1307
|
-
async function
|
|
1290
|
+
async function ys(t, {
|
|
1308
1291
|
exportAssets: e,
|
|
1309
1292
|
pageIds: s = "all",
|
|
1310
1293
|
componentIds: a = "all",
|
|
@@ -1312,7 +1295,7 @@ async function ws(t, {
|
|
|
1312
1295
|
includeResources: r = !1,
|
|
1313
1296
|
routeIds: l = "all"
|
|
1314
1297
|
} = {}) {
|
|
1315
|
-
const n = s === "all" ? t.pageIds : s, c =
|
|
1298
|
+
const n = s === "all" ? t.pageIds : s, c = At({
|
|
1316
1299
|
state: t,
|
|
1317
1300
|
pageIds: n,
|
|
1318
1301
|
componentIds: a === "all" ? Object.keys(t.components) : a
|
|
@@ -1320,7 +1303,7 @@ async function ws(t, {
|
|
|
1320
1303
|
Object.entries(t.components).forEach(([i, d]) => {
|
|
1321
1304
|
d.data?.renderer?.type === "component-template" && c.push(i);
|
|
1322
1305
|
});
|
|
1323
|
-
const
|
|
1306
|
+
const h = l === "all" ? t.routeIds : l, b = (i) => ({
|
|
1324
1307
|
id: i.id,
|
|
1325
1308
|
name: i.name,
|
|
1326
1309
|
isTemplateSection: i.isTemplateSection ?? !1,
|
|
@@ -1332,13 +1315,13 @@ async function ws(t, {
|
|
|
1332
1315
|
visibility: i.visibility,
|
|
1333
1316
|
sections: i?.sectionIds ? L(
|
|
1334
1317
|
i?.sectionIds?.map((d) => {
|
|
1335
|
-
const
|
|
1336
|
-
return
|
|
1318
|
+
const f = i.sections?.[d];
|
|
1319
|
+
return f && b(f);
|
|
1337
1320
|
})
|
|
1338
1321
|
) : void 0
|
|
1339
1322
|
/** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
|
|
1340
1323
|
// properties: section.locales?.[locale] ?? {},
|
|
1341
|
-
}),
|
|
1324
|
+
}), O = (i, d) => ({
|
|
1342
1325
|
id: i.id,
|
|
1343
1326
|
createdAt: i.createdAt,
|
|
1344
1327
|
updatedAt: i.updatedAt,
|
|
@@ -1347,16 +1330,16 @@ async function ws(t, {
|
|
|
1347
1330
|
templateConfig: i.templateConfig,
|
|
1348
1331
|
meta: i.locales?.[d] ?? {},
|
|
1349
1332
|
sections: L(
|
|
1350
|
-
i.sectionIds.map((
|
|
1351
|
-
const
|
|
1352
|
-
return
|
|
1333
|
+
i.sectionIds.map((f) => {
|
|
1334
|
+
const C = i.sections[f];
|
|
1335
|
+
return C && b(C);
|
|
1353
1336
|
})
|
|
1354
1337
|
),
|
|
1355
1338
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1356
1339
|
dataSource: Object.fromEntries(
|
|
1357
|
-
Object.entries(i.dataSource || {}).map(([
|
|
1340
|
+
Object.entries(i.dataSource || {}).map(([f, C]) => [f, C?.[d] ?? {}])
|
|
1358
1341
|
)
|
|
1359
|
-
}),
|
|
1342
|
+
}), w = (i) => ({
|
|
1360
1343
|
id: i.id,
|
|
1361
1344
|
createdAt: i.createdAt,
|
|
1362
1345
|
updatedAt: i.updatedAt,
|
|
@@ -1368,50 +1351,50 @@ async function ws(t, {
|
|
|
1368
1351
|
enabledGenerate: i.enabledGenerate ?? !1,
|
|
1369
1352
|
displayTemplateId: i.displayTemplateId,
|
|
1370
1353
|
dataSource: i.dataSource
|
|
1371
|
-
}),
|
|
1372
|
-
|
|
1354
|
+
}), m = L(
|
|
1355
|
+
h.map((i) => {
|
|
1373
1356
|
const d = t.routes[i];
|
|
1374
|
-
return d &&
|
|
1357
|
+
return d && w(d);
|
|
1375
1358
|
})
|
|
1376
1359
|
), u = L(
|
|
1377
1360
|
t.supportedLocales.map((i) => i.locale).flatMap(
|
|
1378
1361
|
(i) => n.map((d) => {
|
|
1379
|
-
const
|
|
1380
|
-
return
|
|
1362
|
+
const f = t.pages[d];
|
|
1363
|
+
return f && {
|
|
1381
1364
|
locale: i,
|
|
1382
|
-
slug:
|
|
1383
|
-
page:
|
|
1365
|
+
slug: f.slug,
|
|
1366
|
+
page: O(f, i)
|
|
1384
1367
|
};
|
|
1385
1368
|
})
|
|
1386
1369
|
)
|
|
1387
|
-
), I =
|
|
1388
|
-
await B(
|
|
1389
|
-
const
|
|
1390
|
-
await B(
|
|
1391
|
-
const
|
|
1392
|
-
await B(
|
|
1393
|
-
for (const { locale: i, slug: d, page:
|
|
1394
|
-
await ae(
|
|
1370
|
+
), I = Xe(), R = A(I, "pages");
|
|
1371
|
+
await B(R, { recursive: !0 });
|
|
1372
|
+
const j = A(I, "components");
|
|
1373
|
+
await B(j, { recursive: !0 });
|
|
1374
|
+
const S = A(I, "routes");
|
|
1375
|
+
await B(S, { recursive: !0 });
|
|
1376
|
+
for (const { locale: i, slug: d, page: f } of u)
|
|
1377
|
+
await ae(f, R, {
|
|
1395
1378
|
getFilename: () => `${ce(d) || "index"}.${i}.yml`,
|
|
1396
1379
|
exportAssets: e,
|
|
1397
1380
|
useWorker: !0
|
|
1398
1381
|
});
|
|
1399
|
-
for (const i of
|
|
1400
|
-
await ae(i,
|
|
1382
|
+
for (const i of m)
|
|
1383
|
+
await ae(i, S, {
|
|
1401
1384
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1402
1385
|
getFilename: () => `${ce(i.path) || "index"}.yml`,
|
|
1403
1386
|
exportAssets: e
|
|
1404
1387
|
});
|
|
1405
1388
|
for (const i of c) {
|
|
1406
1389
|
const d = t.components[i]?.data;
|
|
1407
|
-
d && await ae(d,
|
|
1408
|
-
getFilename: (
|
|
1390
|
+
d && await ae(d, j, {
|
|
1391
|
+
getFilename: (f) => `${f.name || "unnamed"}.${f.id}.yml`,
|
|
1409
1392
|
exportAssets: e
|
|
1410
1393
|
});
|
|
1411
1394
|
}
|
|
1412
|
-
const
|
|
1413
|
-
await B(M(
|
|
1414
|
-
const
|
|
1395
|
+
const v = A(I, ".blocklet/pages/pages.config.yml");
|
|
1396
|
+
await B(M(v), { recursive: !0 });
|
|
1397
|
+
const g = {
|
|
1415
1398
|
pages: L(
|
|
1416
1399
|
n.map((i) => {
|
|
1417
1400
|
const d = t.pages[i];
|
|
@@ -1419,7 +1402,7 @@ async function ws(t, {
|
|
|
1419
1402
|
})
|
|
1420
1403
|
),
|
|
1421
1404
|
routes: L(
|
|
1422
|
-
|
|
1405
|
+
h.map((i) => {
|
|
1423
1406
|
const d = t.routes[i];
|
|
1424
1407
|
return d && { id: i, path: d.path };
|
|
1425
1408
|
})
|
|
@@ -1446,9 +1429,9 @@ async function ws(t, {
|
|
|
1446
1429
|
supportedLocales: t.supportedLocales,
|
|
1447
1430
|
config: t.config
|
|
1448
1431
|
};
|
|
1449
|
-
await re(
|
|
1450
|
-
const
|
|
1451
|
-
if (o && await re(
|
|
1432
|
+
await re(v, q.stringify(g));
|
|
1433
|
+
const y = A(I, "config.source.json");
|
|
1434
|
+
if (o && await re(y, JSON.stringify(o)), r) {
|
|
1452
1435
|
const i = A(I, "resources"), d = A(i, "components");
|
|
1453
1436
|
await B(d, { recursive: !0 });
|
|
1454
1437
|
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
@@ -1460,9 +1443,9 @@ async function ws(t, {
|
|
|
1460
1443
|
exportAssets: e
|
|
1461
1444
|
});
|
|
1462
1445
|
}
|
|
1463
|
-
const
|
|
1464
|
-
await B(
|
|
1465
|
-
const
|
|
1446
|
+
const f = A(I, "chunks");
|
|
1447
|
+
await B(f, { recursive: !0 });
|
|
1448
|
+
const C = await Ss();
|
|
1466
1449
|
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1467
1450
|
(T) => c.includes(T)
|
|
1468
1451
|
)) {
|
|
@@ -1470,12 +1453,12 @@ async function ws(t, {
|
|
|
1470
1453
|
if (T && T.renderer?.type === "react-component") {
|
|
1471
1454
|
const V = T.renderer?.chunks ?? [];
|
|
1472
1455
|
if (V?.length > 0)
|
|
1473
|
-
for (const
|
|
1474
|
-
const Te = A(
|
|
1456
|
+
for (const J of V) {
|
|
1457
|
+
const Te = A(f, J), de = C?.[J];
|
|
1475
1458
|
try {
|
|
1476
|
-
de && await G(de) && !await G(Te) && await
|
|
1477
|
-
} catch (
|
|
1478
|
-
p.error(`copy chunk ${
|
|
1459
|
+
de && await G(de) && !await G(Te) && await Ct(de, Te);
|
|
1460
|
+
} catch (nt) {
|
|
1461
|
+
p.error(`copy chunk ${J} error`, nt.message);
|
|
1479
1462
|
}
|
|
1480
1463
|
}
|
|
1481
1464
|
}
|
|
@@ -1483,87 +1466,87 @@ async function ws(t, {
|
|
|
1483
1466
|
}
|
|
1484
1467
|
return I;
|
|
1485
1468
|
}
|
|
1486
|
-
async function
|
|
1469
|
+
async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
1487
1470
|
if (!await G(t))
|
|
1488
1471
|
return null;
|
|
1489
1472
|
let a, o = !1;
|
|
1490
1473
|
try {
|
|
1491
|
-
(await oe(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a =
|
|
1492
|
-
const n = (await ye("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], c = n && A(M(n), "../../pages"),
|
|
1474
|
+
(await oe(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Xe(), await Lt({ file: t, C: a }));
|
|
1475
|
+
const n = (await ye("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], c = n && A(M(n), "../../pages"), h = n && A(M(n), "../../components"), b = n && A(M(n), "../../routes");
|
|
1493
1476
|
if (!n)
|
|
1494
1477
|
return null;
|
|
1495
|
-
const
|
|
1496
|
-
let d = A(
|
|
1497
|
-
if (!await G(d) && (d = A(
|
|
1478
|
+
const O = await te(n, "utf-8"), w = q.parse(O), m = async (g, y, i) => {
|
|
1479
|
+
let d = A(g, `${y}${i ? `.${i}` : ""}.yml`);
|
|
1480
|
+
if (!await G(d) && (d = A(g, y, `index${i ? `.${i}` : ""}.yml`), !await G(d)) || !(await oe(d)).isFile())
|
|
1498
1481
|
return null;
|
|
1499
|
-
const
|
|
1500
|
-
return q.parse(
|
|
1501
|
-
}, u = async (
|
|
1482
|
+
const C = await te(d, "utf-8");
|
|
1483
|
+
return q.parse(C);
|
|
1484
|
+
}, u = async (g, y) => {
|
|
1502
1485
|
try {
|
|
1503
|
-
const d = (await ye(`*.${
|
|
1486
|
+
const d = (await ye(`*.${y}.yml`, { cwd: g, absolute: !0 }))[0];
|
|
1504
1487
|
if (!d) return null;
|
|
1505
|
-
const
|
|
1506
|
-
return q.parse(
|
|
1488
|
+
const f = await te(d, "utf-8");
|
|
1489
|
+
return q.parse(f);
|
|
1507
1490
|
} catch (i) {
|
|
1508
1491
|
p.error("parse component error", i);
|
|
1509
1492
|
}
|
|
1510
1493
|
return null;
|
|
1511
|
-
}, I = async (
|
|
1512
|
-
let i = A(
|
|
1513
|
-
if (!await G(i) && (i = A(
|
|
1494
|
+
}, I = async (g, y) => {
|
|
1495
|
+
let i = A(g, `${y}.yml`);
|
|
1496
|
+
if (!await G(i) && (i = A(g, y, "index.yml"), !await G(i)) || !(await oe(i)).isFile())
|
|
1514
1497
|
return null;
|
|
1515
|
-
const
|
|
1516
|
-
return q.parse(
|
|
1517
|
-
},
|
|
1498
|
+
const f = await te(i, "utf-8");
|
|
1499
|
+
return q.parse(f);
|
|
1500
|
+
}, R = L(
|
|
1518
1501
|
await Promise.all(
|
|
1519
|
-
|
|
1520
|
-
const
|
|
1502
|
+
w.pages.map(async ({ slug: g }) => {
|
|
1503
|
+
const y = L(
|
|
1521
1504
|
await Promise.all(
|
|
1522
|
-
|
|
1523
|
-
const
|
|
1524
|
-
if (
|
|
1525
|
-
return { locale:
|
|
1526
|
-
const N = c ? await
|
|
1527
|
-
return N && { locale:
|
|
1505
|
+
w.supportedLocales.map(async ({ locale: f }) => {
|
|
1506
|
+
const C = c ? await m(c, ce(g), f) : void 0;
|
|
1507
|
+
if (C)
|
|
1508
|
+
return { locale: f, page: C };
|
|
1509
|
+
const N = c ? await m(c, g, f) : void 0;
|
|
1510
|
+
return N && { locale: f, page: N };
|
|
1528
1511
|
})
|
|
1529
1512
|
)
|
|
1530
|
-
), i =
|
|
1513
|
+
), i = y[0]?.page;
|
|
1531
1514
|
if (!i)
|
|
1532
1515
|
return null;
|
|
1533
|
-
const d = i.sections.map(
|
|
1516
|
+
const d = i.sections.map(bt);
|
|
1534
1517
|
return {
|
|
1535
|
-
id: i.id ||
|
|
1518
|
+
id: i.id || $e(),
|
|
1536
1519
|
createdAt: i.createdAt,
|
|
1537
1520
|
updatedAt: i.updatedAt,
|
|
1538
1521
|
publishedAt: i.publishedAt,
|
|
1539
1522
|
isPublic: i.isPublic ?? !0,
|
|
1540
1523
|
templateConfig: i.templateConfig,
|
|
1541
|
-
slug:
|
|
1542
|
-
sections: Object.fromEntries(d.map((
|
|
1543
|
-
sectionIds: d.map((
|
|
1544
|
-
locales: Object.fromEntries(
|
|
1524
|
+
slug: g,
|
|
1525
|
+
sections: Object.fromEntries(d.map((f) => [f.id, f])),
|
|
1526
|
+
sectionIds: d.map((f) => f.id),
|
|
1527
|
+
locales: Object.fromEntries(y.map(({ locale: f, page: C }) => [f, C.meta])),
|
|
1545
1528
|
dataSource: i.dataSource ? Object.fromEntries(
|
|
1546
1529
|
// 获取 dataSource 中所有 section ID
|
|
1547
|
-
[...new Set(
|
|
1548
|
-
|
|
1530
|
+
[...new Set(y.flatMap(({ page: f }) => Object.keys(f.dataSource ?? {})))].map((f) => [
|
|
1531
|
+
f,
|
|
1549
1532
|
Object.fromEntries(
|
|
1550
|
-
|
|
1551
|
-
const T = N.dataSource?.[
|
|
1552
|
-
return [
|
|
1533
|
+
y.map(({ locale: C, page: N }) => {
|
|
1534
|
+
const T = N.dataSource?.[f];
|
|
1535
|
+
return [C, T || {}];
|
|
1553
1536
|
})
|
|
1554
1537
|
)
|
|
1555
1538
|
])
|
|
1556
1539
|
) : Object.fromEntries(
|
|
1557
1540
|
// 获取所有 section ID
|
|
1558
|
-
[...new Set(
|
|
1559
|
-
|
|
1541
|
+
[...new Set(y.flatMap(({ page: f }) => f.sections.map((C) => C.id)))].map((f) => [
|
|
1542
|
+
f,
|
|
1560
1543
|
Object.fromEntries(
|
|
1561
|
-
|
|
1562
|
-
const T = N.dataSource?.[
|
|
1544
|
+
y.map(({ locale: C, page: N }) => {
|
|
1545
|
+
const T = N.dataSource?.[f];
|
|
1563
1546
|
if (T)
|
|
1564
|
-
return [
|
|
1565
|
-
const V = N.sections.find((
|
|
1566
|
-
return [
|
|
1547
|
+
return [C, T];
|
|
1548
|
+
const V = N.sections.find((J) => J.id === f);
|
|
1549
|
+
return [C, V?.properties || {}];
|
|
1567
1550
|
})
|
|
1568
1551
|
)
|
|
1569
1552
|
])
|
|
@@ -1571,80 +1554,80 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1571
1554
|
};
|
|
1572
1555
|
})
|
|
1573
1556
|
)
|
|
1574
|
-
),
|
|
1557
|
+
), j = L(
|
|
1575
1558
|
await Promise.all(
|
|
1576
|
-
(
|
|
1577
|
-
const
|
|
1559
|
+
(w?.routes || []).map(async ({ path: g }) => {
|
|
1560
|
+
const y = b ? await I(b, ce(g)) : void 0;
|
|
1578
1561
|
return {
|
|
1579
|
-
...
|
|
1580
|
-
id:
|
|
1581
|
-
createdAt:
|
|
1582
|
-
updatedAt:
|
|
1562
|
+
...y,
|
|
1563
|
+
id: y?.id || $e(),
|
|
1564
|
+
createdAt: y?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1565
|
+
updatedAt: y?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1583
1566
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1584
|
-
path:
|
|
1585
|
-
params:
|
|
1586
|
-
handler:
|
|
1587
|
-
isPublic:
|
|
1588
|
-
enabledGenerate:
|
|
1589
|
-
displayTemplateId:
|
|
1590
|
-
dataSource:
|
|
1567
|
+
path: y?.path ?? `/${y?.id}`,
|
|
1568
|
+
params: y?.params,
|
|
1569
|
+
handler: y?.handler ?? "Pages Kit",
|
|
1570
|
+
isPublic: y?.isPublic ?? !0,
|
|
1571
|
+
enabledGenerate: y?.enabledGenerate ?? !1,
|
|
1572
|
+
displayTemplateId: y?.displayTemplateId ?? void 0,
|
|
1573
|
+
dataSource: y?.dataSource ?? {}
|
|
1591
1574
|
};
|
|
1592
1575
|
})
|
|
1593
1576
|
)
|
|
1594
|
-
),
|
|
1595
|
-
await Promise.all((
|
|
1577
|
+
), S = h ? L(
|
|
1578
|
+
await Promise.all((w.components || []).map(async ({ id: g }) => u(h, g)))
|
|
1596
1579
|
) : [];
|
|
1597
1580
|
if (e) {
|
|
1598
|
-
const
|
|
1599
|
-
p.info(`[${o ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...
|
|
1581
|
+
const g = (...y) => {
|
|
1582
|
+
p.info(`[${o ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...y);
|
|
1600
1583
|
};
|
|
1601
1584
|
try {
|
|
1602
|
-
|
|
1603
|
-
resources: [`${
|
|
1585
|
+
g("wait image-bin api ready"), await $t({
|
|
1586
|
+
resources: [`${Et(lt)}/api/sdk/uploads`],
|
|
1604
1587
|
validateStatus: (d) => d >= 200 && d <= 500
|
|
1605
|
-
}),
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
getFilePath: (d) =>
|
|
1588
|
+
}), g("image-bin api is ready");
|
|
1589
|
+
const y = {}, i = {};
|
|
1590
|
+
g("start to upload assets"), await Promise.allSettled([
|
|
1591
|
+
Ge(S, y, {
|
|
1592
|
+
getFilePath: (d) => h && A(h, d),
|
|
1610
1593
|
onFinish: (d) => {
|
|
1611
|
-
|
|
1594
|
+
g(`upload ${d.length} component assets`);
|
|
1612
1595
|
}
|
|
1613
1596
|
}),
|
|
1614
|
-
|
|
1615
|
-
getFilePath: (d,
|
|
1616
|
-
const
|
|
1617
|
-
return c && A(c, M(
|
|
1597
|
+
Ge(R, i, {
|
|
1598
|
+
getFilePath: (d, f) => {
|
|
1599
|
+
const C = Ce(R, f.slice(0, 1));
|
|
1600
|
+
return c && A(c, M(C.slug), d);
|
|
1618
1601
|
},
|
|
1619
1602
|
onFinish: (d) => {
|
|
1620
|
-
|
|
1603
|
+
g(`upload ${d.length} page assets`);
|
|
1621
1604
|
}
|
|
1622
1605
|
})
|
|
1623
|
-
]),
|
|
1624
|
-
} catch (
|
|
1625
|
-
|
|
1606
|
+
]), g("upload assets done"), Pe.clear(), global.gc && global.gc();
|
|
1607
|
+
} catch (y) {
|
|
1608
|
+
g("Error during asset import:", y);
|
|
1626
1609
|
}
|
|
1627
1610
|
}
|
|
1628
|
-
const
|
|
1611
|
+
const v = {};
|
|
1629
1612
|
if (s) {
|
|
1630
|
-
const
|
|
1613
|
+
const g = n && A(M(n), "../../resources/components"), y = L(
|
|
1631
1614
|
await Promise.all(
|
|
1632
|
-
(
|
|
1615
|
+
(w.resources?.components || []).map(async ({ id: i }) => u(g, i))
|
|
1633
1616
|
)
|
|
1634
1617
|
);
|
|
1635
|
-
|
|
1636
|
-
|
|
1618
|
+
y.length > 0 && (v.components = Object.fromEntries(
|
|
1619
|
+
y.map((i, d) => [i.id, { index: d, component: i }])
|
|
1637
1620
|
));
|
|
1638
1621
|
}
|
|
1639
1622
|
return {
|
|
1640
|
-
supportedLocales:
|
|
1641
|
-
pageIds:
|
|
1642
|
-
components: Object.fromEntries(
|
|
1643
|
-
pages: Object.fromEntries(
|
|
1644
|
-
config:
|
|
1645
|
-
resources:
|
|
1646
|
-
routeIds:
|
|
1647
|
-
routes: Object.fromEntries(
|
|
1623
|
+
supportedLocales: w.supportedLocales,
|
|
1624
|
+
pageIds: R.map((g) => g.id),
|
|
1625
|
+
components: Object.fromEntries(S.map((g, y) => [g.id, { index: y, data: g }])),
|
|
1626
|
+
pages: Object.fromEntries(R.map((g) => [g.id, g])),
|
|
1627
|
+
config: w.config || {},
|
|
1628
|
+
resources: v,
|
|
1629
|
+
routeIds: j.map((g) => g.id),
|
|
1630
|
+
routes: Object.fromEntries(j.map((g) => [g.id, g])),
|
|
1648
1631
|
dataSourceIds: [],
|
|
1649
1632
|
dataSources: {}
|
|
1650
1633
|
};
|
|
@@ -1652,24 +1635,24 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1652
1635
|
o && a && await We(a, { force: !0, recursive: !0 });
|
|
1653
1636
|
}
|
|
1654
1637
|
}
|
|
1655
|
-
async function
|
|
1638
|
+
async function Ve(t, e, {
|
|
1656
1639
|
routes: s,
|
|
1657
1640
|
mergeMode: a = "byUpdateTime",
|
|
1658
1641
|
deleteRoutes: o = !1,
|
|
1659
1642
|
publishMode: r = void 0
|
|
1660
1643
|
} = {}) {
|
|
1661
1644
|
try {
|
|
1662
|
-
r &&
|
|
1663
|
-
} catch (
|
|
1664
|
-
p.error("clear preload page cache error", { error:
|
|
1645
|
+
r && pt(r);
|
|
1646
|
+
} catch (w) {
|
|
1647
|
+
p.error("clear preload page cache error", { error: w });
|
|
1665
1648
|
}
|
|
1666
|
-
const { pages: l, pageIds: n, routeIds: c, routes:
|
|
1649
|
+
const { pages: l, pageIds: n, routeIds: c, routes: h, supportedLocales: b } = t;
|
|
1667
1650
|
if (r === "production") {
|
|
1668
|
-
let
|
|
1651
|
+
let w = s ?? [], m = null;
|
|
1669
1652
|
for (const u of c ?? []) {
|
|
1670
|
-
const I =
|
|
1653
|
+
const I = h?.[u];
|
|
1671
1654
|
if (I?.params && I?.params.length > 0 && I?.paramsOptions && I?.paramsOptions.length > 0) {
|
|
1672
|
-
const
|
|
1655
|
+
const R = be({
|
|
1673
1656
|
basePath: I.path,
|
|
1674
1657
|
params: I.params,
|
|
1675
1658
|
routeId: I.id,
|
|
@@ -1678,127 +1661,127 @@ async function qe(t, e, {
|
|
|
1678
1661
|
currentParams: [],
|
|
1679
1662
|
currentOptionIds: [],
|
|
1680
1663
|
result: []
|
|
1681
|
-
}),
|
|
1682
|
-
|
|
1683
|
-
} else s ||
|
|
1664
|
+
}), j = Object.fromEntries(R.map((S) => [`${u}-${S.paramOptionIds.join("-")}`, S]));
|
|
1665
|
+
m = { ...m || {}, ...j }, s || (w = [...w, ...R.map((S) => `${u}-${S.paramOptionIds.join("-")}`)]);
|
|
1666
|
+
} else s || w.push(u);
|
|
1684
1667
|
}
|
|
1685
|
-
p.info("routeIds to be published: ",
|
|
1686
|
-
for (const u of
|
|
1668
|
+
p.info("routeIds to be published: ", w);
|
|
1669
|
+
for (const u of w) {
|
|
1687
1670
|
let I = u;
|
|
1688
1671
|
if (I.includes("-")) {
|
|
1689
|
-
const [
|
|
1690
|
-
I =
|
|
1672
|
+
const [S] = I.split("-");
|
|
1673
|
+
I = S;
|
|
1691
1674
|
}
|
|
1692
|
-
const
|
|
1693
|
-
if (!
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1696
|
-
for (const
|
|
1697
|
-
|
|
1675
|
+
const R = h?.[I];
|
|
1676
|
+
if (!R) {
|
|
1677
|
+
const S = e.pageIds.indexOf(I);
|
|
1678
|
+
S !== -1 && o && (e.pageIds.splice(S, 1), delete e.pages[I]);
|
|
1679
|
+
for (const v of e.pageIds)
|
|
1680
|
+
v.includes(`${I}-`) && (e.pageIds.splice(e.pageIds.indexOf(v), 1), delete e.pages[v]);
|
|
1698
1681
|
p.info("delete main route page", I);
|
|
1699
1682
|
continue;
|
|
1700
1683
|
}
|
|
1701
|
-
if (u.includes("-") && !
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1684
|
+
if (u.includes("-") && !m?.[u]) {
|
|
1685
|
+
const S = e.pageIds.indexOf(u);
|
|
1686
|
+
S !== -1 && o && (e.pageIds.splice(S, 1), delete e.pages[u]), p.info("delete page", u);
|
|
1704
1687
|
continue;
|
|
1705
1688
|
}
|
|
1706
|
-
if (!
|
|
1689
|
+
if (!R.displayTemplateId) {
|
|
1707
1690
|
p.info("no display template", u);
|
|
1708
1691
|
continue;
|
|
1709
1692
|
}
|
|
1710
|
-
const
|
|
1711
|
-
if (!
|
|
1693
|
+
const j = l[R.displayTemplateId];
|
|
1694
|
+
if (!j) {
|
|
1712
1695
|
p.info("no template page", u);
|
|
1713
1696
|
continue;
|
|
1714
1697
|
}
|
|
1715
1698
|
if (e.pageIds.includes(u)) {
|
|
1716
1699
|
if (p.info("has need update page", u), a === "replace")
|
|
1717
1700
|
e.pages[u] = me({
|
|
1718
|
-
page:
|
|
1719
|
-
route:
|
|
1701
|
+
page: j,
|
|
1702
|
+
route: R,
|
|
1720
1703
|
state: t,
|
|
1721
1704
|
routeId: u,
|
|
1722
|
-
routePathInfo:
|
|
1705
|
+
routePathInfo: m?.[u]
|
|
1723
1706
|
}), p.info("replace page", u);
|
|
1724
1707
|
else if (a === "byUpdateTime") {
|
|
1725
|
-
const
|
|
1726
|
-
(!
|
|
1727
|
-
page:
|
|
1728
|
-
route:
|
|
1708
|
+
const S = e.pages[R.id];
|
|
1709
|
+
(!S || R.updatedAt && R.updatedAt > S.updatedAt) && (e.pages[u] = me({
|
|
1710
|
+
page: j,
|
|
1711
|
+
route: R,
|
|
1729
1712
|
state: t,
|
|
1730
1713
|
routeId: u,
|
|
1731
|
-
routePathInfo:
|
|
1714
|
+
routePathInfo: m?.[u]
|
|
1732
1715
|
}), p.info("replace page by update time", u));
|
|
1733
1716
|
}
|
|
1734
1717
|
} else
|
|
1735
1718
|
e.pageIds.push(u), e.pages[u] = me({
|
|
1736
|
-
page:
|
|
1737
|
-
route:
|
|
1719
|
+
page: j,
|
|
1720
|
+
route: R,
|
|
1738
1721
|
state: t,
|
|
1739
1722
|
routeId: u,
|
|
1740
|
-
routePathInfo:
|
|
1723
|
+
routePathInfo: m?.[u]
|
|
1741
1724
|
}), p.info("add page", u);
|
|
1742
1725
|
}
|
|
1743
1726
|
if (o && !s)
|
|
1744
1727
|
for (const u of e.pageIds)
|
|
1745
|
-
|
|
1728
|
+
w?.includes(u) || (delete e.pages[u], p.info("delete page", u)), e.pageIds = [...e.pageIds].filter((I) => w?.includes(I));
|
|
1746
1729
|
} else {
|
|
1747
|
-
for (const
|
|
1748
|
-
const
|
|
1749
|
-
if (
|
|
1750
|
-
if (e.pageIds.includes(
|
|
1730
|
+
for (const w of n) {
|
|
1731
|
+
const m = l[w];
|
|
1732
|
+
if (m)
|
|
1733
|
+
if (e.pageIds.includes(m.id)) {
|
|
1751
1734
|
if (a === "replace")
|
|
1752
|
-
e.pages[
|
|
1735
|
+
e.pages[m.id] = m;
|
|
1753
1736
|
else if (a === "byUpdateTime") {
|
|
1754
|
-
const u = e.pages[
|
|
1755
|
-
(!u ||
|
|
1737
|
+
const u = e.pages[m.id];
|
|
1738
|
+
(!u || m.updatedAt && m.updatedAt > u.updatedAt) && (e.pages[m.id] = m);
|
|
1756
1739
|
}
|
|
1757
1740
|
} else
|
|
1758
|
-
e.pageIds.push(
|
|
1741
|
+
e.pageIds.push(m.id), e.pages[m.id] = m;
|
|
1759
1742
|
}
|
|
1760
|
-
for (const
|
|
1761
|
-
const
|
|
1762
|
-
if (
|
|
1763
|
-
if (e.routeIds.includes(
|
|
1743
|
+
for (const w of c) {
|
|
1744
|
+
const m = h[w];
|
|
1745
|
+
if (m)
|
|
1746
|
+
if (e.routeIds.includes(m.id)) {
|
|
1764
1747
|
if (a === "replace")
|
|
1765
|
-
e.routes[
|
|
1748
|
+
e.routes[m.id] = m;
|
|
1766
1749
|
else if (a === "byUpdateTime") {
|
|
1767
|
-
const u = e.routes[
|
|
1768
|
-
(!u ||
|
|
1750
|
+
const u = e.routes[m.id];
|
|
1751
|
+
(!u || m.updatedAt && m.updatedAt > u.updatedAt) && (e.routes[m.id] = m);
|
|
1769
1752
|
}
|
|
1770
1753
|
} else
|
|
1771
|
-
e.routeIds.push(
|
|
1754
|
+
e.routeIds.push(m.id), e.routes[m.id] = m;
|
|
1772
1755
|
}
|
|
1773
1756
|
}
|
|
1774
1757
|
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ae(b)), o)
|
|
1775
|
-
for (const
|
|
1776
|
-
delete e.components[
|
|
1777
|
-
let
|
|
1778
|
-
|
|
1758
|
+
for (const w of Object.keys(e.components))
|
|
1759
|
+
delete e.components[w];
|
|
1760
|
+
let O = JSON.parse(JSON.stringify(t.components));
|
|
1761
|
+
O = Object.fromEntries(
|
|
1779
1762
|
await Promise.all(
|
|
1780
|
-
Object.entries(
|
|
1781
|
-
const u = await
|
|
1763
|
+
Object.entries(O).map(async ([w, m]) => {
|
|
1764
|
+
const u = await et(m?.data);
|
|
1782
1765
|
return [
|
|
1783
|
-
|
|
1766
|
+
w,
|
|
1784
1767
|
{
|
|
1785
|
-
...
|
|
1768
|
+
...m,
|
|
1786
1769
|
data: u
|
|
1787
1770
|
}
|
|
1788
1771
|
];
|
|
1789
1772
|
})
|
|
1790
1773
|
)
|
|
1791
|
-
), Object.assign(e.components,
|
|
1774
|
+
), Object.assign(e.components, O), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), De(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1792
1775
|
}
|
|
1793
|
-
const
|
|
1776
|
+
const et = it(
|
|
1794
1777
|
async (t) => {
|
|
1795
|
-
if (!
|
|
1778
|
+
if (!De(t?.properties))
|
|
1796
1779
|
return t;
|
|
1797
1780
|
if (t?.renderer?.type === "react-component") {
|
|
1798
1781
|
const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
|
|
1799
1782
|
if (s || e && e.includes("PROPERTIES_SCHEMA"))
|
|
1800
1783
|
try {
|
|
1801
|
-
const a = await
|
|
1784
|
+
const a = await ct(
|
|
1802
1785
|
e ?? "",
|
|
1803
1786
|
"PROPERTIES_SCHEMA",
|
|
1804
1787
|
t.id,
|
|
@@ -1821,32 +1804,32 @@ const st = lt(
|
|
|
1821
1804
|
}
|
|
1822
1805
|
);
|
|
1823
1806
|
let le, Q, pe, ue;
|
|
1824
|
-
const
|
|
1807
|
+
const tt = () => jt({
|
|
1825
1808
|
types: [
|
|
1826
|
-
{ did:
|
|
1827
|
-
{ did:
|
|
1809
|
+
{ did: Ke, type: Fe },
|
|
1810
|
+
{ did: zt, type: Fe }
|
|
1828
1811
|
]
|
|
1829
|
-
}),
|
|
1830
|
-
const t =
|
|
1812
|
+
}), Ss = async () => {
|
|
1813
|
+
const t = tt(), e = {};
|
|
1831
1814
|
for (const s of t) {
|
|
1832
1815
|
const o = (await ye("**/.blocklet/pages/pages.config.yml", {
|
|
1833
1816
|
cwd: s.path,
|
|
1834
1817
|
absolute: !0
|
|
1835
1818
|
}))[0], r = o && A(M(o), "../../chunks");
|
|
1836
1819
|
if (r && await G(r)) {
|
|
1837
|
-
const l = await
|
|
1820
|
+
const l = await Dt(r);
|
|
1838
1821
|
for (const n of l)
|
|
1839
1822
|
e[n] = A(r, n);
|
|
1840
1823
|
}
|
|
1841
1824
|
}
|
|
1842
1825
|
return e;
|
|
1843
1826
|
};
|
|
1844
|
-
function
|
|
1827
|
+
function st() {
|
|
1845
1828
|
return le = (async () => {
|
|
1846
|
-
const t =
|
|
1829
|
+
const t = tt();
|
|
1847
1830
|
Q = (await Promise.all(
|
|
1848
1831
|
t.map(async (s) => {
|
|
1849
|
-
const a = s.path ? await
|
|
1832
|
+
const a = s.path ? await Ze(s.path, { importAssets: !1 }) : void 0;
|
|
1850
1833
|
return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
|
|
1851
1834
|
})
|
|
1852
1835
|
)).filter((s) => !!s), pe = Q.reduce(
|
|
@@ -1870,7 +1853,7 @@ function ot() {
|
|
|
1870
1853
|
ue = Object.fromEntries(
|
|
1871
1854
|
await Promise.all(
|
|
1872
1855
|
Object.entries(e).map(async ([s, a]) => {
|
|
1873
|
-
const o = await
|
|
1856
|
+
const o = await et(a.component);
|
|
1874
1857
|
return [
|
|
1875
1858
|
s,
|
|
1876
1859
|
{
|
|
@@ -1883,10 +1866,10 @@ function ot() {
|
|
|
1883
1866
|
);
|
|
1884
1867
|
})(), le;
|
|
1885
1868
|
}
|
|
1886
|
-
function
|
|
1887
|
-
const e =
|
|
1869
|
+
function ws(t) {
|
|
1870
|
+
const e = Re(
|
|
1888
1871
|
async () => {
|
|
1889
|
-
await
|
|
1872
|
+
await st().catch((s) => {
|
|
1890
1873
|
p.error("load resource states error", { error: s });
|
|
1891
1874
|
}), await t?.({
|
|
1892
1875
|
states: Q,
|
|
@@ -1902,12 +1885,12 @@ function Ps(t) {
|
|
|
1902
1885
|
E.events.off(E.Events.componentAdded, e), E.events.off(E.Events.componentRemoved, e), E.events.off(E.Events.componentStarted, e), E.events.off(E.Events.componentStopped, e), E.events.off(E.Events.componentUpdated, e), E.events.off(we, e);
|
|
1903
1886
|
};
|
|
1904
1887
|
}
|
|
1905
|
-
const
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
const s = await
|
|
1888
|
+
const at = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), ot = globalThis;
|
|
1889
|
+
ot[at]?.();
|
|
1890
|
+
ot[at] = ws(async ({ pages: t, components: e }) => {
|
|
1891
|
+
const s = await D.getProjectIds();
|
|
1909
1892
|
p.info(`start update resource states projects(${s.length})`, s);
|
|
1910
|
-
const a =
|
|
1893
|
+
const a = Oe(10);
|
|
1911
1894
|
await Promise.race([
|
|
1912
1895
|
new Promise((o) => {
|
|
1913
1896
|
setTimeout(() => {
|
|
@@ -1917,7 +1900,7 @@ nt[rt] = Ps(async ({ pages: t, components: e }) => {
|
|
|
1917
1900
|
Promise.all(
|
|
1918
1901
|
s.map(
|
|
1919
1902
|
(o) => a(async () => {
|
|
1920
|
-
|
|
1903
|
+
rt({
|
|
1921
1904
|
projectId: o,
|
|
1922
1905
|
pages: t,
|
|
1923
1906
|
components: e
|
|
@@ -1929,52 +1912,47 @@ nt[rt] = Ps(async ({ pages: t, components: e }) => {
|
|
|
1929
1912
|
p.error("update resource states failed:", o);
|
|
1930
1913
|
});
|
|
1931
1914
|
});
|
|
1932
|
-
|
|
1915
|
+
D.startPeriodicCheck();
|
|
1933
1916
|
process.on("beforeExit", () => {
|
|
1934
|
-
|
|
1917
|
+
D.stopPeriodicCheck();
|
|
1935
1918
|
});
|
|
1936
1919
|
process.on("SIGINT", () => {
|
|
1937
|
-
|
|
1920
|
+
D.stopPeriodicCheck(), process.exit(0);
|
|
1938
1921
|
});
|
|
1939
1922
|
process.on("SIGTERM", () => {
|
|
1940
|
-
|
|
1923
|
+
D.stopPeriodicCheck(), process.exit(0);
|
|
1941
1924
|
});
|
|
1942
|
-
async function
|
|
1925
|
+
async function rt({
|
|
1943
1926
|
projectId: t,
|
|
1944
1927
|
pages: e,
|
|
1945
1928
|
components: s
|
|
1946
1929
|
}) {
|
|
1947
|
-
const a =
|
|
1930
|
+
const a = D.sharedInstances[t];
|
|
1948
1931
|
if (!a) {
|
|
1949
1932
|
p.info(`projectId: ${t} not found in sharedInstances`);
|
|
1950
1933
|
return;
|
|
1951
1934
|
}
|
|
1952
|
-
const o =
|
|
1935
|
+
const o = await U.findByPk(t, {
|
|
1953
1936
|
attributes: { exclude: ["productionState", "relatedBlocklets"] }
|
|
1954
1937
|
});
|
|
1955
|
-
let
|
|
1956
|
-
if (
|
|
1957
|
-
|
|
1938
|
+
let r;
|
|
1939
|
+
if (o?.useAllResources)
|
|
1940
|
+
r = s;
|
|
1958
1941
|
else {
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1942
|
+
const n = (await ve.findAll({ where: { projectId: t } })).map((c) => c.componentId);
|
|
1943
|
+
r = Object.fromEntries(Object.entries(s || {}).filter(([c]) => n.includes(c)));
|
|
1961
1944
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
`[${t}] components resources updated: ${Object.keys(n || {}).length} components`
|
|
1966
|
-
));
|
|
1967
|
-
}) : p.info(`[${t}] resource states unchanged, skipping update`), p.info(`update [${t}] resource states summary:`, {
|
|
1945
|
+
a.transact(() => {
|
|
1946
|
+
a.syncedStore.resources.pages = e, p.info(`[${t}] pages resources updated: ${Object.keys(e || {}).length} pages`), a.syncedStore.resources.components = r, p.info(`[${t}] components resources updated: ${Object.keys(r || {}).length} components`);
|
|
1947
|
+
}), p.info(`update [${t}] resource states summary:`, {
|
|
1968
1948
|
pages: Object.keys(a.syncedStore.resources.pages || {}).length,
|
|
1969
|
-
components: Object.keys(a.syncedStore.resources.components || {}).length
|
|
1970
|
-
pagesChanged: c,
|
|
1971
|
-
componentsChanged: f
|
|
1949
|
+
components: Object.keys(a.syncedStore.resources.components || {}).length
|
|
1972
1950
|
});
|
|
1973
1951
|
}
|
|
1974
1952
|
const he = /* @__PURE__ */ new Map();
|
|
1975
|
-
async function
|
|
1953
|
+
async function Is(t) {
|
|
1976
1954
|
if (!he.has(t)) {
|
|
1977
|
-
const e =
|
|
1955
|
+
const e = Re(async (s) => rt({
|
|
1978
1956
|
projectId: s,
|
|
1979
1957
|
pages: pe,
|
|
1980
1958
|
components: ue
|
|
@@ -1983,31 +1961,31 @@ async function bs(t) {
|
|
|
1983
1961
|
}
|
|
1984
1962
|
return he.get(t)(t);
|
|
1985
1963
|
}
|
|
1986
|
-
async function
|
|
1964
|
+
async function ra() {
|
|
1987
1965
|
p.info("trigger reload all project resource"), E.events.emit(we);
|
|
1988
1966
|
}
|
|
1989
|
-
async function
|
|
1967
|
+
async function na({
|
|
1990
1968
|
ensureLoaded: t = !0
|
|
1991
1969
|
} = {}) {
|
|
1992
|
-
return t && (le ??=
|
|
1970
|
+
return t && (le ??= st(), await le), { states: Q, pages: pe, components: ue };
|
|
1993
1971
|
}
|
|
1994
1972
|
export {
|
|
1995
|
-
|
|
1973
|
+
Ke as C,
|
|
1996
1974
|
U as P,
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
1975
|
+
Fe as R,
|
|
1976
|
+
D as S,
|
|
1977
|
+
H as a,
|
|
1978
|
+
aa as b,
|
|
1979
|
+
sa as c,
|
|
1980
|
+
oa as d,
|
|
1981
|
+
fs as e,
|
|
1982
|
+
gs as f,
|
|
1983
|
+
na as g,
|
|
1984
|
+
hs as h,
|
|
1985
|
+
Ze as i,
|
|
1986
|
+
ws as j,
|
|
1987
|
+
ra as k,
|
|
1988
|
+
Ve as m,
|
|
1989
|
+
ys as t,
|
|
1990
|
+
Is as u
|
|
2013
1991
|
};
|