@blocklet/pages-kit-inner-components 0.7.4 → 0.7.5
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-D9DYye_t.js +1 -0
- package/lib/cjs/locales.js +2 -2
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/chunks/{site-state-zNlcYOxL.js → site-state-Ct2OR_RE.js} +570 -517
- package/lib/es/locales.js +17 -1
- 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-DApZigAR.js +0 -1
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { d as Je, l as
|
|
1
|
+
import { d as Je, l as p, m as lt, b as pt, I as ut, c as dt } from "./components-CcZk17uO.js";
|
|
2
2
|
import { getYjsValue as J, syncedStore as ft } from "@syncedstore/core";
|
|
3
3
|
import * as F from "yjs";
|
|
4
4
|
import { setPageDataSource as mt } from "@blocklet/pages-kit/utils/data-source";
|
|
5
|
-
import { getRouteMetaDataByOptionIds as gt, generateParamCombinations as
|
|
6
|
-
import
|
|
7
|
-
import { DataTypes as P, Sequelize as ht, Model as
|
|
5
|
+
import { getRouteMetaDataByOptionIds as gt, generateParamCombinations as be } from "@blocklet/pages-kit/utils/route";
|
|
6
|
+
import Ae from "lodash/cloneDeep";
|
|
7
|
+
import { DataTypes as P, Sequelize as ht, 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 Oe, withLeadingSlash as He, joinURL as
|
|
10
|
+
import { withoutTrailingSlash as Oe, withLeadingSlash as He, joinURL as x } from "ufo";
|
|
11
11
|
import { union as yt } from "lodash";
|
|
12
12
|
import Le from "crypto";
|
|
13
13
|
import z, { mkdtempSync as St, existsSync as wt, readFileSync as It, createWriteStream as Pt } from "fs";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { nextId as
|
|
14
|
+
import Re from "p-limit";
|
|
15
|
+
import $e, { join as b, basename as $, dirname as M } from "path";
|
|
16
|
+
import { nextId as Ue } from "@blocklet/pages-kit/utils/common";
|
|
17
17
|
import { unzipSection as bt } from "@blocklet/pages-kit/utils/page-model";
|
|
18
18
|
import { getComponentDependencies as At } from "@blocklet/pages-kit/utils/property";
|
|
19
|
-
import { getComponentWebEndpoint as Et, getResources as Ot, call as
|
|
20
|
-
import { reactive as
|
|
21
|
-
import { rename as
|
|
22
|
-
import { globSync as kt, glob as
|
|
23
|
-
import * as
|
|
19
|
+
import { getComponentWebEndpoint as Et, getResources as Ot, call as Rt } from "@blocklet/sdk/lib/component";
|
|
20
|
+
import { reactive as Ct } from "@reactivedata/reactive";
|
|
21
|
+
import { rename as Ne, mkdir as B, rm as Ke, writeFile as ne, lstat as oe, readFile as te, copyFile as jt, readdir as Dt } from "fs/promises";
|
|
22
|
+
import { globSync as kt, glob as ye } from "glob";
|
|
23
|
+
import * as fe from "lib0/decoding";
|
|
24
24
|
import * as v from "lib0/encoding";
|
|
25
|
-
import
|
|
25
|
+
import Ce from "lodash/debounce";
|
|
26
26
|
import je from "lodash/get";
|
|
27
27
|
import De from "lodash/isEmpty";
|
|
28
28
|
import Me from "lodash/set";
|
|
@@ -30,8 +30,8 @@ import vt from "lodash/union";
|
|
|
30
30
|
import { LRUCache as We } from "lru-cache";
|
|
31
31
|
import { pipeline as Tt } from "stream/promises";
|
|
32
32
|
import { x as Lt } from "tar";
|
|
33
|
-
import
|
|
34
|
-
import { Awareness as
|
|
33
|
+
import $t from "wait-on";
|
|
34
|
+
import { Awareness as Ut, encodeAwarenessUpdate as _e, removeAwarenessStates as Nt, applyAwarenessUpdate as Mt } from "y-protocols/awareness";
|
|
35
35
|
import { writeUpdate as _t, writeSyncStep1 as Ft, readSyncMessage as xt } from "y-protocols/sync";
|
|
36
36
|
import * as q from "yaml";
|
|
37
37
|
import { m as Fe } from "./html-CNFwwbdj.js";
|
|
@@ -75,17 +75,17 @@ async function Gt(t, e) {
|
|
|
75
75
|
console.error("Failed to cleanup SQLite memory", e, s);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
let Se = null;
|
|
79
|
+
Se && clearInterval(Se);
|
|
80
|
+
Se = setInterval(
|
|
81
81
|
async () => {
|
|
82
|
-
|
|
82
|
+
p.info("Start cleanupSqliteMemory"), await Gt(_, Je), p.info("End cleanupSqliteMemory");
|
|
83
83
|
},
|
|
84
84
|
60 * 1e3 * 10
|
|
85
85
|
// 10 minutes
|
|
86
86
|
);
|
|
87
|
-
const Vt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", xe = "page",
|
|
88
|
-
class ke extends
|
|
87
|
+
const Vt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", xe = "page", we = "trigger-reload-project-resource", Ye = Vt, zt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", qt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
|
|
88
|
+
class ke extends Ee {
|
|
89
89
|
// Foreign key to Component
|
|
90
90
|
}
|
|
91
91
|
ke.init(
|
|
@@ -144,11 +144,11 @@ const Jt = "SLUG_INVALID", K = (t) => ({
|
|
|
144
144
|
const e = Oe(t);
|
|
145
145
|
return He(e) || "/";
|
|
146
146
|
}, Yt = (t) => t.did === qt;
|
|
147
|
-
class
|
|
147
|
+
class U extends Ee {
|
|
148
148
|
static async getProjectByIdOrSlug(e, s) {
|
|
149
|
-
return e ?
|
|
149
|
+
return e ? U.findOne({
|
|
150
150
|
where: {
|
|
151
|
-
[
|
|
151
|
+
[Z.or]: [{ id: e }, { slug: e }],
|
|
152
152
|
...s?.createdBy ? { createdBy: s.createdBy } : {}
|
|
153
153
|
}
|
|
154
154
|
}) : null;
|
|
@@ -172,13 +172,13 @@ class $ extends Ae {
|
|
|
172
172
|
return K((r) => `Project slug "${r}" contains invalid characters`);
|
|
173
173
|
if (E.components?.filter((r) => r.mountPoint && !Yt(r)).some((r) => Be(r.mountPoint) === o))
|
|
174
174
|
return K((r) => `Project slug "${r}" conflicts with existing blocklet`);
|
|
175
|
-
const l = await
|
|
175
|
+
const l = await U.findOne({
|
|
176
176
|
where: { slug: a }
|
|
177
177
|
});
|
|
178
178
|
return l && l?.id !== s ? Kt : null;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
U.init(
|
|
182
182
|
{
|
|
183
183
|
id: {
|
|
184
184
|
type: P.UUID,
|
|
@@ -216,14 +216,14 @@ $.init(
|
|
|
216
216
|
try {
|
|
217
217
|
return t ? JSON.parse(t) : {};
|
|
218
218
|
} catch (e) {
|
|
219
|
-
return
|
|
219
|
+
return p.error("Failed to parse relatedBlocklets", { error: e, rawValue: t }), {};
|
|
220
220
|
}
|
|
221
221
|
},
|
|
222
222
|
set(t) {
|
|
223
223
|
try {
|
|
224
224
|
this.setDataValue("relatedBlocklets", t ? JSON.stringify(t) : "{}");
|
|
225
225
|
} catch (e) {
|
|
226
|
-
|
|
226
|
+
p.error("Failed to set relatedBlocklets", { error: e, value: t }), this.setDataValue("relatedBlocklets", "{}");
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
},
|
|
@@ -238,14 +238,14 @@ $.init(
|
|
|
238
238
|
try {
|
|
239
239
|
return t ? JSON.parse(t) : {};
|
|
240
240
|
} catch (e) {
|
|
241
|
-
return
|
|
241
|
+
return p.error("Failed to parse productionState", { error: e, rawValue: t }), {};
|
|
242
242
|
}
|
|
243
243
|
},
|
|
244
244
|
set(t) {
|
|
245
245
|
try {
|
|
246
246
|
this.setDataValue("productionState", t ? JSON.stringify(t) : "{}");
|
|
247
247
|
} catch (e) {
|
|
248
|
-
|
|
248
|
+
p.error("Failed to set productionState", { error: e, value: t }), this.setDataValue("productionState", "{}");
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
},
|
|
@@ -275,18 +275,18 @@ $.init(
|
|
|
275
275
|
],
|
|
276
276
|
where: {
|
|
277
277
|
meta: {
|
|
278
|
-
[
|
|
278
|
+
[Z.ne]: null
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
]
|
|
283
283
|
}
|
|
284
284
|
);
|
|
285
|
-
|
|
285
|
+
U.hasMany(ke, {
|
|
286
286
|
foreignKey: "projectId",
|
|
287
287
|
as: "components"
|
|
288
288
|
});
|
|
289
|
-
async function
|
|
289
|
+
async function G(t) {
|
|
290
290
|
try {
|
|
291
291
|
return await z.promises.access(t, z.constants.F_OK), !0;
|
|
292
292
|
} catch {
|
|
@@ -303,16 +303,16 @@ async function Qe(t, e) {
|
|
|
303
303
|
await z.promises.mkdir(e, { recursive: !0 });
|
|
304
304
|
const s = await z.promises.readdir(t, { withFileTypes: !0 });
|
|
305
305
|
for (const a of s) {
|
|
306
|
-
const o =
|
|
306
|
+
const o = $e.join(t, a.name), n = $e.join(e, a.name);
|
|
307
307
|
a.isDirectory() ? await Qe(o, n) : await Xe(o, n);
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
|
-
async function
|
|
310
|
+
async function Zs(t, e) {
|
|
311
311
|
(await z.promises.stat(t)).isDirectory() ? await Qe(t, e) : await Xe(t, e);
|
|
312
312
|
}
|
|
313
|
-
class
|
|
313
|
+
class ee extends Ee {
|
|
314
314
|
}
|
|
315
|
-
|
|
315
|
+
ee.init(
|
|
316
316
|
{
|
|
317
317
|
id: {
|
|
318
318
|
type: P.UUID,
|
|
@@ -414,49 +414,123 @@ function Xt(t) {
|
|
|
414
414
|
const { projectId: e, projectSlug: s, state: a } = t, o = s || e, n = yt(
|
|
415
415
|
E.env.languages?.map((i) => i.code) || [],
|
|
416
416
|
a.supportedLocales?.map((i) => i.locale) || []
|
|
417
|
-
), l = {}, r = (i,
|
|
418
|
-
o && (l[
|
|
419
|
-
...
|
|
417
|
+
), l = {}, r = (i, f) => {
|
|
418
|
+
o && (l[x("/", o, i)] = {
|
|
419
|
+
...f,
|
|
420
420
|
shouldRedirect: !0,
|
|
421
421
|
mainPage: !0
|
|
422
|
-
}), l[
|
|
423
|
-
...
|
|
422
|
+
}), l[x("/", e, i)] = {
|
|
423
|
+
...f,
|
|
424
424
|
shouldRedirect: !0,
|
|
425
425
|
mainPage: !0
|
|
426
426
|
};
|
|
427
|
-
for (const
|
|
428
|
-
const
|
|
429
|
-
l[
|
|
427
|
+
for (const A of n) {
|
|
428
|
+
const R = { ...f, locale: A };
|
|
429
|
+
l[x("/", A, e, i)] = R, o && (l[x("/", A, o, i)] = R);
|
|
430
430
|
}
|
|
431
431
|
};
|
|
432
432
|
for (const i of a.pageIds || []) {
|
|
433
|
-
const
|
|
434
|
-
if (!
|
|
433
|
+
const f = a.pages?.[i];
|
|
434
|
+
if (!f || !f.isPublic)
|
|
435
435
|
continue;
|
|
436
|
-
const
|
|
436
|
+
const A = {
|
|
437
437
|
projectId: e,
|
|
438
438
|
projectSlug: o,
|
|
439
|
-
pageSlug:
|
|
439
|
+
pageSlug: f.slug,
|
|
440
440
|
pageId: i,
|
|
441
441
|
defaultLocale: n?.[0],
|
|
442
442
|
locales: n,
|
|
443
443
|
publishedAt: a.config?.publishedAt,
|
|
444
|
-
isPublic:
|
|
444
|
+
isPublic: f.isPublic
|
|
445
445
|
};
|
|
446
|
-
r(
|
|
446
|
+
r(f.slug, A);
|
|
447
447
|
}
|
|
448
448
|
return l;
|
|
449
449
|
}
|
|
450
|
-
function
|
|
450
|
+
async function Qt(t, e, s) {
|
|
451
|
+
const a = t.map((n) => n.urlPath), o = await ee.findAll({
|
|
452
|
+
where: {
|
|
453
|
+
urlPath: {
|
|
454
|
+
[Z.in]: a
|
|
455
|
+
},
|
|
456
|
+
projectId: {
|
|
457
|
+
[Z.ne]: e
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
attributes: ["urlPath", "projectId", "projectSlug", "pageSlug"],
|
|
461
|
+
transaction: s,
|
|
462
|
+
raw: !0
|
|
463
|
+
});
|
|
464
|
+
if (o.length > 0) {
|
|
465
|
+
p.warn(
|
|
466
|
+
`[URL Duplicate Warning] Found ${o.length} URL conflicts for project ${e}:`
|
|
467
|
+
);
|
|
468
|
+
for (const n of o) {
|
|
469
|
+
const l = t.find((r) => r.urlPath === n.urlPath);
|
|
470
|
+
if (l) {
|
|
471
|
+
const r = n.projectSlug ? x(n.projectSlug, n.pageSlug) : n.pageSlug;
|
|
472
|
+
p.warn(
|
|
473
|
+
` - URL "${n.urlPath}" conflicts with project ${n.projectId} (${r}). Current project trying to use same URL for page: ${l.pageSlug}`
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
p.warn(
|
|
478
|
+
"[URL Duplicate Warning] These duplicate URLs will be ignored during save. Consider using different project slugs or page slugs to avoid conflicts."
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
async function Zt(t) {
|
|
483
|
+
const { projectId: e, transaction: s } = t;
|
|
484
|
+
try {
|
|
485
|
+
await ee.destroy({
|
|
486
|
+
where: { projectId: e },
|
|
487
|
+
transaction: s
|
|
488
|
+
});
|
|
489
|
+
const a = Xt(t), o = Object.entries(a).map(([n, l]) => ({
|
|
490
|
+
projectId: e,
|
|
491
|
+
urlPath: n,
|
|
492
|
+
projectSlug: l.projectSlug,
|
|
493
|
+
pageSlug: l.pageSlug,
|
|
494
|
+
pageId: l.pageId,
|
|
495
|
+
routeId: l.routeId,
|
|
496
|
+
locale: l.locale,
|
|
497
|
+
defaultLocale: l.defaultLocale,
|
|
498
|
+
shouldRedirect: l.shouldRedirect,
|
|
499
|
+
mainPage: l.mainPage,
|
|
500
|
+
isPublic: l.isPublic,
|
|
501
|
+
publishedAt: typeof l.publishedAt == "number" ? l.publishedAt : void 0,
|
|
502
|
+
locales: l.locales
|
|
503
|
+
}));
|
|
504
|
+
if (o.length > 0) {
|
|
505
|
+
await Qt(o, e, s);
|
|
506
|
+
const n = 100, l = [];
|
|
507
|
+
for (let r = 0; r < o.length; r += n) {
|
|
508
|
+
const i = o.slice(r, r + n);
|
|
509
|
+
l.push(
|
|
510
|
+
ee.bulkCreate(i, {
|
|
511
|
+
transaction: s,
|
|
512
|
+
ignoreDuplicates: !0
|
|
513
|
+
// 忽略重复数据,避免因脏数据导致整批插入失败
|
|
514
|
+
})
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
await Promise.all(l), p.info(`Regenerated ${o.length} URL mappings for project ${e}`);
|
|
518
|
+
}
|
|
519
|
+
return o.length;
|
|
520
|
+
} catch (a) {
|
|
521
|
+
throw p.error(`Failed to regenerate URL mappings for project ${e}:`, a), a;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function re(t) {
|
|
451
525
|
t.observeDeep((e) => {
|
|
452
526
|
e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
453
527
|
});
|
|
454
528
|
}
|
|
455
529
|
function Ze() {
|
|
456
|
-
return St(
|
|
530
|
+
return St(b(E.env.dataDir, "tmp-"));
|
|
457
531
|
}
|
|
458
|
-
function
|
|
459
|
-
return Array.isArray(t) ? t.flatMap((a, o) =>
|
|
532
|
+
function ie(t, e, s = []) {
|
|
533
|
+
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] : [];
|
|
460
534
|
}
|
|
461
535
|
function L(t) {
|
|
462
536
|
return t.filter((e) => e != null);
|
|
@@ -478,37 +552,37 @@ function Ge(t, e) {
|
|
|
478
552
|
const o = Le.createHash("md5").update(JSON.stringify(t, Object.keys(t).sort())).digest("hex"), n = Le.createHash("md5").update(JSON.stringify(e, Object.keys(e).sort())).digest("hex");
|
|
479
553
|
return o === n;
|
|
480
554
|
}
|
|
481
|
-
function
|
|
555
|
+
function es(t) {
|
|
482
556
|
t.pages && Object.keys(t.pages).forEach((s) => {
|
|
483
557
|
const a = J(t.pages[s]);
|
|
484
|
-
a && a instanceof F.Map &&
|
|
558
|
+
a && a instanceof F.Map && re(a);
|
|
485
559
|
});
|
|
486
560
|
const e = J(t.pages);
|
|
487
561
|
e && e instanceof F.Map && e.observe((s) => {
|
|
488
562
|
s.changes.keys.forEach((a, o) => {
|
|
489
563
|
if (a.action === "add") {
|
|
490
564
|
const n = J(t.pages[o]);
|
|
491
|
-
n && n instanceof F.Map &&
|
|
565
|
+
n && n instanceof F.Map && re(n);
|
|
492
566
|
}
|
|
493
567
|
});
|
|
494
568
|
});
|
|
495
569
|
}
|
|
496
|
-
function
|
|
570
|
+
function ts(t) {
|
|
497
571
|
t.routes && Object.keys(t.routes).forEach((s) => {
|
|
498
572
|
const a = J(t.routes?.[s]);
|
|
499
|
-
a && a instanceof F.Map &&
|
|
573
|
+
a && a instanceof F.Map && re(a);
|
|
500
574
|
});
|
|
501
575
|
const e = J(t.routes);
|
|
502
576
|
e && e instanceof F.Map && e.observe((s) => {
|
|
503
577
|
s.changes.keys.forEach((a, o) => {
|
|
504
578
|
if (a.action === "add") {
|
|
505
579
|
const n = J(t.routes?.[o]);
|
|
506
|
-
n && n instanceof F.Map &&
|
|
580
|
+
n && n instanceof F.Map && re(n);
|
|
507
581
|
}
|
|
508
582
|
});
|
|
509
583
|
});
|
|
510
584
|
}
|
|
511
|
-
function
|
|
585
|
+
function ss(t, e) {
|
|
512
586
|
for (const s of e || Object.keys(t.routes || {})) {
|
|
513
587
|
let a = s, o = [];
|
|
514
588
|
if (s.includes("-")) {
|
|
@@ -525,7 +599,7 @@ function es(t, e) {
|
|
|
525
599
|
l && (l.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
526
600
|
}
|
|
527
601
|
if (!e) {
|
|
528
|
-
const l =
|
|
602
|
+
const l = be({
|
|
529
603
|
basePath: n.path,
|
|
530
604
|
params: n.params,
|
|
531
605
|
routeId: n.id,
|
|
@@ -541,18 +615,18 @@ function es(t, e) {
|
|
|
541
615
|
}
|
|
542
616
|
}
|
|
543
617
|
}
|
|
544
|
-
function
|
|
618
|
+
function me({
|
|
545
619
|
page: t,
|
|
546
620
|
route: e,
|
|
547
621
|
state: s,
|
|
548
622
|
routeId: a,
|
|
549
623
|
routePathInfo: o
|
|
550
624
|
}) {
|
|
551
|
-
|
|
625
|
+
p.info(
|
|
552
626
|
`Executing datasource data assembly, routeId: ${a}, routePathInfo: ${JSON.stringify(o)}`
|
|
553
627
|
);
|
|
554
628
|
const n = {
|
|
555
|
-
...
|
|
629
|
+
...Ae(t),
|
|
556
630
|
id: a,
|
|
557
631
|
slug: o?.path ?? e.path,
|
|
558
632
|
createdAt: e.createdAt,
|
|
@@ -574,41 +648,41 @@ function fe({
|
|
|
574
648
|
return n;
|
|
575
649
|
}
|
|
576
650
|
["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
|
|
577
|
-
const
|
|
651
|
+
const as = 60 * 60 * 1e3, Y = new We({
|
|
578
652
|
max: 300,
|
|
579
|
-
ttl:
|
|
653
|
+
ttl: as,
|
|
580
654
|
ttlResolution: 10 * 1e3,
|
|
581
655
|
// 10 seconds
|
|
582
656
|
allowStale: !0
|
|
583
657
|
});
|
|
584
|
-
function
|
|
658
|
+
function os(t, e = []) {
|
|
585
659
|
let s = 0;
|
|
586
660
|
const a = Array.from(Y.keys()), o = t.map((n) => Oe(n));
|
|
587
661
|
for (const n of a)
|
|
588
662
|
for (const l of o) {
|
|
589
663
|
if (Fe(n, { currentPath: l })) {
|
|
590
|
-
Y.delete(n), s++,
|
|
664
|
+
Y.delete(n), s++, p.info(`[Cache CLEAR] key: ${n}`);
|
|
591
665
|
break;
|
|
592
666
|
}
|
|
593
667
|
for (const r of e)
|
|
594
668
|
if (Fe(n, { currentPath: `/${r}${l}` })) {
|
|
595
|
-
Y.delete(n), s++,
|
|
669
|
+
Y.delete(n), s++, p.info(`[Cache CLEAR] key: ${n}`);
|
|
596
670
|
break;
|
|
597
671
|
}
|
|
598
672
|
}
|
|
599
|
-
return
|
|
673
|
+
return p.info(`[Cache CLEAR] cleared ${s} entries for paths:`, o), s;
|
|
600
674
|
}
|
|
601
|
-
function
|
|
675
|
+
function ns() {
|
|
602
676
|
const t = Y.size;
|
|
603
|
-
return Y.clear(),
|
|
677
|
+
return Y.clear(), p.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
|
|
604
678
|
}
|
|
605
|
-
E.events.on(E.Events.envUpdate,
|
|
606
|
-
const { uploadToMediaKit:
|
|
607
|
-
function
|
|
679
|
+
E.events.on(E.Events.envUpdate, ns);
|
|
680
|
+
const { uploadToMediaKit: rs } = require("@blocklet/uploader-server"), ve = /^\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, Ve = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, is = 1e4, cs = 3e4, se = 0, ge = 1, ls = 0, ps = 1, Ie = E, W = b(process.env.BLOCKLET_DATA_DIR, "site-state"), ea = ["production", "draft"], ta = ["production"];
|
|
681
|
+
function ce(t) {
|
|
608
682
|
return t?.replace(/\//g, "|") || "";
|
|
609
683
|
}
|
|
610
|
-
function
|
|
611
|
-
const t =
|
|
684
|
+
function us() {
|
|
685
|
+
const t = Ie.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
|
|
612
686
|
return {
|
|
613
687
|
pageIds: [],
|
|
614
688
|
pages: {},
|
|
@@ -624,7 +698,7 @@ function ls() {
|
|
|
624
698
|
}
|
|
625
699
|
class D extends F.Doc {
|
|
626
700
|
constructor(e) {
|
|
627
|
-
super(), this.options = e, wt(this.draftYjsFilePath) && F.applyUpdate(this, It(this.draftYjsFilePath)), this.syncedStore =
|
|
701
|
+
super(), this.options = e, wt(this.draftYjsFilePath) && F.applyUpdate(this, It(this.draftYjsFilePath)), this.syncedStore = Ct(
|
|
628
702
|
ft(
|
|
629
703
|
{
|
|
630
704
|
pages: {},
|
|
@@ -640,7 +714,7 @@ class D extends F.Doc {
|
|
|
640
714
|
},
|
|
641
715
|
this
|
|
642
716
|
)
|
|
643
|
-
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new
|
|
717
|
+
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Ut(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
|
|
644
718
|
}
|
|
645
719
|
// 延迟释放时间:5 分钟
|
|
646
720
|
static RELEASE_DELAY = 5 * 60 * 1e3;
|
|
@@ -655,14 +729,14 @@ class D extends F.Doc {
|
|
|
655
729
|
if (!e)
|
|
656
730
|
throw new Error("Should provide project context");
|
|
657
731
|
try {
|
|
658
|
-
const s =
|
|
659
|
-
await
|
|
732
|
+
const s = b(W, e), a = b(W, `@del-${e}`);
|
|
733
|
+
await Ne(s, a);
|
|
660
734
|
} catch (s) {
|
|
661
|
-
|
|
735
|
+
p.error("Failed to safe delete project state dir:", s);
|
|
662
736
|
}
|
|
663
737
|
}
|
|
664
738
|
static async getProjectIds() {
|
|
665
|
-
return (await
|
|
739
|
+
return (await U.findAll({ attributes: ["id"], raw: !0 }))?.map((e) => e.id);
|
|
666
740
|
}
|
|
667
741
|
/** @deprecated 不再使用这个 getter 了,仅作为兼容性处理,请使用 getProjectIds 代替 */
|
|
668
742
|
static get projectIds() {
|
|
@@ -681,19 +755,19 @@ class D extends F.Doc {
|
|
|
681
755
|
throw new Error("Should provide project context");
|
|
682
756
|
let s = D.sharedInstances[e];
|
|
683
757
|
return s || (s = new D({
|
|
684
|
-
path:
|
|
758
|
+
path: b(W, e)
|
|
685
759
|
}), D.sharedInstances[e] = s, s);
|
|
686
760
|
}
|
|
687
761
|
// 轻量级 production 状态获取,不加载 draft 数据
|
|
688
762
|
static async getProductionState(e) {
|
|
689
|
-
const s = await
|
|
763
|
+
const s = await U.findByPk(e, {
|
|
690
764
|
attributes: ["productionState"]
|
|
691
765
|
});
|
|
692
766
|
if (De(s?.productionState)) {
|
|
693
|
-
const a =
|
|
767
|
+
const a = b(W, e, "production"), o = await tt(a, { includeResources: !0 }) ?? us();
|
|
694
768
|
if (!o?.config?.defaultLocale) {
|
|
695
769
|
o.config ??= {};
|
|
696
|
-
const n =
|
|
770
|
+
const n = Ie.env.languages?.map((l) => ({ locale: l.code, name: l.name })) || [];
|
|
697
771
|
o.config.defaultLocale = n[0]?.locale;
|
|
698
772
|
}
|
|
699
773
|
return o;
|
|
@@ -702,14 +776,14 @@ class D extends F.Doc {
|
|
|
702
776
|
}
|
|
703
777
|
destroy() {
|
|
704
778
|
this.cancelRelease(), this.save({ flush: !0 }), this.conns.forEach((s, a) => this.closeConn(a)), this.awareness.destroy();
|
|
705
|
-
const e =
|
|
779
|
+
const e = $(this.options.path);
|
|
706
780
|
delete D.sharedInstances[e], super.destroy();
|
|
707
781
|
}
|
|
708
782
|
initObserver() {
|
|
709
|
-
|
|
783
|
+
es(this.syncedStore), ts(this.syncedStore);
|
|
710
784
|
}
|
|
711
785
|
get draftYjsFilePath() {
|
|
712
|
-
return
|
|
786
|
+
return b(this.options.path, "draft.yjs");
|
|
713
787
|
}
|
|
714
788
|
static async getStateByProjectId({
|
|
715
789
|
projectId: e,
|
|
@@ -725,51 +799,30 @@ class D extends F.Doc {
|
|
|
725
799
|
async getState(e) {
|
|
726
800
|
if (e === "draft")
|
|
727
801
|
return JSON.parse(JSON.stringify(this.syncedStore));
|
|
728
|
-
const s =
|
|
802
|
+
const s = $(this.options.path);
|
|
729
803
|
return D.getProductionState(s);
|
|
730
804
|
}
|
|
731
805
|
async setState(e, s) {
|
|
732
|
-
const a = await
|
|
733
|
-
if (await
|
|
734
|
-
const n =
|
|
806
|
+
const a = await gs(s, { exportAssets: !1, includeResources: !0 }), o = this.getPublishDir(e);
|
|
807
|
+
if (await B(M(o), { recursive: !0 }), await Ke(o, { force: !0, recursive: !0 }), await Ne(a, o), e === "production") {
|
|
808
|
+
const n = $(this.options.path), l = Ae(s);
|
|
735
809
|
await _.transaction(async (r) => {
|
|
736
|
-
await
|
|
737
|
-
const i = await
|
|
810
|
+
await U.update({ productionState: l }, { where: { id: n }, transaction: r });
|
|
811
|
+
const i = await U.findByPk(n, {
|
|
738
812
|
attributes: ["slug"],
|
|
739
813
|
transaction: r
|
|
740
|
-
}),
|
|
814
|
+
}), f = await Zt({
|
|
741
815
|
projectId: n,
|
|
742
816
|
projectSlug: i?.slug,
|
|
743
|
-
state: s
|
|
744
|
-
});
|
|
745
|
-
await ae.destroy({
|
|
746
|
-
where: { projectId: n },
|
|
817
|
+
state: s,
|
|
747
818
|
transaction: r
|
|
748
819
|
});
|
|
749
|
-
|
|
750
|
-
projectId: n,
|
|
751
|
-
urlPath: O,
|
|
752
|
-
projectSlug: p.projectSlug,
|
|
753
|
-
pageSlug: p.pageSlug,
|
|
754
|
-
pageId: p.pageId,
|
|
755
|
-
routeId: p.routeId,
|
|
756
|
-
locale: p.locale,
|
|
757
|
-
defaultLocale: p.defaultLocale,
|
|
758
|
-
shouldRedirect: p.shouldRedirect,
|
|
759
|
-
mainPage: p.mainPage,
|
|
760
|
-
isPublic: p.isPublic,
|
|
761
|
-
publishedAt: p.publishedAt,
|
|
762
|
-
locales: p.locales
|
|
763
|
-
}));
|
|
764
|
-
if (b.length > 0)
|
|
765
|
-
for (let p = 0; p < b.length; p += 100)
|
|
766
|
-
await ae.bulkCreate(b.slice(p, p + 100), { transaction: r });
|
|
767
|
-
u.info(`[SiteState] saved ${b.length} URL mappings for project ${n}`);
|
|
820
|
+
p.info(`[SiteState] saved ${f} URL mappings for project ${n}`);
|
|
768
821
|
});
|
|
769
822
|
}
|
|
770
823
|
}
|
|
771
824
|
getPublishDir(e) {
|
|
772
|
-
return
|
|
825
|
+
return b(this.options.path, e);
|
|
773
826
|
}
|
|
774
827
|
syncedStore;
|
|
775
828
|
conns = /* @__PURE__ */ new Map();
|
|
@@ -780,20 +833,20 @@ class D extends F.Doc {
|
|
|
780
833
|
const n = e.concat(s, a);
|
|
781
834
|
if (o !== null) {
|
|
782
835
|
const i = this.conns.get(o);
|
|
783
|
-
i && (e.forEach((
|
|
784
|
-
i.add(
|
|
785
|
-
}), a.forEach((
|
|
786
|
-
i.delete(
|
|
836
|
+
i && (e.forEach((f) => {
|
|
837
|
+
i.add(f);
|
|
838
|
+
}), a.forEach((f) => {
|
|
839
|
+
i.delete(f);
|
|
787
840
|
}));
|
|
788
841
|
}
|
|
789
842
|
const l = v.createEncoder();
|
|
790
|
-
v.writeVarUint(l,
|
|
843
|
+
v.writeVarUint(l, ge), v.writeVarUint8Array(l, _e(this.awareness, n));
|
|
791
844
|
const r = v.toUint8Array(l);
|
|
792
|
-
this.conns.forEach((i,
|
|
845
|
+
this.conns.forEach((i, f) => this.send(f, r));
|
|
793
846
|
};
|
|
794
847
|
updateHandler = (e) => {
|
|
795
848
|
const s = v.createEncoder();
|
|
796
|
-
v.writeVarUint(s,
|
|
849
|
+
v.writeVarUint(s, se), _t(s, e);
|
|
797
850
|
const a = v.toUint8Array(s);
|
|
798
851
|
this.conns.forEach((o, n) => this.send(n, a));
|
|
799
852
|
};
|
|
@@ -804,31 +857,31 @@ class D extends F.Doc {
|
|
|
804
857
|
const r = new Set(Object.keys(s));
|
|
805
858
|
let i = 0;
|
|
806
859
|
for (; i < a.length; ) {
|
|
807
|
-
const
|
|
808
|
-
r.has(
|
|
860
|
+
const f = a[i];
|
|
861
|
+
r.has(f) ? (r.delete(f), i++) : a.splice(i, 1);
|
|
809
862
|
}
|
|
810
863
|
}
|
|
811
864
|
{
|
|
812
865
|
const r = new Set(Object.keys(n));
|
|
813
866
|
let i = 0;
|
|
814
867
|
for (; i < l.length; ) {
|
|
815
|
-
const
|
|
816
|
-
r.has(
|
|
868
|
+
const f = l[i];
|
|
869
|
+
r.has(f) ? (r.delete(f), i++) : l.splice(i, 1);
|
|
817
870
|
}
|
|
818
871
|
}
|
|
819
|
-
e.splice(0, e.length), e.push(...
|
|
872
|
+
e.splice(0, e.length), e.push(...Ie.env.languages.map((r) => ({ locale: r.code, name: r.name }))), o.defaultLocale = e[0]?.locale;
|
|
820
873
|
{
|
|
821
874
|
let r = 0;
|
|
822
875
|
const i = /* @__PURE__ */ new Set();
|
|
823
876
|
for (; r < e.length; ) {
|
|
824
|
-
const { locale:
|
|
825
|
-
i.has(
|
|
877
|
+
const { locale: f } = e[r];
|
|
878
|
+
i.has(f) ? e.splice(r, 1) : (r++, i.add(f));
|
|
826
879
|
}
|
|
827
880
|
}
|
|
828
881
|
});
|
|
829
882
|
};
|
|
830
883
|
send = (e, s) => {
|
|
831
|
-
e.readyState !==
|
|
884
|
+
e.readyState !== ls && e.readyState !== ps && this.closeConn(e);
|
|
832
885
|
try {
|
|
833
886
|
e.send(s, (a) => {
|
|
834
887
|
a && this.closeConn(e);
|
|
@@ -840,7 +893,7 @@ class D extends F.Doc {
|
|
|
840
893
|
closeConn = (e) => {
|
|
841
894
|
if (e.removeAllListeners(), this.conns.has(e)) {
|
|
842
895
|
const s = this.conns.get(e);
|
|
843
|
-
this.conns.delete(e), s &&
|
|
896
|
+
this.conns.delete(e), s && Nt(this.awareness, Array.from(s), null);
|
|
844
897
|
}
|
|
845
898
|
e.close(), this.checkAndScheduleRelease();
|
|
846
899
|
};
|
|
@@ -851,30 +904,30 @@ class D extends F.Doc {
|
|
|
851
904
|
// 调度延迟释放
|
|
852
905
|
scheduleRelease() {
|
|
853
906
|
this.cancelRelease();
|
|
854
|
-
const e =
|
|
907
|
+
const e = $(this.options.path);
|
|
855
908
|
this.releaseTimer = setTimeout(() => {
|
|
856
|
-
|
|
857
|
-
}, D.RELEASE_DELAY),
|
|
909
|
+
p.info(`[SiteState] releasing instance due to no active connections: ${e}`), this.conns.size === 0 && (this.releaseTimer = void 0, this.destroy());
|
|
910
|
+
}, D.RELEASE_DELAY), p.info(`[SiteState] scheduled release for project ${e} in ${D.RELEASE_DELAY / 1e3}s`);
|
|
858
911
|
}
|
|
859
912
|
// 取消延迟释放
|
|
860
913
|
cancelRelease() {
|
|
861
914
|
if (this.releaseTimer) {
|
|
862
915
|
clearTimeout(this.releaseTimer), this.releaseTimer = void 0;
|
|
863
|
-
const e =
|
|
864
|
-
|
|
916
|
+
const e = $(this.options.path);
|
|
917
|
+
p.info(`[SiteState] cancelled scheduled release for project ${e}`);
|
|
865
918
|
}
|
|
866
919
|
}
|
|
867
|
-
autoSave =
|
|
868
|
-
await
|
|
869
|
-
},
|
|
920
|
+
autoSave = Ce(async () => {
|
|
921
|
+
await B(M(this.draftYjsFilePath), { recursive: !0 }), await ne(this.draftYjsFilePath, F.encodeStateAsUpdate(this));
|
|
922
|
+
}, is);
|
|
870
923
|
save = ({ flush: e = !1 } = {}) => {
|
|
871
924
|
this.autoSave(), e && this.autoSave.flush();
|
|
872
925
|
};
|
|
873
926
|
publish = async ({ mode: e, routes: s }) => {
|
|
874
|
-
const a =
|
|
875
|
-
await
|
|
927
|
+
const a = $(this.options.path);
|
|
928
|
+
await Ss(a);
|
|
876
929
|
const o = await this.getState("draft"), n = await this.getState("production");
|
|
877
|
-
await qe(o, n, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(),
|
|
930
|
+
await qe(o, n, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), ss(this.syncedStore, s), await this.setState(e, n), await this.clearPageCacheForRoutes(s, n);
|
|
878
931
|
};
|
|
879
932
|
mergeState = async (e, s) => {
|
|
880
933
|
const a = JSON.parse(JSON.stringify(s));
|
|
@@ -892,18 +945,18 @@ class D extends F.Doc {
|
|
|
892
945
|
});
|
|
893
946
|
};
|
|
894
947
|
clearPageCacheForRoutes = async (e, s) => {
|
|
895
|
-
const a =
|
|
948
|
+
const a = $(this.options.path), n = (await U.findByPk(a))?.slug || a;
|
|
896
949
|
let l = e;
|
|
897
|
-
(!l || l.length === 0) && (l = s.pageIds ?? []),
|
|
898
|
-
const r = s.supportedLocales.map((
|
|
899
|
-
for (const
|
|
900
|
-
const
|
|
901
|
-
n && n !== a && (n === "/" ? i.push(
|
|
950
|
+
(!l || l.length === 0) && (l = s.pageIds ?? []), p.info(`[SiteState] clearing page cache for project ${a}, routes:`, l || []);
|
|
951
|
+
const r = s.supportedLocales.map((A) => A.locale), i = [], f = l.filter((A) => s.pageIds?.includes(A));
|
|
952
|
+
for (const A of f) {
|
|
953
|
+
const y = s.pages[A].slug;
|
|
954
|
+
n && n !== a && (n === "/" ? i.push(y) : i.push(`/${n}${y}`)), i.push(`/${a}${y}`);
|
|
902
955
|
}
|
|
903
956
|
if (i.length > 0)
|
|
904
957
|
try {
|
|
905
|
-
const
|
|
906
|
-
|
|
958
|
+
const A = os(i, r);
|
|
959
|
+
p.info(`[SiteState] cleared ${A} page cache entries for project ${a}, routes:`, l);
|
|
907
960
|
} catch {
|
|
908
961
|
}
|
|
909
962
|
};
|
|
@@ -923,7 +976,7 @@ class D extends F.Doc {
|
|
|
923
976
|
this.closeConn(e), clearInterval(a);
|
|
924
977
|
}
|
|
925
978
|
}
|
|
926
|
-
},
|
|
979
|
+
}, cs);
|
|
927
980
|
e.on("close", () => {
|
|
928
981
|
this.closeConn(e), clearInterval(a);
|
|
929
982
|
}), e.on("pong", () => {
|
|
@@ -931,37 +984,37 @@ class D extends F.Doc {
|
|
|
931
984
|
});
|
|
932
985
|
{
|
|
933
986
|
const o = v.createEncoder();
|
|
934
|
-
v.writeVarUint(o,
|
|
987
|
+
v.writeVarUint(o, se), Ft(o, this), this.send(e, v.toUint8Array(o));
|
|
935
988
|
const n = this.awareness.getStates();
|
|
936
989
|
if (n.size > 0) {
|
|
937
990
|
const l = v.createEncoder();
|
|
938
|
-
v.writeVarUint(l,
|
|
991
|
+
v.writeVarUint(l, ge), v.writeVarUint8Array(l, _e(this.awareness, Array.from(n.keys()))), this.send(e, v.toUint8Array(l));
|
|
939
992
|
}
|
|
940
993
|
}
|
|
941
994
|
};
|
|
942
995
|
messageListener = (e, s) => {
|
|
943
996
|
try {
|
|
944
|
-
const a = v.createEncoder(), o =
|
|
997
|
+
const a = v.createEncoder(), o = fe.createDecoder(s), n = fe.readVarUint(o);
|
|
945
998
|
switch (n) {
|
|
946
|
-
case
|
|
947
|
-
v.writeVarUint(a,
|
|
999
|
+
case se:
|
|
1000
|
+
v.writeVarUint(a, se), xt(o, a, this, null), v.length(a) > 1 && (this.ensureDataStructure(), this.send(e, v.toUint8Array(a)));
|
|
948
1001
|
break;
|
|
949
|
-
case
|
|
950
|
-
Mt(this.awareness,
|
|
1002
|
+
case ge: {
|
|
1003
|
+
Mt(this.awareness, fe.readVarUint8Array(o), e);
|
|
951
1004
|
break;
|
|
952
1005
|
}
|
|
953
1006
|
default:
|
|
954
|
-
|
|
1007
|
+
p.warn(`Unsupported messageType ${n}`);
|
|
955
1008
|
}
|
|
956
1009
|
} catch (a) {
|
|
957
|
-
|
|
1010
|
+
p.error(a);
|
|
958
1011
|
}
|
|
959
1012
|
this.save();
|
|
960
1013
|
};
|
|
961
1014
|
// 这个方法还是需要动态的,因为可能会动态修改 projectSlug、语言之类的
|
|
962
1015
|
static async pageUrlMap(e, s) {
|
|
963
|
-
if (
|
|
964
|
-
const n = s ? { projectId: s } : {}, l = await
|
|
1016
|
+
if (p.info(`[SiteState] get pageUrlMap, mode: ${e}, projectId: ${s}`), e === "production") {
|
|
1017
|
+
const n = s ? { projectId: s } : {}, l = await ee.findAll({
|
|
965
1018
|
where: n,
|
|
966
1019
|
raw: !0
|
|
967
1020
|
}), r = {};
|
|
@@ -980,21 +1033,21 @@ class D extends F.Doc {
|
|
|
980
1033
|
publishedAt: i.publishedAt,
|
|
981
1034
|
locales: i.locales
|
|
982
1035
|
};
|
|
983
|
-
return
|
|
1036
|
+
return p.info(`[SiteState] loaded ${l.length} URL mappings from database`), r;
|
|
984
1037
|
}
|
|
985
1038
|
let a = [];
|
|
986
1039
|
s ? a = [s] : a = await this.getProjectIds();
|
|
987
1040
|
let o = {};
|
|
988
1041
|
if (a?.length) {
|
|
989
|
-
|
|
990
|
-
const n = 30, l =
|
|
1042
|
+
p.info("[SiteState] find project infos from database, projectIds: ", a);
|
|
1043
|
+
const n = 30, l = Re(5);
|
|
991
1044
|
for (let r = 0; r < a.length; r += n) {
|
|
992
1045
|
const i = a.slice(r, r + n);
|
|
993
|
-
|
|
994
|
-
const
|
|
1046
|
+
p.info(`[SiteState] processing project batch ${r / n + 1}, ids: `, i);
|
|
1047
|
+
const f = await U.findAll({
|
|
995
1048
|
where: {
|
|
996
1049
|
id: {
|
|
997
|
-
[
|
|
1050
|
+
[Z.in]: i
|
|
998
1051
|
}
|
|
999
1052
|
},
|
|
1000
1053
|
attributes: {
|
|
@@ -1002,32 +1055,32 @@ class D extends F.Doc {
|
|
|
1002
1055
|
}
|
|
1003
1056
|
});
|
|
1004
1057
|
await Promise.all(
|
|
1005
|
-
|
|
1006
|
-
(
|
|
1007
|
-
const
|
|
1008
|
-
E.env.languages?.map((
|
|
1009
|
-
|
|
1010
|
-
),
|
|
1011
|
-
|
|
1058
|
+
f?.map(
|
|
1059
|
+
(A) => l(async () => {
|
|
1060
|
+
const R = A.id, y = A.slug || R, g = {}, u = await D.getStateByProjectId({ projectId: A.id, mode: e, clone: !1 }), I = vt(
|
|
1061
|
+
E.env.languages?.map((O) => O.code) || [],
|
|
1062
|
+
u.supportedLocales?.map((O) => O.locale) || []
|
|
1063
|
+
), C = (O, w) => {
|
|
1064
|
+
y && (g[x("/", y, O)] = {
|
|
1012
1065
|
...w,
|
|
1013
1066
|
shouldRedirect: !0,
|
|
1014
1067
|
mainPage: !0
|
|
1015
|
-
}),
|
|
1068
|
+
}), g[x("/", R, O)] = {
|
|
1016
1069
|
...w,
|
|
1017
1070
|
shouldRedirect: !0,
|
|
1018
1071
|
mainPage: !0
|
|
1019
1072
|
};
|
|
1020
1073
|
for (const k of I) {
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1074
|
+
const h = { ...w, locale: k };
|
|
1075
|
+
g[x("/", k, R, O)] = h, y && (g[x("/", k, y, O)] = h);
|
|
1023
1076
|
}
|
|
1024
1077
|
};
|
|
1025
1078
|
if (e === "draft")
|
|
1026
|
-
for (const
|
|
1027
|
-
const w =
|
|
1079
|
+
for (const O of u.routeIds || []) {
|
|
1080
|
+
const w = u?.routes?.[O];
|
|
1028
1081
|
if (!w) continue;
|
|
1029
1082
|
if (w.params && w.params.length > 0) {
|
|
1030
|
-
const S =
|
|
1083
|
+
const S = be({
|
|
1031
1084
|
basePath: w.path,
|
|
1032
1085
|
params: w.params,
|
|
1033
1086
|
routeId: w.id,
|
|
@@ -1038,59 +1091,59 @@ class D extends F.Doc {
|
|
|
1038
1091
|
result: []
|
|
1039
1092
|
});
|
|
1040
1093
|
for (const c of S) {
|
|
1041
|
-
const
|
|
1042
|
-
projectId:
|
|
1043
|
-
projectSlug:
|
|
1044
|
-
pageSlug:
|
|
1094
|
+
const d = c.path, m = {
|
|
1095
|
+
projectId: R,
|
|
1096
|
+
projectSlug: y,
|
|
1097
|
+
pageSlug: d,
|
|
1045
1098
|
pageId: w.displayTemplateId || "",
|
|
1046
|
-
routeId:
|
|
1099
|
+
routeId: O,
|
|
1047
1100
|
// default locale
|
|
1048
1101
|
defaultLocale: I?.[0],
|
|
1049
1102
|
locales: I,
|
|
1050
|
-
publishedAt:
|
|
1103
|
+
publishedAt: u.config.publishedAt,
|
|
1051
1104
|
isPublic: w.isPublic && c?.routeMetaData?.isPublic
|
|
1052
1105
|
};
|
|
1053
|
-
|
|
1106
|
+
C(d, m);
|
|
1054
1107
|
}
|
|
1055
1108
|
}
|
|
1056
|
-
const k = w.path,
|
|
1057
|
-
projectId:
|
|
1058
|
-
projectSlug:
|
|
1109
|
+
const k = w.path, h = {
|
|
1110
|
+
projectId: R,
|
|
1111
|
+
projectSlug: y,
|
|
1059
1112
|
pageSlug: k,
|
|
1060
1113
|
pageId: w.displayTemplateId || "",
|
|
1061
|
-
routeId:
|
|
1114
|
+
routeId: O,
|
|
1062
1115
|
// default locale
|
|
1063
1116
|
defaultLocale: I?.[0],
|
|
1064
1117
|
locales: I,
|
|
1065
|
-
publishedAt:
|
|
1118
|
+
publishedAt: u.config.publishedAt,
|
|
1066
1119
|
isPublic: w.isPublic
|
|
1067
1120
|
};
|
|
1068
|
-
|
|
1121
|
+
C(k, h);
|
|
1069
1122
|
}
|
|
1070
|
-
for (const
|
|
1071
|
-
const w =
|
|
1123
|
+
for (const O of u.pageIds || []) {
|
|
1124
|
+
const w = u.pages[O];
|
|
1072
1125
|
if (!w) continue;
|
|
1073
|
-
const k = w.slug,
|
|
1074
|
-
projectId:
|
|
1075
|
-
projectSlug:
|
|
1126
|
+
const k = w.slug, h = A.slug || R, S = {
|
|
1127
|
+
projectId: R,
|
|
1128
|
+
projectSlug: h,
|
|
1076
1129
|
pageSlug: k,
|
|
1077
|
-
pageId:
|
|
1130
|
+
pageId: O,
|
|
1078
1131
|
// default locale
|
|
1079
1132
|
defaultLocale: I?.[0],
|
|
1080
1133
|
locales: I,
|
|
1081
|
-
publishedAt:
|
|
1134
|
+
publishedAt: u.config.publishedAt,
|
|
1082
1135
|
isPublic: w.isPublic,
|
|
1083
1136
|
templateConfig: w.templateConfig
|
|
1084
1137
|
};
|
|
1085
|
-
|
|
1138
|
+
C(k, S);
|
|
1086
1139
|
}
|
|
1087
|
-
o = { ...o, ...
|
|
1140
|
+
o = { ...o, ...g };
|
|
1088
1141
|
})
|
|
1089
1142
|
)
|
|
1090
1143
|
);
|
|
1091
1144
|
}
|
|
1092
1145
|
}
|
|
1093
|
-
return
|
|
1146
|
+
return p.info("[SiteState] success get pageUrlMap"), o;
|
|
1094
1147
|
}
|
|
1095
1148
|
getDocumentSize() {
|
|
1096
1149
|
return F.encodeStateAsUpdate(this).byteLength;
|
|
@@ -1112,58 +1165,58 @@ class D extends F.Doc {
|
|
|
1112
1165
|
static startPeriodicCheck() {
|
|
1113
1166
|
this.periodicCheckTimer || (this.periodicCheckTimer = setInterval(() => {
|
|
1114
1167
|
this.performPeriodicCheck();
|
|
1115
|
-
}, this.PERIODIC_CHECK_INTERVAL),
|
|
1168
|
+
}, this.PERIODIC_CHECK_INTERVAL), p.info(
|
|
1116
1169
|
`[SiteState] periodic check started, interval: ${this.PERIODIC_CHECK_INTERVAL / (60 * 60 * 1e3)} hours`
|
|
1117
1170
|
));
|
|
1118
1171
|
}
|
|
1119
1172
|
// 停止定期检查
|
|
1120
1173
|
static stopPeriodicCheck() {
|
|
1121
|
-
this.periodicCheckTimer && (clearInterval(this.periodicCheckTimer), this.periodicCheckTimer = void 0,
|
|
1174
|
+
this.periodicCheckTimer && (clearInterval(this.periodicCheckTimer), this.periodicCheckTimer = void 0, p.info("[SiteState] periodic check stopped"));
|
|
1122
1175
|
}
|
|
1123
1176
|
// 执行定期检查
|
|
1124
1177
|
static performPeriodicCheck() {
|
|
1125
1178
|
const e = Object.keys(D.sharedInstances).length, s = [], a = [];
|
|
1126
1179
|
for (const [o, n] of Object.entries(D.sharedInstances))
|
|
1127
1180
|
n.conns.size === 0 ? s.push({ projectId: o, instance: n }) : a.push({ projectId: o, connections: n.conns.size });
|
|
1128
|
-
if (
|
|
1181
|
+
if (p.info(
|
|
1129
1182
|
`[SiteState] periodic check summary: total instances: ${e}, with connections: ${a.length}, without connections: ${s.length}`
|
|
1130
1183
|
), s.length > 0) {
|
|
1131
|
-
|
|
1184
|
+
p.info(
|
|
1132
1185
|
`[SiteState] releasing ${s.length} instances without connections:`,
|
|
1133
1186
|
s.map((n) => n.projectId)
|
|
1134
1187
|
);
|
|
1135
1188
|
let o = 0;
|
|
1136
1189
|
for (const { projectId: n, instance: l } of s)
|
|
1137
1190
|
try {
|
|
1138
|
-
|
|
1191
|
+
p.info(`[SiteState] releasing instance due to periodic check: ${n}`), l.destroy(), o++;
|
|
1139
1192
|
} catch (r) {
|
|
1140
|
-
|
|
1193
|
+
p.error(`[SiteState] failed to release instance ${n} during periodic check:`, r);
|
|
1141
1194
|
}
|
|
1142
|
-
|
|
1195
|
+
p.info(
|
|
1143
1196
|
`[SiteState] periodic check completed: ${o}/${s.length} instances released successfully`
|
|
1144
1197
|
);
|
|
1145
|
-
} else e > 0 ?
|
|
1198
|
+
} else e > 0 ? p.debug("[SiteState] periodic check: all instances have active connections") : p.debug("[SiteState] periodic check: no instances exist");
|
|
1146
1199
|
}
|
|
1147
1200
|
}
|
|
1148
|
-
async function
|
|
1149
|
-
if (!t || !await
|
|
1201
|
+
async function ds(t, e, s) {
|
|
1202
|
+
if (!t || !await G(t) || !(await oe(t)).isFile())
|
|
1150
1203
|
return null;
|
|
1151
1204
|
let o = s[t];
|
|
1152
1205
|
return o || (o = (async () => {
|
|
1153
1206
|
try {
|
|
1154
|
-
return (await
|
|
1207
|
+
return (await rs({
|
|
1155
1208
|
filePath: t,
|
|
1156
1209
|
fileName: e
|
|
1157
1210
|
}))?.data?.filename;
|
|
1158
1211
|
} catch (n) {
|
|
1159
|
-
return
|
|
1212
|
+
return p.error(`Failed to upload asset ${t}:`, n), null;
|
|
1160
1213
|
}
|
|
1161
1214
|
})(), s[t] = o), o;
|
|
1162
1215
|
}
|
|
1163
|
-
const
|
|
1164
|
-
const s =
|
|
1216
|
+
const fs = async (t, e) => {
|
|
1217
|
+
const s = $(t), a = await Rt({
|
|
1165
1218
|
name: Ye,
|
|
1166
|
-
path:
|
|
1219
|
+
path: x("/uploads", s),
|
|
1167
1220
|
responseType: "stream",
|
|
1168
1221
|
method: "GET"
|
|
1169
1222
|
});
|
|
@@ -1172,13 +1225,13 @@ const us = async (t, e) => {
|
|
|
1172
1225
|
await Tt(a.data, o);
|
|
1173
1226
|
} else
|
|
1174
1227
|
throw new Error(`download asset failed ${a.status}`);
|
|
1175
|
-
},
|
|
1228
|
+
}, ms = async (t, e) => {
|
|
1176
1229
|
await Promise.all(
|
|
1177
1230
|
t.map(async (s) => {
|
|
1178
1231
|
try {
|
|
1179
|
-
await
|
|
1232
|
+
await fs(s, b(e, $(s)));
|
|
1180
1233
|
} catch (a) {
|
|
1181
|
-
|
|
1234
|
+
p.error(`Failed to export assets: ${s}, ${a}`);
|
|
1182
1235
|
}
|
|
1183
1236
|
})
|
|
1184
1237
|
);
|
|
@@ -1186,49 +1239,49 @@ const us = async (t, e) => {
|
|
|
1186
1239
|
function et(t) {
|
|
1187
1240
|
return ve.test(t) ? [t] : X.test(t) ? (Ve.lastIndex = 0, Array.from(t.matchAll(Ve)).map((s) => s[1]).filter((s) => !!s)) : [];
|
|
1188
1241
|
}
|
|
1189
|
-
async function
|
|
1190
|
-
const { getFilename: a, exportAssets: o } = s, n =
|
|
1191
|
-
if (await
|
|
1192
|
-
const r =
|
|
1242
|
+
async function ae(t, e, s) {
|
|
1243
|
+
const { getFilename: a, exportAssets: o } = s, n = b(e, a(t));
|
|
1244
|
+
if (await B(M(n), { recursive: !0 }), await ne(n, q.stringify(t)), o) {
|
|
1245
|
+
const r = ie(
|
|
1193
1246
|
t,
|
|
1194
1247
|
(i) => typeof i == "string" && (ve.test(i) || X.test(i))
|
|
1195
1248
|
).map((i) => {
|
|
1196
|
-
const
|
|
1197
|
-
return et(
|
|
1249
|
+
const f = je(t, i);
|
|
1250
|
+
return et(f);
|
|
1198
1251
|
}).flat().filter(Boolean);
|
|
1199
|
-
await
|
|
1252
|
+
await ms(r, M(n));
|
|
1200
1253
|
}
|
|
1201
1254
|
}
|
|
1202
|
-
const
|
|
1255
|
+
const Pe = new We({
|
|
1203
1256
|
max: 100,
|
|
1204
1257
|
ttl: 1 * 60 * 1e3
|
|
1205
1258
|
// 1 minute
|
|
1206
1259
|
});
|
|
1207
1260
|
async function ze(t, e, s) {
|
|
1208
|
-
const a =
|
|
1261
|
+
const a = ie(
|
|
1209
1262
|
t,
|
|
1210
1263
|
(r) => typeof r == "string" && (ve.test(r) || X.test(r))
|
|
1211
|
-
), o =
|
|
1264
|
+
), o = Re(2), n = a.map(
|
|
1212
1265
|
(r) => o(async () => {
|
|
1213
1266
|
try {
|
|
1214
|
-
const i = je(t, r),
|
|
1215
|
-
for (const
|
|
1216
|
-
const
|
|
1217
|
-
if (
|
|
1218
|
-
X.test(i) || Me(t, r,
|
|
1267
|
+
const i = je(t, r), f = et(i);
|
|
1268
|
+
for (const A of f) {
|
|
1269
|
+
const R = $(A), y = s.getFilePath(A, r), g = y ? `${y}:${R}` : R, u = Pe.get(g);
|
|
1270
|
+
if (u) {
|
|
1271
|
+
X.test(i) || Me(t, r, u);
|
|
1219
1272
|
return;
|
|
1220
1273
|
}
|
|
1221
|
-
const I = await
|
|
1222
|
-
I && (X.test(i) || Me(t, r, I),
|
|
1274
|
+
const I = await ds(y, R, e);
|
|
1275
|
+
I && (X.test(i) || Me(t, r, I), Pe.set(g, I));
|
|
1223
1276
|
}
|
|
1224
1277
|
} catch (i) {
|
|
1225
|
-
|
|
1278
|
+
p.error(`Failed to process upload for path ${r.join(".")}:`, i.message || i.reason);
|
|
1226
1279
|
}
|
|
1227
1280
|
})
|
|
1228
1281
|
), l = await Promise.allSettled(n);
|
|
1229
1282
|
s.onFinish?.(l);
|
|
1230
1283
|
}
|
|
1231
|
-
async function
|
|
1284
|
+
async function gs(t, {
|
|
1232
1285
|
exportAssets: e,
|
|
1233
1286
|
pageIds: s = "all",
|
|
1234
1287
|
componentIds: a = "all",
|
|
@@ -1241,10 +1294,10 @@ async function fs(t, {
|
|
|
1241
1294
|
pageIds: r,
|
|
1242
1295
|
componentIds: a === "all" ? Object.keys(t.components) : a
|
|
1243
1296
|
});
|
|
1244
|
-
Object.entries(t.components).forEach(([c,
|
|
1245
|
-
|
|
1297
|
+
Object.entries(t.components).forEach(([c, d]) => {
|
|
1298
|
+
d.data?.renderer?.type === "component-template" && i.push(c);
|
|
1246
1299
|
});
|
|
1247
|
-
const
|
|
1300
|
+
const f = l === "all" ? t.routeIds : l, A = (c) => ({
|
|
1248
1301
|
id: c.id,
|
|
1249
1302
|
name: c.name,
|
|
1250
1303
|
isTemplateSection: c.isTemplateSection ?? !1,
|
|
@@ -1255,32 +1308,32 @@ async function fs(t, {
|
|
|
1255
1308
|
config: c.config,
|
|
1256
1309
|
visibility: c.visibility,
|
|
1257
1310
|
sections: c?.sectionIds ? L(
|
|
1258
|
-
c?.sectionIds?.map((
|
|
1259
|
-
const
|
|
1260
|
-
return
|
|
1311
|
+
c?.sectionIds?.map((d) => {
|
|
1312
|
+
const m = c.sections?.[d];
|
|
1313
|
+
return m && A(m);
|
|
1261
1314
|
})
|
|
1262
1315
|
) : void 0
|
|
1263
1316
|
/** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
|
|
1264
1317
|
// properties: section.locales?.[locale] ?? {},
|
|
1265
|
-
}),
|
|
1318
|
+
}), R = (c, d) => ({
|
|
1266
1319
|
id: c.id,
|
|
1267
1320
|
createdAt: c.createdAt,
|
|
1268
1321
|
updatedAt: c.updatedAt,
|
|
1269
1322
|
publishedAt: c.publishedAt,
|
|
1270
1323
|
isPublic: c.isPublic ?? !0,
|
|
1271
1324
|
templateConfig: c.templateConfig,
|
|
1272
|
-
meta: c.locales?.[
|
|
1325
|
+
meta: c.locales?.[d] ?? {},
|
|
1273
1326
|
sections: L(
|
|
1274
|
-
c.sectionIds.map((
|
|
1275
|
-
const j = c.sections[
|
|
1276
|
-
return j &&
|
|
1327
|
+
c.sectionIds.map((m) => {
|
|
1328
|
+
const j = c.sections[m];
|
|
1329
|
+
return j && A(j);
|
|
1277
1330
|
})
|
|
1278
1331
|
),
|
|
1279
1332
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1280
1333
|
dataSource: Object.fromEntries(
|
|
1281
|
-
Object.entries(c.dataSource || {}).map(([
|
|
1334
|
+
Object.entries(c.dataSource || {}).map(([m, j]) => [m, j?.[d] ?? {}])
|
|
1282
1335
|
)
|
|
1283
|
-
}),
|
|
1336
|
+
}), y = (c) => ({
|
|
1284
1337
|
id: c.id,
|
|
1285
1338
|
createdAt: c.createdAt,
|
|
1286
1339
|
updatedAt: c.updatedAt,
|
|
@@ -1292,67 +1345,67 @@ async function fs(t, {
|
|
|
1292
1345
|
enabledGenerate: c.enabledGenerate ?? !1,
|
|
1293
1346
|
displayTemplateId: c.displayTemplateId,
|
|
1294
1347
|
dataSource: c.dataSource
|
|
1295
|
-
}),
|
|
1296
|
-
|
|
1297
|
-
const
|
|
1298
|
-
return
|
|
1348
|
+
}), g = L(
|
|
1349
|
+
f.map((c) => {
|
|
1350
|
+
const d = t.routes[c];
|
|
1351
|
+
return d && y(d);
|
|
1299
1352
|
})
|
|
1300
|
-
),
|
|
1353
|
+
), u = L(
|
|
1301
1354
|
t.supportedLocales.map((c) => c.locale).flatMap(
|
|
1302
|
-
(c) => r.map((
|
|
1303
|
-
const
|
|
1304
|
-
return
|
|
1355
|
+
(c) => r.map((d) => {
|
|
1356
|
+
const m = t.pages[d];
|
|
1357
|
+
return m && {
|
|
1305
1358
|
locale: c,
|
|
1306
|
-
slug:
|
|
1307
|
-
page:
|
|
1359
|
+
slug: m.slug,
|
|
1360
|
+
page: R(m, c)
|
|
1308
1361
|
};
|
|
1309
1362
|
})
|
|
1310
1363
|
)
|
|
1311
|
-
), I = Ze(),
|
|
1312
|
-
await
|
|
1313
|
-
const
|
|
1314
|
-
await
|
|
1315
|
-
const w =
|
|
1316
|
-
await
|
|
1317
|
-
for (const { locale: c, slug:
|
|
1318
|
-
await
|
|
1319
|
-
getFilename: () => `${
|
|
1364
|
+
), I = Ze(), C = b(I, "pages");
|
|
1365
|
+
await B(C, { recursive: !0 });
|
|
1366
|
+
const O = b(I, "components");
|
|
1367
|
+
await B(O, { recursive: !0 });
|
|
1368
|
+
const w = b(I, "routes");
|
|
1369
|
+
await B(w, { recursive: !0 });
|
|
1370
|
+
for (const { locale: c, slug: d, page: m } of u)
|
|
1371
|
+
await ae(m, C, {
|
|
1372
|
+
getFilename: () => `${ce(d) || "index"}.${c}.yml`,
|
|
1320
1373
|
exportAssets: e
|
|
1321
1374
|
});
|
|
1322
|
-
for (const c of
|
|
1323
|
-
await
|
|
1375
|
+
for (const c of g)
|
|
1376
|
+
await ae(c, w, {
|
|
1324
1377
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1325
|
-
getFilename: () => `${
|
|
1378
|
+
getFilename: () => `${ce(c.path) || "index"}.yml`,
|
|
1326
1379
|
exportAssets: e
|
|
1327
1380
|
});
|
|
1328
1381
|
for (const c of i) {
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
getFilename: (
|
|
1382
|
+
const d = t.components[c]?.data;
|
|
1383
|
+
d && await ae(d, O, {
|
|
1384
|
+
getFilename: (m) => `${m.name || "unnamed"}.${m.id}.yml`,
|
|
1332
1385
|
exportAssets: e
|
|
1333
1386
|
});
|
|
1334
1387
|
}
|
|
1335
|
-
const k =
|
|
1336
|
-
await
|
|
1337
|
-
const
|
|
1388
|
+
const k = b(I, ".blocklet/pages/pages.config.yml");
|
|
1389
|
+
await B(M(k), { recursive: !0 });
|
|
1390
|
+
const h = {
|
|
1338
1391
|
pages: L(
|
|
1339
1392
|
r.map((c) => {
|
|
1340
|
-
const
|
|
1341
|
-
return
|
|
1393
|
+
const d = t.pages[c];
|
|
1394
|
+
return d && { id: c, slug: d.slug };
|
|
1342
1395
|
})
|
|
1343
1396
|
),
|
|
1344
1397
|
routes: L(
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1347
|
-
return
|
|
1398
|
+
f.map((c) => {
|
|
1399
|
+
const d = t.routes[c];
|
|
1400
|
+
return d && { id: c, path: d.path };
|
|
1348
1401
|
})
|
|
1349
1402
|
),
|
|
1350
1403
|
components: L(
|
|
1351
1404
|
i.map((c) => {
|
|
1352
|
-
const
|
|
1353
|
-
return
|
|
1405
|
+
const d = t.components[c]?.data;
|
|
1406
|
+
return d && {
|
|
1354
1407
|
id: c,
|
|
1355
|
-
name:
|
|
1408
|
+
name: d.name
|
|
1356
1409
|
};
|
|
1357
1410
|
})
|
|
1358
1411
|
),
|
|
@@ -1369,36 +1422,36 @@ async function fs(t, {
|
|
|
1369
1422
|
supportedLocales: t.supportedLocales,
|
|
1370
1423
|
config: t.config
|
|
1371
1424
|
};
|
|
1372
|
-
await
|
|
1373
|
-
const S =
|
|
1374
|
-
if (o && await
|
|
1375
|
-
const c =
|
|
1376
|
-
await
|
|
1377
|
-
for (const
|
|
1425
|
+
await ne(k, q.stringify(h));
|
|
1426
|
+
const S = b(I, "config.source.json");
|
|
1427
|
+
if (o && await ne(S, JSON.stringify(o)), n) {
|
|
1428
|
+
const c = b(I, "resources"), d = b(c, "components");
|
|
1429
|
+
await B(d, { recursive: !0 });
|
|
1430
|
+
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1378
1431
|
(T) => i.includes(T)
|
|
1379
1432
|
)) {
|
|
1380
|
-
const T = t.resources?.components?.[
|
|
1381
|
-
T && await
|
|
1433
|
+
const T = t.resources?.components?.[N]?.component;
|
|
1434
|
+
T && await ae(T, d, {
|
|
1382
1435
|
getFilename: (V) => `${V.name || "unnamed"}.${V.id}.yml`,
|
|
1383
1436
|
exportAssets: e
|
|
1384
1437
|
});
|
|
1385
1438
|
}
|
|
1386
|
-
const
|
|
1387
|
-
await
|
|
1388
|
-
const j = await
|
|
1389
|
-
for (const
|
|
1439
|
+
const m = b(I, "chunks");
|
|
1440
|
+
await B(m, { recursive: !0 });
|
|
1441
|
+
const j = await hs();
|
|
1442
|
+
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1390
1443
|
(T) => i.includes(T)
|
|
1391
1444
|
)) {
|
|
1392
|
-
const T = t.resources?.components?.[
|
|
1445
|
+
const T = t.resources?.components?.[N]?.component;
|
|
1393
1446
|
if (T && T.renderer?.type === "react-component") {
|
|
1394
1447
|
const V = T.renderer?.chunks ?? [];
|
|
1395
1448
|
if (V?.length > 0)
|
|
1396
1449
|
for (const H of V) {
|
|
1397
|
-
const Te =
|
|
1450
|
+
const Te = b(m, H), de = j?.[H];
|
|
1398
1451
|
try {
|
|
1399
|
-
|
|
1452
|
+
de && await G(de) && !await G(Te) && await jt(de, Te);
|
|
1400
1453
|
} catch (ct) {
|
|
1401
|
-
|
|
1454
|
+
p.error(`copy chunk ${H} error`, ct.message);
|
|
1402
1455
|
}
|
|
1403
1456
|
}
|
|
1404
1457
|
}
|
|
@@ -1407,85 +1460,85 @@ async function fs(t, {
|
|
|
1407
1460
|
return I;
|
|
1408
1461
|
}
|
|
1409
1462
|
async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
1410
|
-
if (!await
|
|
1463
|
+
if (!await G(t))
|
|
1411
1464
|
return null;
|
|
1412
1465
|
let a, o = !1;
|
|
1413
1466
|
try {
|
|
1414
|
-
(await
|
|
1415
|
-
const r = (await
|
|
1467
|
+
(await oe(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Ze(), await Lt({ file: t, C: a }));
|
|
1468
|
+
const r = (await ye("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], i = r && b(M(r), "../../pages"), f = r && b(M(r), "../../components"), A = r && b(M(r), "../../routes");
|
|
1416
1469
|
if (!r)
|
|
1417
1470
|
return null;
|
|
1418
|
-
const
|
|
1419
|
-
let
|
|
1420
|
-
if (!await
|
|
1471
|
+
const R = await te(r, "utf-8"), y = q.parse(R), g = async (h, S, c) => {
|
|
1472
|
+
let d = b(h, `${S}${c ? `.${c}` : ""}.yml`);
|
|
1473
|
+
if (!await G(d) && (d = b(h, S, `index${c ? `.${c}` : ""}.yml`), !await G(d)) || !(await oe(d)).isFile())
|
|
1421
1474
|
return null;
|
|
1422
|
-
const j = await
|
|
1475
|
+
const j = await te(d, "utf-8");
|
|
1423
1476
|
return q.parse(j);
|
|
1424
|
-
},
|
|
1477
|
+
}, u = async (h, S) => {
|
|
1425
1478
|
try {
|
|
1426
|
-
const
|
|
1427
|
-
if (!
|
|
1428
|
-
const
|
|
1429
|
-
return q.parse(
|
|
1479
|
+
const d = (await ye(`*.${S}.yml`, { cwd: h, absolute: !0 }))[0];
|
|
1480
|
+
if (!d) return null;
|
|
1481
|
+
const m = await te(d, "utf-8");
|
|
1482
|
+
return q.parse(m);
|
|
1430
1483
|
} catch (c) {
|
|
1431
|
-
|
|
1484
|
+
p.error("parse component error", c);
|
|
1432
1485
|
}
|
|
1433
1486
|
return null;
|
|
1434
|
-
}, I = async (
|
|
1435
|
-
let c =
|
|
1436
|
-
if (!await
|
|
1487
|
+
}, I = async (h, S) => {
|
|
1488
|
+
let c = b(h, `${S}.yml`);
|
|
1489
|
+
if (!await G(c) && (c = b(h, S, "index.yml"), !await G(c)) || !(await oe(c)).isFile())
|
|
1437
1490
|
return null;
|
|
1438
|
-
const
|
|
1439
|
-
return q.parse(
|
|
1440
|
-
},
|
|
1491
|
+
const m = await te(c, "utf-8");
|
|
1492
|
+
return q.parse(m);
|
|
1493
|
+
}, C = L(
|
|
1441
1494
|
await Promise.all(
|
|
1442
|
-
|
|
1495
|
+
y.pages.map(async ({ slug: h }) => {
|
|
1443
1496
|
const S = L(
|
|
1444
1497
|
await Promise.all(
|
|
1445
|
-
|
|
1446
|
-
const j = i ? await
|
|
1498
|
+
y.supportedLocales.map(async ({ locale: m }) => {
|
|
1499
|
+
const j = i ? await g(i, ce(h), m) : void 0;
|
|
1447
1500
|
if (j)
|
|
1448
|
-
return { locale:
|
|
1449
|
-
const
|
|
1450
|
-
return
|
|
1501
|
+
return { locale: m, page: j };
|
|
1502
|
+
const N = i ? await g(i, h, m) : void 0;
|
|
1503
|
+
return N && { locale: m, page: N };
|
|
1451
1504
|
})
|
|
1452
1505
|
)
|
|
1453
1506
|
), c = S[0]?.page;
|
|
1454
1507
|
if (!c)
|
|
1455
1508
|
return null;
|
|
1456
|
-
const
|
|
1509
|
+
const d = c.sections.map(bt);
|
|
1457
1510
|
return {
|
|
1458
|
-
id: c.id ||
|
|
1511
|
+
id: c.id || Ue(),
|
|
1459
1512
|
createdAt: c.createdAt,
|
|
1460
1513
|
updatedAt: c.updatedAt,
|
|
1461
1514
|
publishedAt: c.publishedAt,
|
|
1462
1515
|
isPublic: c.isPublic ?? !0,
|
|
1463
1516
|
templateConfig: c.templateConfig,
|
|
1464
|
-
slug:
|
|
1465
|
-
sections: Object.fromEntries(
|
|
1466
|
-
sectionIds:
|
|
1467
|
-
locales: Object.fromEntries(S.map(({ locale:
|
|
1517
|
+
slug: h,
|
|
1518
|
+
sections: Object.fromEntries(d.map((m) => [m.id, m])),
|
|
1519
|
+
sectionIds: d.map((m) => m.id),
|
|
1520
|
+
locales: Object.fromEntries(S.map(({ locale: m, page: j }) => [m, j.meta])),
|
|
1468
1521
|
dataSource: c.dataSource ? Object.fromEntries(
|
|
1469
1522
|
// 获取 dataSource 中所有 section ID
|
|
1470
|
-
[...new Set(S.flatMap(({ page:
|
|
1471
|
-
|
|
1523
|
+
[...new Set(S.flatMap(({ page: m }) => Object.keys(m.dataSource ?? {})))].map((m) => [
|
|
1524
|
+
m,
|
|
1472
1525
|
Object.fromEntries(
|
|
1473
|
-
S.map(({ locale: j, page:
|
|
1474
|
-
const T =
|
|
1526
|
+
S.map(({ locale: j, page: N }) => {
|
|
1527
|
+
const T = N.dataSource?.[m];
|
|
1475
1528
|
return [j, T || {}];
|
|
1476
1529
|
})
|
|
1477
1530
|
)
|
|
1478
1531
|
])
|
|
1479
1532
|
) : Object.fromEntries(
|
|
1480
1533
|
// 获取所有 section ID
|
|
1481
|
-
[...new Set(S.flatMap(({ page:
|
|
1482
|
-
|
|
1534
|
+
[...new Set(S.flatMap(({ page: m }) => m.sections.map((j) => j.id)))].map((m) => [
|
|
1535
|
+
m,
|
|
1483
1536
|
Object.fromEntries(
|
|
1484
|
-
S.map(({ locale: j, page:
|
|
1485
|
-
const T =
|
|
1537
|
+
S.map(({ locale: j, page: N }) => {
|
|
1538
|
+
const T = N.dataSource?.[m];
|
|
1486
1539
|
if (T)
|
|
1487
1540
|
return [j, T];
|
|
1488
|
-
const V =
|
|
1541
|
+
const V = N.sections.find((H) => H.id === m);
|
|
1489
1542
|
return [j, V?.properties || {}];
|
|
1490
1543
|
})
|
|
1491
1544
|
)
|
|
@@ -1494,13 +1547,13 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1494
1547
|
};
|
|
1495
1548
|
})
|
|
1496
1549
|
)
|
|
1497
|
-
),
|
|
1550
|
+
), O = L(
|
|
1498
1551
|
await Promise.all(
|
|
1499
|
-
(
|
|
1500
|
-
const S =
|
|
1552
|
+
(y?.routes || []).map(async ({ path: h }) => {
|
|
1553
|
+
const S = A ? await I(A, ce(h)) : void 0;
|
|
1501
1554
|
return {
|
|
1502
1555
|
...S,
|
|
1503
|
-
id: S?.id ||
|
|
1556
|
+
id: S?.id || Ue(),
|
|
1504
1557
|
createdAt: S?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1505
1558
|
updatedAt: S?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1506
1559
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -1514,60 +1567,60 @@ async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1514
1567
|
};
|
|
1515
1568
|
})
|
|
1516
1569
|
)
|
|
1517
|
-
), w =
|
|
1518
|
-
await Promise.all((
|
|
1570
|
+
), w = f ? L(
|
|
1571
|
+
await Promise.all((y.components || []).map(async ({ id: h }) => u(f, h)))
|
|
1519
1572
|
) : [];
|
|
1520
1573
|
if (e) {
|
|
1521
|
-
const
|
|
1522
|
-
|
|
1574
|
+
const h = (...S) => {
|
|
1575
|
+
p.info(`[${o ? $(t) : $(b(t, "../../../../"))}] importAssets:`, ...S);
|
|
1523
1576
|
};
|
|
1524
1577
|
try {
|
|
1525
|
-
|
|
1578
|
+
h("wait image-bin api ready"), await $t({
|
|
1526
1579
|
resources: [`${Et(ut)}/api/sdk/uploads`],
|
|
1527
|
-
validateStatus: (
|
|
1528
|
-
}),
|
|
1580
|
+
validateStatus: (d) => d >= 200 && d <= 500
|
|
1581
|
+
}), h("image-bin api is ready");
|
|
1529
1582
|
const S = {}, c = {};
|
|
1530
|
-
|
|
1583
|
+
h("start to upload assets"), await Promise.allSettled([
|
|
1531
1584
|
ze(w, S, {
|
|
1532
|
-
getFilePath: (
|
|
1533
|
-
onFinish: (
|
|
1534
|
-
|
|
1585
|
+
getFilePath: (d) => f && b(f, d),
|
|
1586
|
+
onFinish: (d) => {
|
|
1587
|
+
h(`upload ${d.length} component assets`);
|
|
1535
1588
|
}
|
|
1536
1589
|
}),
|
|
1537
|
-
ze(
|
|
1538
|
-
getFilePath: (
|
|
1539
|
-
const j = je(
|
|
1540
|
-
return i &&
|
|
1590
|
+
ze(C, c, {
|
|
1591
|
+
getFilePath: (d, m) => {
|
|
1592
|
+
const j = je(C, m.slice(0, 1));
|
|
1593
|
+
return i && b(i, M(j.slug), d);
|
|
1541
1594
|
},
|
|
1542
|
-
onFinish: (
|
|
1543
|
-
|
|
1595
|
+
onFinish: (d) => {
|
|
1596
|
+
h(`upload ${d.length} page assets`);
|
|
1544
1597
|
}
|
|
1545
1598
|
})
|
|
1546
|
-
]),
|
|
1599
|
+
]), h("upload assets done"), Pe.clear(), global.gc && global.gc();
|
|
1547
1600
|
} catch (S) {
|
|
1548
|
-
|
|
1601
|
+
h("Error during asset import:", S);
|
|
1549
1602
|
}
|
|
1550
1603
|
}
|
|
1551
1604
|
const k = {};
|
|
1552
1605
|
if (s) {
|
|
1553
|
-
const
|
|
1606
|
+
const h = r && b(M(r), "../../resources/components"), S = L(
|
|
1554
1607
|
await Promise.all(
|
|
1555
|
-
(
|
|
1608
|
+
(y.resources?.components || []).map(async ({ id: c }) => u(h, c))
|
|
1556
1609
|
)
|
|
1557
1610
|
);
|
|
1558
1611
|
S.length > 0 && (k.components = Object.fromEntries(
|
|
1559
|
-
S.map((c,
|
|
1612
|
+
S.map((c, d) => [c.id, { index: d, component: c }])
|
|
1560
1613
|
));
|
|
1561
1614
|
}
|
|
1562
1615
|
return {
|
|
1563
|
-
supportedLocales:
|
|
1564
|
-
pageIds:
|
|
1565
|
-
components: Object.fromEntries(w.map((
|
|
1566
|
-
pages: Object.fromEntries(
|
|
1567
|
-
config:
|
|
1616
|
+
supportedLocales: y.supportedLocales,
|
|
1617
|
+
pageIds: C.map((h) => h.id),
|
|
1618
|
+
components: Object.fromEntries(w.map((h, S) => [h.id, { index: S, data: h }])),
|
|
1619
|
+
pages: Object.fromEntries(C.map((h) => [h.id, h])),
|
|
1620
|
+
config: y.config || {},
|
|
1568
1621
|
resources: k,
|
|
1569
|
-
routeIds:
|
|
1570
|
-
routes: Object.fromEntries(
|
|
1622
|
+
routeIds: O.map((h) => h.id),
|
|
1623
|
+
routes: Object.fromEntries(O.map((h) => [h.id, h])),
|
|
1571
1624
|
dataSourceIds: [],
|
|
1572
1625
|
dataSources: {}
|
|
1573
1626
|
};
|
|
@@ -1583,16 +1636,16 @@ async function qe(t, e, {
|
|
|
1583
1636
|
} = {}) {
|
|
1584
1637
|
try {
|
|
1585
1638
|
n && dt(n);
|
|
1586
|
-
} catch (
|
|
1587
|
-
|
|
1639
|
+
} catch (y) {
|
|
1640
|
+
p.error("clear preload page cache error", { error: y });
|
|
1588
1641
|
}
|
|
1589
|
-
const { pages: l, pageIds: r, routeIds: i, routes:
|
|
1642
|
+
const { pages: l, pageIds: r, routeIds: i, routes: f, supportedLocales: A } = t;
|
|
1590
1643
|
if (n === "production") {
|
|
1591
|
-
let
|
|
1592
|
-
for (const
|
|
1593
|
-
const I =
|
|
1644
|
+
let y = s ?? [], g = null;
|
|
1645
|
+
for (const u of i ?? []) {
|
|
1646
|
+
const I = f?.[u];
|
|
1594
1647
|
if (I?.params && I?.params.length > 0 && I?.paramsOptions && I?.paramsOptions.length > 0) {
|
|
1595
|
-
const
|
|
1648
|
+
const C = be({
|
|
1596
1649
|
basePath: I.path,
|
|
1597
1650
|
params: I.params,
|
|
1598
1651
|
routeId: I.id,
|
|
@@ -1601,117 +1654,117 @@ async function qe(t, e, {
|
|
|
1601
1654
|
currentParams: [],
|
|
1602
1655
|
currentOptionIds: [],
|
|
1603
1656
|
result: []
|
|
1604
|
-
}),
|
|
1605
|
-
|
|
1606
|
-
} else s ||
|
|
1657
|
+
}), O = Object.fromEntries(C.map((w) => [`${u}-${w.paramOptionIds.join("-")}`, w]));
|
|
1658
|
+
g = { ...g || {}, ...O }, s || (y = [...y, ...C.map((w) => `${u}-${w.paramOptionIds.join("-")}`)]);
|
|
1659
|
+
} else s || y.push(u);
|
|
1607
1660
|
}
|
|
1608
|
-
|
|
1609
|
-
for (const
|
|
1610
|
-
let I =
|
|
1661
|
+
p.info("routeIds to be published: ", y);
|
|
1662
|
+
for (const u of y) {
|
|
1663
|
+
let I = u;
|
|
1611
1664
|
if (I.includes("-")) {
|
|
1612
1665
|
const [w] = I.split("-");
|
|
1613
1666
|
I = w;
|
|
1614
1667
|
}
|
|
1615
|
-
const
|
|
1616
|
-
if (!
|
|
1668
|
+
const C = f?.[I];
|
|
1669
|
+
if (!C) {
|
|
1617
1670
|
const w = e.pageIds.indexOf(I);
|
|
1618
1671
|
w !== -1 && o && (e.pageIds.splice(w, 1), delete e.pages[I]);
|
|
1619
1672
|
for (const k of e.pageIds)
|
|
1620
1673
|
k.includes(`${I}-`) && (e.pageIds.splice(e.pageIds.indexOf(k), 1), delete e.pages[k]);
|
|
1621
|
-
|
|
1674
|
+
p.info("delete main route page", I);
|
|
1622
1675
|
continue;
|
|
1623
1676
|
}
|
|
1624
|
-
if (
|
|
1625
|
-
const w = e.pageIds.indexOf(
|
|
1626
|
-
w !== -1 && o && (e.pageIds.splice(w, 1), delete e.pages[
|
|
1677
|
+
if (u.includes("-") && !g?.[u]) {
|
|
1678
|
+
const w = e.pageIds.indexOf(u);
|
|
1679
|
+
w !== -1 && o && (e.pageIds.splice(w, 1), delete e.pages[u]), p.info("delete page", u);
|
|
1627
1680
|
continue;
|
|
1628
1681
|
}
|
|
1629
|
-
if (!
|
|
1630
|
-
|
|
1682
|
+
if (!C.displayTemplateId) {
|
|
1683
|
+
p.info("no display template", u);
|
|
1631
1684
|
continue;
|
|
1632
1685
|
}
|
|
1633
|
-
const
|
|
1634
|
-
if (!
|
|
1635
|
-
|
|
1686
|
+
const O = l[C.displayTemplateId];
|
|
1687
|
+
if (!O) {
|
|
1688
|
+
p.info("no template page", u);
|
|
1636
1689
|
continue;
|
|
1637
1690
|
}
|
|
1638
|
-
if (e.pageIds.includes(
|
|
1639
|
-
if (
|
|
1640
|
-
e.pages[
|
|
1641
|
-
page:
|
|
1642
|
-
route:
|
|
1691
|
+
if (e.pageIds.includes(u)) {
|
|
1692
|
+
if (p.info("has need update page", u), a === "replace")
|
|
1693
|
+
e.pages[u] = me({
|
|
1694
|
+
page: O,
|
|
1695
|
+
route: C,
|
|
1643
1696
|
state: t,
|
|
1644
|
-
routeId:
|
|
1645
|
-
routePathInfo:
|
|
1646
|
-
}),
|
|
1697
|
+
routeId: u,
|
|
1698
|
+
routePathInfo: g?.[u]
|
|
1699
|
+
}), p.info("replace page", u);
|
|
1647
1700
|
else if (a === "byUpdateTime") {
|
|
1648
|
-
const w = e.pages[
|
|
1649
|
-
(!w ||
|
|
1650
|
-
page:
|
|
1651
|
-
route:
|
|
1701
|
+
const w = e.pages[C.id];
|
|
1702
|
+
(!w || C.updatedAt && C.updatedAt > w.updatedAt) && (e.pages[u] = me({
|
|
1703
|
+
page: O,
|
|
1704
|
+
route: C,
|
|
1652
1705
|
state: t,
|
|
1653
|
-
routeId:
|
|
1654
|
-
routePathInfo:
|
|
1655
|
-
}),
|
|
1706
|
+
routeId: u,
|
|
1707
|
+
routePathInfo: g?.[u]
|
|
1708
|
+
}), p.info("replace page by update time", u));
|
|
1656
1709
|
}
|
|
1657
1710
|
} else
|
|
1658
|
-
e.pageIds.push(
|
|
1659
|
-
page:
|
|
1660
|
-
route:
|
|
1711
|
+
e.pageIds.push(u), e.pages[u] = me({
|
|
1712
|
+
page: O,
|
|
1713
|
+
route: C,
|
|
1661
1714
|
state: t,
|
|
1662
|
-
routeId:
|
|
1663
|
-
routePathInfo:
|
|
1664
|
-
}),
|
|
1715
|
+
routeId: u,
|
|
1716
|
+
routePathInfo: g?.[u]
|
|
1717
|
+
}), p.info("add page", u);
|
|
1665
1718
|
}
|
|
1666
1719
|
if (o && !s)
|
|
1667
|
-
for (const
|
|
1668
|
-
|
|
1720
|
+
for (const u of e.pageIds)
|
|
1721
|
+
y?.includes(u) || (delete e.pages[u], p.info("delete page", u)), e.pageIds = [...e.pageIds].filter((I) => y?.includes(I));
|
|
1669
1722
|
} else {
|
|
1670
|
-
for (const
|
|
1671
|
-
const
|
|
1672
|
-
if (
|
|
1673
|
-
if (e.pageIds.includes(
|
|
1723
|
+
for (const y of r) {
|
|
1724
|
+
const g = l[y];
|
|
1725
|
+
if (g)
|
|
1726
|
+
if (e.pageIds.includes(g.id)) {
|
|
1674
1727
|
if (a === "replace")
|
|
1675
|
-
e.pages[
|
|
1728
|
+
e.pages[g.id] = g;
|
|
1676
1729
|
else if (a === "byUpdateTime") {
|
|
1677
|
-
const
|
|
1678
|
-
(!
|
|
1730
|
+
const u = e.pages[g.id];
|
|
1731
|
+
(!u || g.updatedAt && g.updatedAt > u.updatedAt) && (e.pages[g.id] = g);
|
|
1679
1732
|
}
|
|
1680
1733
|
} else
|
|
1681
|
-
e.pageIds.push(
|
|
1734
|
+
e.pageIds.push(g.id), e.pages[g.id] = g;
|
|
1682
1735
|
}
|
|
1683
|
-
for (const
|
|
1684
|
-
const
|
|
1685
|
-
if (
|
|
1686
|
-
if (e.routeIds.includes(
|
|
1736
|
+
for (const y of i) {
|
|
1737
|
+
const g = f[y];
|
|
1738
|
+
if (g)
|
|
1739
|
+
if (e.routeIds.includes(g.id)) {
|
|
1687
1740
|
if (a === "replace")
|
|
1688
|
-
e.routes[
|
|
1741
|
+
e.routes[g.id] = g;
|
|
1689
1742
|
else if (a === "byUpdateTime") {
|
|
1690
|
-
const
|
|
1691
|
-
(!
|
|
1743
|
+
const u = e.routes[g.id];
|
|
1744
|
+
(!u || g.updatedAt && g.updatedAt > u.updatedAt) && (e.routes[g.id] = g);
|
|
1692
1745
|
}
|
|
1693
1746
|
} else
|
|
1694
|
-
e.routeIds.push(
|
|
1747
|
+
e.routeIds.push(g.id), e.routes[g.id] = g;
|
|
1695
1748
|
}
|
|
1696
1749
|
}
|
|
1697
|
-
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...
|
|
1698
|
-
for (const
|
|
1699
|
-
delete e.components[
|
|
1700
|
-
let
|
|
1701
|
-
|
|
1750
|
+
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ae(A)), o)
|
|
1751
|
+
for (const y of Object.keys(e.components))
|
|
1752
|
+
delete e.components[y];
|
|
1753
|
+
let R = JSON.parse(JSON.stringify(t.components));
|
|
1754
|
+
R = Object.fromEntries(
|
|
1702
1755
|
await Promise.all(
|
|
1703
|
-
Object.entries(
|
|
1704
|
-
const
|
|
1756
|
+
Object.entries(R).map(async ([y, g]) => {
|
|
1757
|
+
const u = await st(g?.data);
|
|
1705
1758
|
return [
|
|
1706
|
-
|
|
1759
|
+
y,
|
|
1707
1760
|
{
|
|
1708
|
-
...
|
|
1709
|
-
data:
|
|
1761
|
+
...g,
|
|
1762
|
+
data: u
|
|
1710
1763
|
}
|
|
1711
1764
|
];
|
|
1712
1765
|
})
|
|
1713
1766
|
)
|
|
1714
|
-
), Object.assign(e.components,
|
|
1767
|
+
), Object.assign(e.components, R), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), De(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1715
1768
|
}
|
|
1716
1769
|
const st = lt(
|
|
1717
1770
|
async (t) => {
|
|
@@ -1734,7 +1787,7 @@ const st = lt(
|
|
|
1734
1787
|
});
|
|
1735
1788
|
}));
|
|
1736
1789
|
} catch (a) {
|
|
1737
|
-
|
|
1790
|
+
p.error("getPropertiesFromCode error", { componentId: t.id, name: t.name }, { error: a });
|
|
1738
1791
|
}
|
|
1739
1792
|
}
|
|
1740
1793
|
return t;
|
|
@@ -1743,36 +1796,36 @@ const st = lt(
|
|
|
1743
1796
|
subdir: "getPropertiesFromCode"
|
|
1744
1797
|
}
|
|
1745
1798
|
);
|
|
1746
|
-
let
|
|
1799
|
+
let le, Q, pe, ue;
|
|
1747
1800
|
const at = () => Ot({
|
|
1748
1801
|
types: [
|
|
1749
1802
|
{ did: Ye, type: xe },
|
|
1750
1803
|
{ did: zt, type: xe }
|
|
1751
1804
|
]
|
|
1752
|
-
}),
|
|
1805
|
+
}), hs = async () => {
|
|
1753
1806
|
const t = at(), e = {};
|
|
1754
1807
|
for (const s of t) {
|
|
1755
|
-
const o = (await
|
|
1808
|
+
const o = (await ye("**/.blocklet/pages/pages.config.yml", {
|
|
1756
1809
|
cwd: s.path,
|
|
1757
1810
|
absolute: !0
|
|
1758
|
-
}))[0], n = o &&
|
|
1759
|
-
if (n && await
|
|
1811
|
+
}))[0], n = o && b(M(o), "../../chunks");
|
|
1812
|
+
if (n && await G(n)) {
|
|
1760
1813
|
const l = await Dt(n);
|
|
1761
1814
|
for (const r of l)
|
|
1762
|
-
e[r] =
|
|
1815
|
+
e[r] = b(n, r);
|
|
1763
1816
|
}
|
|
1764
1817
|
}
|
|
1765
1818
|
return e;
|
|
1766
1819
|
};
|
|
1767
1820
|
function ot() {
|
|
1768
|
-
return
|
|
1821
|
+
return le = (async () => {
|
|
1769
1822
|
const t = at();
|
|
1770
1823
|
Q = (await Promise.all(
|
|
1771
1824
|
t.map(async (s) => {
|
|
1772
1825
|
const a = s.path ? await tt(s.path, { importAssets: !1 }) : void 0;
|
|
1773
1826
|
return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
|
|
1774
1827
|
})
|
|
1775
|
-
)).filter((s) => !!s),
|
|
1828
|
+
)).filter((s) => !!s), pe = Q.reduce(
|
|
1776
1829
|
(s, a) => Object.assign(
|
|
1777
1830
|
s,
|
|
1778
1831
|
Object.fromEntries(
|
|
@@ -1790,7 +1843,7 @@ function ot() {
|
|
|
1790
1843
|
),
|
|
1791
1844
|
{}
|
|
1792
1845
|
);
|
|
1793
|
-
|
|
1846
|
+
ue = Object.fromEntries(
|
|
1794
1847
|
await Promise.all(
|
|
1795
1848
|
Object.entries(e).map(async ([s, a]) => {
|
|
1796
1849
|
const o = await st(a.component);
|
|
@@ -1804,33 +1857,33 @@ function ot() {
|
|
|
1804
1857
|
})
|
|
1805
1858
|
)
|
|
1806
1859
|
);
|
|
1807
|
-
})(),
|
|
1860
|
+
})(), le;
|
|
1808
1861
|
}
|
|
1809
|
-
function
|
|
1810
|
-
const e =
|
|
1862
|
+
function ys(t) {
|
|
1863
|
+
const e = Ce(
|
|
1811
1864
|
async () => {
|
|
1812
1865
|
await ot().catch((s) => {
|
|
1813
|
-
|
|
1866
|
+
p.error("load resource states error", { error: s });
|
|
1814
1867
|
}), await t?.({
|
|
1815
1868
|
states: Q,
|
|
1816
|
-
pages:
|
|
1817
|
-
components:
|
|
1869
|
+
pages: pe,
|
|
1870
|
+
components: ue
|
|
1818
1871
|
});
|
|
1819
1872
|
},
|
|
1820
1873
|
3e3,
|
|
1821
1874
|
// 3s
|
|
1822
1875
|
{ leading: !1, trailing: !0 }
|
|
1823
1876
|
);
|
|
1824
|
-
return e(), E.events.on(E.Events.componentAdded, e), E.events.on(E.Events.componentRemoved, e), E.events.on(E.Events.componentStarted, e), E.events.on(E.Events.componentStopped, e), E.events.on(E.Events.componentUpdated, e), E.events.on(
|
|
1825
|
-
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(
|
|
1877
|
+
return e(), E.events.on(E.Events.componentAdded, e), E.events.on(E.Events.componentRemoved, e), E.events.on(E.Events.componentStarted, e), E.events.on(E.Events.componentStopped, e), E.events.on(E.Events.componentUpdated, e), E.events.on(we, e), () => {
|
|
1878
|
+
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);
|
|
1826
1879
|
};
|
|
1827
1880
|
}
|
|
1828
1881
|
const nt = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), rt = globalThis;
|
|
1829
1882
|
rt[nt]?.();
|
|
1830
|
-
rt[nt] =
|
|
1883
|
+
rt[nt] = ys(async ({ pages: t, components: e }) => {
|
|
1831
1884
|
const s = await D.getProjectIds();
|
|
1832
|
-
|
|
1833
|
-
const a =
|
|
1885
|
+
p.info(`start update resource states projects(${s.length})`, s);
|
|
1886
|
+
const a = Re(10);
|
|
1834
1887
|
await Promise.race([
|
|
1835
1888
|
new Promise((o) => {
|
|
1836
1889
|
setTimeout(() => {
|
|
@@ -1849,7 +1902,7 @@ rt[nt] = gs(async ({ pages: t, components: e }) => {
|
|
|
1849
1902
|
)
|
|
1850
1903
|
)
|
|
1851
1904
|
]).catch((o) => {
|
|
1852
|
-
|
|
1905
|
+
p.error("update resource states failed:", o);
|
|
1853
1906
|
});
|
|
1854
1907
|
});
|
|
1855
1908
|
D.startPeriodicCheck();
|
|
@@ -1869,68 +1922,68 @@ async function it({
|
|
|
1869
1922
|
}) {
|
|
1870
1923
|
const a = D.sharedInstances[t];
|
|
1871
1924
|
if (!a) {
|
|
1872
|
-
|
|
1925
|
+
p.info(`projectId: ${t} not found in sharedInstances`);
|
|
1873
1926
|
return;
|
|
1874
1927
|
}
|
|
1875
|
-
const o = a.syncedStore.resources.pages, n = a.syncedStore.resources.components, l = await
|
|
1928
|
+
const o = a.syncedStore.resources.pages, n = a.syncedStore.resources.components, l = await U.findByPk(t, {
|
|
1876
1929
|
attributes: { exclude: ["productionState", "relatedBlocklets"] }
|
|
1877
1930
|
});
|
|
1878
1931
|
let r;
|
|
1879
1932
|
if (l?.useAllResources)
|
|
1880
1933
|
r = s;
|
|
1881
1934
|
else {
|
|
1882
|
-
const
|
|
1883
|
-
r = Object.fromEntries(Object.entries(s || {}).filter(([
|
|
1935
|
+
const R = (await ke.findAll({ where: { projectId: t } })).map((y) => y.componentId);
|
|
1936
|
+
r = Object.fromEntries(Object.entries(s || {}).filter(([y]) => R.includes(y)));
|
|
1884
1937
|
}
|
|
1885
|
-
const i = !Ge(o, e),
|
|
1886
|
-
i ||
|
|
1887
|
-
i && (a.syncedStore.resources.pages = e,
|
|
1938
|
+
const i = !Ge(o, e), f = !Ge(n, r);
|
|
1939
|
+
i || f ? a.transact(() => {
|
|
1940
|
+
i && (a.syncedStore.resources.pages = e, p.info(`[${t}] pages resources updated: ${Object.keys(e || {}).length} pages`)), f && (a.syncedStore.resources.components = r, p.info(
|
|
1888
1941
|
`[${t}] components resources updated: ${Object.keys(r || {}).length} components`
|
|
1889
1942
|
));
|
|
1890
|
-
}) :
|
|
1943
|
+
}) : p.info(`[${t}] resource states unchanged, skipping update`), p.info(`update [${t}] resource states summary:`, {
|
|
1891
1944
|
pages: Object.keys(a.syncedStore.resources.pages || {}).length,
|
|
1892
1945
|
components: Object.keys(a.syncedStore.resources.components || {}).length,
|
|
1893
1946
|
pagesChanged: i,
|
|
1894
|
-
componentsChanged:
|
|
1947
|
+
componentsChanged: f
|
|
1895
1948
|
});
|
|
1896
1949
|
}
|
|
1897
|
-
const
|
|
1898
|
-
async function
|
|
1899
|
-
if (!
|
|
1900
|
-
const e =
|
|
1950
|
+
const he = /* @__PURE__ */ new Map();
|
|
1951
|
+
async function Ss(t) {
|
|
1952
|
+
if (!he.has(t)) {
|
|
1953
|
+
const e = Ce(async (s) => it({
|
|
1901
1954
|
projectId: s,
|
|
1902
|
-
pages:
|
|
1903
|
-
components:
|
|
1955
|
+
pages: pe,
|
|
1956
|
+
components: ue
|
|
1904
1957
|
}), 3e3);
|
|
1905
|
-
|
|
1958
|
+
he.set(t, e);
|
|
1906
1959
|
}
|
|
1907
|
-
return
|
|
1960
|
+
return he.get(t)(t);
|
|
1908
1961
|
}
|
|
1909
|
-
async function
|
|
1910
|
-
|
|
1962
|
+
async function sa() {
|
|
1963
|
+
p.info("trigger reload all project resource"), E.events.emit(we);
|
|
1911
1964
|
}
|
|
1912
|
-
async function
|
|
1965
|
+
async function aa({
|
|
1913
1966
|
ensureLoaded: t = !0
|
|
1914
1967
|
} = {}) {
|
|
1915
|
-
return t && (
|
|
1968
|
+
return t && (le ??= ot(), await le), { states: Q, pages: pe, components: ue };
|
|
1916
1969
|
}
|
|
1917
1970
|
export {
|
|
1918
1971
|
Ye as C,
|
|
1919
|
-
|
|
1972
|
+
U as P,
|
|
1920
1973
|
xe as R,
|
|
1921
1974
|
D as S,
|
|
1922
1975
|
W as a,
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1976
|
+
ea as b,
|
|
1977
|
+
Zs as c,
|
|
1978
|
+
ta as d,
|
|
1979
|
+
us as e,
|
|
1980
|
+
fs as f,
|
|
1981
|
+
aa as g,
|
|
1982
|
+
ms as h,
|
|
1930
1983
|
tt as i,
|
|
1931
|
-
|
|
1932
|
-
|
|
1984
|
+
ys as j,
|
|
1985
|
+
sa as k,
|
|
1933
1986
|
qe as m,
|
|
1934
|
-
|
|
1935
|
-
|
|
1987
|
+
gs as t,
|
|
1988
|
+
Ss as u
|
|
1936
1989
|
};
|