@blocklet/pages-kit-inner-components 0.6.95 → 0.6.97
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-D2b0QUgx.js +1 -0
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/chunks/{site-state-tBjPpz08.js → site-state-zENZxyOj.js} +297 -272
- package/lib/es/resources.js +1 -1
- package/lib/es/site-state.js +1 -1
- package/package.json +17 -17
- package/lib/cjs/chunks/site-state-CaWZo_HF.js +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { d as Ne, l as f, I as et, c as tt, m as st, b as ot } from "./components-DLwSTd_N.js";
|
|
2
2
|
import { getYjsValue as V, syncedStore as at } from "@syncedstore/core";
|
|
3
|
-
import * as
|
|
4
|
-
import { setPageDataSource as
|
|
5
|
-
import { getRouteMetaDataByOptionIds as
|
|
3
|
+
import * as _ from "yjs";
|
|
4
|
+
import { setPageDataSource as nt } from "@blocklet/pages-kit/utils/data-source";
|
|
5
|
+
import { getRouteMetaDataByOptionIds as rt, generateParamCombinations as Ie } from "@blocklet/pages-kit/utils/route";
|
|
6
6
|
import Ee from "lodash/cloneDeep";
|
|
7
7
|
import E from "@blocklet/sdk/lib/config";
|
|
8
|
-
import { mkdtempSync as it, existsSync as M, readFileSync as J, renameSync as
|
|
8
|
+
import { mkdtempSync as it, existsSync as M, readFileSync as J, renameSync as Re, mkdirSync as N, rmSync as Fe, writeFileSync as te, copyFileSync as ct, lstatSync as x, readdirSync as lt, createWriteStream as pt } from "fs";
|
|
9
9
|
import { join as b, basename as k, dirname as L } from "path";
|
|
10
|
-
import { nextId as
|
|
10
|
+
import { nextId as je } from "@blocklet/pages-kit/utils/common";
|
|
11
11
|
import { unzipSection as ut } from "@blocklet/pages-kit/utils/page-model";
|
|
12
12
|
import { getComponentDependencies as dt } from "@blocklet/pages-kit/utils/property";
|
|
13
13
|
import { getComponentWebEndpoint as ft, getResources as mt, call as gt } from "@blocklet/sdk/lib/component";
|
|
@@ -15,27 +15,27 @@ import { reactive as ht } from "@reactivedata/reactive";
|
|
|
15
15
|
import { globSync as se } from "glob";
|
|
16
16
|
import * as de from "lib0/decoding";
|
|
17
17
|
import * as D from "lib0/encoding";
|
|
18
|
-
import
|
|
18
|
+
import Ge from "lodash/debounce";
|
|
19
19
|
import be from "lodash/get";
|
|
20
|
-
import
|
|
21
|
-
import
|
|
20
|
+
import Ae from "lodash/isEmpty";
|
|
21
|
+
import De from "lodash/set";
|
|
22
22
|
import yt from "lodash/union";
|
|
23
|
-
import { LRUCache as
|
|
23
|
+
import { LRUCache as we } from "lru-cache";
|
|
24
24
|
import St from "p-limit";
|
|
25
|
-
import { DataTypes as R, Sequelize as It, Model as xe, Op as
|
|
25
|
+
import { DataTypes as R, Sequelize as It, Model as xe, Op as Pe } from "sequelize";
|
|
26
26
|
import { pipeline as Et } from "stream/promises";
|
|
27
27
|
import { x as bt } from "tar";
|
|
28
|
-
import { withoutTrailingSlash as
|
|
29
|
-
import
|
|
30
|
-
import { Awareness as Pt, encodeAwarenessUpdate as
|
|
28
|
+
import { withoutTrailingSlash as Be, withLeadingSlash as At, joinURL as Y } from "ufo";
|
|
29
|
+
import wt from "wait-on";
|
|
30
|
+
import { Awareness as Pt, encodeAwarenessUpdate as Te, removeAwarenessStates as Ot, applyAwarenessUpdate as Ct } from "y-protocols/awareness";
|
|
31
31
|
import { writeUpdate as vt, writeSyncStep1 as Rt, readSyncMessage as jt } from "y-protocols/sync";
|
|
32
|
-
import * as
|
|
33
|
-
import { m as
|
|
32
|
+
import * as B from "yaml";
|
|
33
|
+
import { m as ke } from "./html-DOgzvdOd.js";
|
|
34
34
|
import "sqlite3";
|
|
35
35
|
import "@blocklet/pages-kit/types/state";
|
|
36
36
|
const Dt = R.sqlite.DATE.parse;
|
|
37
37
|
R.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Dt(t, e);
|
|
38
|
-
const
|
|
38
|
+
const F = new It({
|
|
39
39
|
dialect: "sqlite",
|
|
40
40
|
storage: Ne,
|
|
41
41
|
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
@@ -48,16 +48,15 @@ const _ = new It({
|
|
|
48
48
|
logging: process.env.ENABLE_SEQUELIZE_LOGGING === "true" ? console.log : !1
|
|
49
49
|
// logQueryParameters: true,
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_.query("pragma mmap_size = 33554432;");
|
|
51
|
+
F.query("PRAGMA journal_mode = WAL;");
|
|
52
|
+
F.query("PRAGMA synchronous = normal;");
|
|
53
|
+
F.query("PRAGMA journal_size_limit = 67108864;");
|
|
54
|
+
F.query("PRAGMA cache_size = 10000;");
|
|
56
55
|
process.on("SIGINT", async () => {
|
|
57
|
-
await
|
|
56
|
+
await F.close(), process.exit(0);
|
|
58
57
|
});
|
|
59
58
|
process.on("SIGTERM", async () => {
|
|
60
|
-
await
|
|
59
|
+
await F.close(), process.exit(0);
|
|
61
60
|
});
|
|
62
61
|
async function Tt(t, e) {
|
|
63
62
|
try {
|
|
@@ -77,16 +76,16 @@ let ge = null;
|
|
|
77
76
|
ge && clearInterval(ge);
|
|
78
77
|
ge = setInterval(
|
|
79
78
|
async () => {
|
|
80
|
-
f.info("Start cleanupSqliteMemory"), await Tt(
|
|
79
|
+
f.info("Start cleanupSqliteMemory"), await Tt(F, Ne), f.info("End cleanupSqliteMemory");
|
|
81
80
|
},
|
|
82
81
|
60 * 1e3 * 10
|
|
83
82
|
// 10 minutes
|
|
84
83
|
);
|
|
85
|
-
const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o",
|
|
86
|
-
class
|
|
84
|
+
const kt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Le = "page", he = "trigger-reload-project-resource", Ve = kt, Lt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Ut = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
|
|
85
|
+
class Oe extends xe {
|
|
87
86
|
// Foreign key to Component
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
Oe.init(
|
|
90
89
|
{
|
|
91
90
|
id: {
|
|
92
91
|
type: R.UUID,
|
|
@@ -103,9 +102,9 @@ Pe.init(
|
|
|
103
102
|
allowNull: !1
|
|
104
103
|
}
|
|
105
104
|
},
|
|
106
|
-
{ sequelize:
|
|
105
|
+
{ sequelize: F, tableName: "ProjectComponents", timestamps: !1 }
|
|
107
106
|
);
|
|
108
|
-
const $t = "SLUG_INVALID",
|
|
107
|
+
const $t = "SLUG_INVALID", K = (t) => ({
|
|
109
108
|
error: "slugInvalid",
|
|
110
109
|
code: $t,
|
|
111
110
|
field: "slug",
|
|
@@ -115,12 +114,12 @@ const $t = "SLUG_INVALID", q = (t) => ({
|
|
|
115
114
|
code: "SLUG_REQUIRED",
|
|
116
115
|
field: "slug",
|
|
117
116
|
message: () => "Project slug is required"
|
|
118
|
-
},
|
|
117
|
+
}, _t = {
|
|
119
118
|
error: "slugAlreadyExists",
|
|
120
119
|
code: "SLUG_EXISTS",
|
|
121
120
|
field: "slug",
|
|
122
121
|
message: (t) => `Project slug "${t}" already exists`
|
|
123
|
-
},
|
|
122
|
+
}, Nt = [
|
|
124
123
|
/\.\./,
|
|
125
124
|
// Directory traversal
|
|
126
125
|
/<[^>]*>/,
|
|
@@ -136,17 +135,17 @@ const $t = "SLUG_INVALID", q = (t) => ({
|
|
|
136
135
|
// Control characters
|
|
137
136
|
/[^a-zA-Z0-9-_@/\\:]/
|
|
138
137
|
// Only allow specific characters
|
|
139
|
-
],
|
|
138
|
+
], Ue = (t) => {
|
|
140
139
|
if (!t) return "";
|
|
141
140
|
if (t === "/") return "/";
|
|
142
|
-
const e =
|
|
143
|
-
return
|
|
141
|
+
const e = Be(t);
|
|
142
|
+
return At(e) || "/";
|
|
144
143
|
}, Ft = (t) => t.did === Ut;
|
|
145
144
|
class U extends xe {
|
|
146
145
|
static async getProjectByIdOrSlug(e, s) {
|
|
147
146
|
return e ? U.findOne({
|
|
148
147
|
where: {
|
|
149
|
-
[
|
|
148
|
+
[Pe.or]: [{ id: e }, { slug: e }],
|
|
150
149
|
...s?.createdBy ? { createdBy: s.createdBy } : {}
|
|
151
150
|
},
|
|
152
151
|
// 软删除
|
|
@@ -161,19 +160,19 @@ class U extends xe {
|
|
|
161
160
|
return null;
|
|
162
161
|
if (e === "")
|
|
163
162
|
return Mt;
|
|
164
|
-
const o =
|
|
163
|
+
const o = Ue(e);
|
|
165
164
|
if (e !== "/" && e.endsWith("/"))
|
|
166
|
-
return
|
|
165
|
+
return K((r) => `Project slug "${r}" cannot end with /`);
|
|
167
166
|
if (/\/{2,}/.test(e))
|
|
168
|
-
return
|
|
167
|
+
return K((r) => `Project slug "${r}" cannot contain consecutive /`);
|
|
169
168
|
if (/\s/.test(e))
|
|
170
|
-
return
|
|
171
|
-
if (
|
|
172
|
-
return
|
|
173
|
-
if (E.components?.filter((
|
|
174
|
-
return
|
|
175
|
-
const
|
|
176
|
-
return
|
|
169
|
+
return K((r) => `Project slug "${r}" cannot contain whitespace`);
|
|
170
|
+
if (Nt.some((r) => r.test(e)))
|
|
171
|
+
return K((r) => `Project slug "${r}" contains invalid characters`);
|
|
172
|
+
if (E.components?.filter((r) => r.mountPoint && !Ft(r)).some((r) => Ue(r.mountPoint) === o))
|
|
173
|
+
return K((r) => `Project slug "${r}" conflicts with existing blocklet`);
|
|
174
|
+
const n = await U.findOne({ where: { slug: `${e}` } });
|
|
175
|
+
return n && n?.id !== s ? _t : null;
|
|
177
176
|
}
|
|
178
177
|
}
|
|
179
178
|
U.init(
|
|
@@ -252,9 +251,35 @@ U.init(
|
|
|
252
251
|
allowNull: !0
|
|
253
252
|
}
|
|
254
253
|
},
|
|
255
|
-
{
|
|
254
|
+
{
|
|
255
|
+
sequelize: F,
|
|
256
|
+
paranoid: !0,
|
|
257
|
+
indexes: [
|
|
258
|
+
{
|
|
259
|
+
name: "projects_slug_unique",
|
|
260
|
+
unique: !0,
|
|
261
|
+
fields: ["slug"]
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "projects_created_by",
|
|
265
|
+
fields: ["createdBy"]
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "projects_pinned_updated_meta_not_null",
|
|
269
|
+
fields: [
|
|
270
|
+
{ name: "pinnedAt", order: "DESC" },
|
|
271
|
+
{ name: "updatedAt", order: "DESC" }
|
|
272
|
+
],
|
|
273
|
+
where: {
|
|
274
|
+
meta: {
|
|
275
|
+
[Pe.ne]: null
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
}
|
|
256
281
|
);
|
|
257
|
-
U.hasMany(
|
|
282
|
+
U.hasMany(Oe, {
|
|
258
283
|
foreignKey: "projectId",
|
|
259
284
|
as: "components"
|
|
260
285
|
});
|
|
@@ -272,64 +297,64 @@ function ae(t, e, s = []) {
|
|
|
272
297
|
function T(t) {
|
|
273
298
|
return t.filter((e) => e != null);
|
|
274
299
|
}
|
|
275
|
-
function
|
|
300
|
+
function Gt(t) {
|
|
276
301
|
t.pages && Object.keys(t.pages).forEach((s) => {
|
|
277
302
|
const o = V(t.pages[s]);
|
|
278
|
-
o && o instanceof
|
|
303
|
+
o && o instanceof _.Map && oe(o);
|
|
279
304
|
});
|
|
280
305
|
const e = V(t.pages);
|
|
281
|
-
e && e instanceof
|
|
306
|
+
e && e instanceof _.Map && e.observe((s) => {
|
|
282
307
|
s.changes.keys.forEach((o, a) => {
|
|
283
308
|
if (o.action === "add") {
|
|
284
|
-
const
|
|
285
|
-
|
|
309
|
+
const n = V(t.pages[a]);
|
|
310
|
+
n && n instanceof _.Map && oe(n);
|
|
286
311
|
}
|
|
287
312
|
});
|
|
288
313
|
});
|
|
289
314
|
}
|
|
290
|
-
function
|
|
315
|
+
function xt(t) {
|
|
291
316
|
t.routes && Object.keys(t.routes).forEach((s) => {
|
|
292
317
|
const o = V(t.routes?.[s]);
|
|
293
|
-
o && o instanceof
|
|
318
|
+
o && o instanceof _.Map && oe(o);
|
|
294
319
|
});
|
|
295
320
|
const e = V(t.routes);
|
|
296
|
-
e && e instanceof
|
|
321
|
+
e && e instanceof _.Map && e.observe((s) => {
|
|
297
322
|
s.changes.keys.forEach((o, a) => {
|
|
298
323
|
if (o.action === "add") {
|
|
299
|
-
const
|
|
300
|
-
|
|
324
|
+
const n = V(t.routes?.[a]);
|
|
325
|
+
n && n instanceof _.Map && oe(n);
|
|
301
326
|
}
|
|
302
327
|
});
|
|
303
328
|
});
|
|
304
329
|
}
|
|
305
|
-
function
|
|
330
|
+
function Bt(t, e) {
|
|
306
331
|
for (const s of e || Object.keys(t.routes || {})) {
|
|
307
332
|
let o = s, a = [];
|
|
308
333
|
if (s.includes("-")) {
|
|
309
|
-
const [
|
|
310
|
-
o =
|
|
334
|
+
const [n, ...r] = s.split("-");
|
|
335
|
+
o = n, a = r || [];
|
|
311
336
|
}
|
|
312
337
|
if (t.routes?.[o] !== void 0) {
|
|
313
338
|
t.routes[o].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
339
|
+
const n = t.routes[o];
|
|
340
|
+
if (!n || !n.params || n.params.length === 0)
|
|
316
341
|
continue;
|
|
317
342
|
if (s.includes("-") && a.length > 0) {
|
|
318
|
-
const
|
|
319
|
-
|
|
343
|
+
const r = rt(a, n);
|
|
344
|
+
r && (r.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
320
345
|
}
|
|
321
346
|
if (!e) {
|
|
322
|
-
const
|
|
323
|
-
basePath:
|
|
324
|
-
params:
|
|
325
|
-
routeId:
|
|
326
|
-
paramsOptions:
|
|
347
|
+
const r = Ie({
|
|
348
|
+
basePath: n.path,
|
|
349
|
+
params: n.params,
|
|
350
|
+
routeId: n.id,
|
|
351
|
+
paramsOptions: n.paramsOptions,
|
|
327
352
|
currentIndex: 0,
|
|
328
353
|
currentParams: [],
|
|
329
354
|
currentOptionIds: [],
|
|
330
355
|
result: []
|
|
331
356
|
});
|
|
332
|
-
for (const l of
|
|
357
|
+
for (const l of r)
|
|
333
358
|
l.routeMetaData ??= {}, l.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
334
359
|
}
|
|
335
360
|
}
|
|
@@ -345,7 +370,7 @@ function fe({
|
|
|
345
370
|
f.info(
|
|
346
371
|
`Executing datasource data assembly, routeId: ${o}, routePathInfo: ${JSON.stringify(a)}`
|
|
347
372
|
);
|
|
348
|
-
const
|
|
373
|
+
const n = {
|
|
349
374
|
...Ee(t),
|
|
350
375
|
id: o,
|
|
351
376
|
slug: a?.path ?? e.path,
|
|
@@ -354,21 +379,21 @@ function fe({
|
|
|
354
379
|
publishedAt: a?.routeMetaData?.publishedAt ?? e.publishedAt,
|
|
355
380
|
isPublic: (a?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
|
|
356
381
|
};
|
|
357
|
-
for (const
|
|
382
|
+
for (const r of s.supportedLocales) {
|
|
358
383
|
if (e.dataSource) {
|
|
359
384
|
let l = e.id;
|
|
360
385
|
a && (l = a.paramOptionIds.join("-"));
|
|
361
|
-
const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[
|
|
386
|
+
const p = e.dataSource.pathDataMappings?.[l]?.dataCache?.[r.locale] ?? e.dataSource.pathDataMappings?.[l]?.dataCache?.[s.config.defaultLocale || "en"];
|
|
362
387
|
if (!p)
|
|
363
388
|
continue;
|
|
364
|
-
|
|
389
|
+
nt(n, s, r.locale, p);
|
|
365
390
|
}
|
|
366
391
|
a && a.routeMetaData && (a.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
367
392
|
}
|
|
368
|
-
return
|
|
393
|
+
return n;
|
|
369
394
|
}
|
|
370
395
|
["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
|
|
371
|
-
const Vt = 60 * 60 * 1e3, W = new
|
|
396
|
+
const Vt = 60 * 60 * 1e3, W = new we({
|
|
372
397
|
max: 100,
|
|
373
398
|
ttl: Vt,
|
|
374
399
|
ttlResolution: 10 * 1e3,
|
|
@@ -377,28 +402,28 @@ const Vt = 60 * 60 * 1e3, W = new Ae({
|
|
|
377
402
|
});
|
|
378
403
|
function zt(t, e = []) {
|
|
379
404
|
let s = 0;
|
|
380
|
-
const o = Array.from(W.keys()), a = t.map((
|
|
381
|
-
for (const
|
|
382
|
-
for (const
|
|
383
|
-
if (
|
|
384
|
-
W.delete(
|
|
405
|
+
const o = Array.from(W.keys()), a = t.map((n) => Be(n));
|
|
406
|
+
for (const n of o)
|
|
407
|
+
for (const r of a) {
|
|
408
|
+
if (ke(n, { currentPath: r })) {
|
|
409
|
+
W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
|
|
385
410
|
break;
|
|
386
411
|
}
|
|
387
412
|
for (const l of e)
|
|
388
|
-
if (
|
|
389
|
-
W.delete(
|
|
413
|
+
if (ke(n, { currentPath: `/${l}${r}` })) {
|
|
414
|
+
W.delete(n), s++, f.info(`[Cache CLEAR] key: ${n}`);
|
|
390
415
|
break;
|
|
391
416
|
}
|
|
392
417
|
}
|
|
393
418
|
return f.info(`[Cache CLEAR] cleared ${s} entries for paths:`, a), s;
|
|
394
419
|
}
|
|
395
|
-
function
|
|
420
|
+
function qt() {
|
|
396
421
|
const t = W.size;
|
|
397
422
|
return W.clear(), f.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
|
|
398
423
|
}
|
|
399
|
-
E.events.on(E.Events.envUpdate,
|
|
400
|
-
const { uploadToMediaKit:
|
|
401
|
-
function
|
|
424
|
+
E.events.on(E.Events.envUpdate, qt);
|
|
425
|
+
const { uploadToMediaKit: Kt } = require("@blocklet/uploader-server"), Ce = /^\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, $e = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, Ht = 1e4, Jt = 3e4, Z = 0, me = 1, Yt = 0, Wt = 1, ye = E, H = b(process.env.BLOCKLET_DATA_DIR, "site-state"), Ms = ["production", "draft"], _s = ["production"];
|
|
426
|
+
function ne(t) {
|
|
402
427
|
return t?.replace(/\//g, "|") || "";
|
|
403
428
|
}
|
|
404
429
|
function Xt() {
|
|
@@ -416,9 +441,9 @@ function Xt() {
|
|
|
416
441
|
resources: {}
|
|
417
442
|
};
|
|
418
443
|
}
|
|
419
|
-
class O extends
|
|
444
|
+
class O extends _.Doc {
|
|
420
445
|
constructor(e) {
|
|
421
|
-
super(), this.options = e, M(this.draftYjsFilePath) &&
|
|
446
|
+
super(), this.options = e, M(this.draftYjsFilePath) && _.applyUpdate(this, J(this.draftYjsFilePath)), this.syncedStore = ht(
|
|
422
447
|
at(
|
|
423
448
|
{
|
|
424
449
|
pages: {},
|
|
@@ -442,7 +467,7 @@ class O extends N.Doc {
|
|
|
442
467
|
static PERIODIC_CHECK_INTERVAL = 2 * 60 * 60 * 1e3;
|
|
443
468
|
// 2 hours
|
|
444
469
|
static sharedInstances = {};
|
|
445
|
-
static pageUrlMapCache = new
|
|
470
|
+
static pageUrlMapCache = new we({
|
|
446
471
|
max: 100,
|
|
447
472
|
ttl: 1e3 * 60 * 60 * 24
|
|
448
473
|
// 1 day
|
|
@@ -455,7 +480,7 @@ class O extends N.Doc {
|
|
|
455
480
|
throw new Error("Should provide project context");
|
|
456
481
|
try {
|
|
457
482
|
const s = b(H, e), o = b(H, `@del-${e}`);
|
|
458
|
-
|
|
483
|
+
Re(s, o);
|
|
459
484
|
} catch (s) {
|
|
460
485
|
f.error("Failed to safe delete project state dir:", s);
|
|
461
486
|
}
|
|
@@ -488,12 +513,12 @@ class O extends N.Doc {
|
|
|
488
513
|
const s = await U.findByPk(e, {
|
|
489
514
|
attributes: ["productionState"]
|
|
490
515
|
});
|
|
491
|
-
if (
|
|
492
|
-
const o = b(H, e, "production"), a = await
|
|
516
|
+
if (Ae(s?.productionState)) {
|
|
517
|
+
const o = b(H, e, "production"), a = await Ke(o, { includeResources: !0 }) ?? Xt();
|
|
493
518
|
if (!a?.config?.defaultLocale) {
|
|
494
519
|
a.config ??= {};
|
|
495
|
-
const
|
|
496
|
-
a.config.defaultLocale =
|
|
520
|
+
const n = ye.env.languages?.map((r) => ({ locale: r.code, name: r.name })) || [];
|
|
521
|
+
a.config.defaultLocale = n[0]?.locale;
|
|
497
522
|
}
|
|
498
523
|
return a;
|
|
499
524
|
}
|
|
@@ -505,7 +530,7 @@ class O extends N.Doc {
|
|
|
505
530
|
delete O.sharedInstances[e], super.destroy();
|
|
506
531
|
}
|
|
507
532
|
initObserver() {
|
|
508
|
-
|
|
533
|
+
Gt(this.syncedStore), xt(this.syncedStore);
|
|
509
534
|
}
|
|
510
535
|
get draftYjsFilePath() {
|
|
511
536
|
return b(this.options.path, "draft.yjs");
|
|
@@ -525,11 +550,11 @@ class O extends N.Doc {
|
|
|
525
550
|
}
|
|
526
551
|
async setState(e, s) {
|
|
527
552
|
const o = await ts(s, { exportAssets: !1, includeResources: !0 }), a = this.getPublishDir(e);
|
|
528
|
-
if (
|
|
529
|
-
const
|
|
530
|
-
O.pageUrlMapCache.delete(
|
|
531
|
-
const
|
|
532
|
-
await U.update({ productionState:
|
|
553
|
+
if (N(L(a), { recursive: !0 }), Fe(a, { force: !0, recursive: !0 }), Re(o, a), e === "production") {
|
|
554
|
+
const n = k(this.options.path);
|
|
555
|
+
O.pageUrlMapCache.delete(n);
|
|
556
|
+
const r = Ee(s);
|
|
557
|
+
await U.update({ productionState: r }, { where: { id: n } });
|
|
533
558
|
}
|
|
534
559
|
}
|
|
535
560
|
getPublishDir(e) {
|
|
@@ -541,7 +566,7 @@ class O extends N.Doc {
|
|
|
541
566
|
// 延迟释放定时器
|
|
542
567
|
releaseTimer;
|
|
543
568
|
awarenessChangeHandler = ({ added: e, updated: s, removed: o }, a) => {
|
|
544
|
-
const
|
|
569
|
+
const n = e.concat(s, o);
|
|
545
570
|
if (a !== null) {
|
|
546
571
|
const p = this.conns.get(a);
|
|
547
572
|
p && (e.forEach((y) => {
|
|
@@ -550,19 +575,19 @@ class O extends N.Doc {
|
|
|
550
575
|
p.delete(y);
|
|
551
576
|
}));
|
|
552
577
|
}
|
|
553
|
-
const
|
|
554
|
-
D.writeVarUint(
|
|
555
|
-
const l = D.toUint8Array(
|
|
578
|
+
const r = D.createEncoder();
|
|
579
|
+
D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, n));
|
|
580
|
+
const l = D.toUint8Array(r);
|
|
556
581
|
this.conns.forEach((p, y) => this.send(y, l));
|
|
557
582
|
};
|
|
558
583
|
updateHandler = (e) => {
|
|
559
584
|
const s = D.createEncoder();
|
|
560
585
|
D.writeVarUint(s, Z), vt(s, e);
|
|
561
586
|
const o = D.toUint8Array(s);
|
|
562
|
-
this.conns.forEach((a,
|
|
587
|
+
this.conns.forEach((a, n) => this.send(n, o));
|
|
563
588
|
};
|
|
564
589
|
ensureDataStructure = () => {
|
|
565
|
-
const { supportedLocales: e, pages: s, pageIds: o, config: a, routes:
|
|
590
|
+
const { supportedLocales: e, pages: s, pageIds: o, config: a, routes: n, routeIds: r } = this.syncedStore;
|
|
566
591
|
{
|
|
567
592
|
const l = new Set(Object.keys(s));
|
|
568
593
|
let p = 0;
|
|
@@ -572,11 +597,11 @@ class O extends N.Doc {
|
|
|
572
597
|
}
|
|
573
598
|
}
|
|
574
599
|
{
|
|
575
|
-
const l = new Set(Object.keys(
|
|
600
|
+
const l = new Set(Object.keys(n));
|
|
576
601
|
let p = 0;
|
|
577
|
-
for (; p <
|
|
578
|
-
const y =
|
|
579
|
-
l.has(y) ? (l.delete(y), p++) :
|
|
602
|
+
for (; p < r.length; ) {
|
|
603
|
+
const y = r[p];
|
|
604
|
+
l.has(y) ? (l.delete(y), p++) : r.splice(p, 1);
|
|
580
605
|
}
|
|
581
606
|
}
|
|
582
607
|
e.splice(0, e.length), e.push(...ye.env.languages.map((l) => ({ locale: l.code, name: l.name }))), a.defaultLocale = e[0]?.locale;
|
|
@@ -626,8 +651,8 @@ class O extends N.Doc {
|
|
|
626
651
|
f.info(`[SiteState] cancelled scheduled release for project ${e}`);
|
|
627
652
|
}
|
|
628
653
|
}
|
|
629
|
-
autoSave =
|
|
630
|
-
|
|
654
|
+
autoSave = Ge(() => {
|
|
655
|
+
N(L(this.draftYjsFilePath), { recursive: !0 }), te(this.draftYjsFilePath, _.encodeStateAsUpdate(this));
|
|
631
656
|
}, Ht);
|
|
632
657
|
save = ({ flush: e = !1 } = {}) => {
|
|
633
658
|
this.autoSave(), e && this.autoSave.flush();
|
|
@@ -635,18 +660,18 @@ class O extends N.Doc {
|
|
|
635
660
|
publish = async ({ mode: e, routes: s }) => {
|
|
636
661
|
const o = k(this.options.path);
|
|
637
662
|
await as(o);
|
|
638
|
-
const a = await this.getState("draft"),
|
|
639
|
-
await
|
|
663
|
+
const a = await this.getState("draft"), n = await this.getState("production");
|
|
664
|
+
await _e(a, n, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), n.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), Bt(this.syncedStore, s), await this.setState(e, n), await this.clearPageCacheForRoutes(s, n);
|
|
640
665
|
};
|
|
641
666
|
mergeState = async (e, s) => {
|
|
642
667
|
const o = JSON.parse(JSON.stringify(s));
|
|
643
668
|
e.config.fontFamily ??= {};
|
|
644
|
-
const a = o.config?.fontFamily,
|
|
645
|
-
e.config.fontFamily.title = a?.title ||
|
|
669
|
+
const a = o.config?.fontFamily, n = e.config?.fontFamily;
|
|
670
|
+
e.config.fontFamily.title = a?.title || n?.title, e.config.fontFamily.description = a?.description || n?.description, await new Promise((r, l) => {
|
|
646
671
|
this.transact(async () => {
|
|
647
672
|
try {
|
|
648
|
-
const p = await
|
|
649
|
-
|
|
673
|
+
const p = await _e(e, s);
|
|
674
|
+
r(p);
|
|
650
675
|
} catch (p) {
|
|
651
676
|
l(p);
|
|
652
677
|
}
|
|
@@ -654,18 +679,18 @@ class O extends N.Doc {
|
|
|
654
679
|
});
|
|
655
680
|
};
|
|
656
681
|
clearPageCacheForRoutes = async (e, s) => {
|
|
657
|
-
const o = k(this.options.path),
|
|
658
|
-
let
|
|
659
|
-
(!
|
|
660
|
-
const l = s.supportedLocales.map((
|
|
661
|
-
for (const
|
|
662
|
-
const I = s.pages[
|
|
663
|
-
|
|
682
|
+
const o = k(this.options.path), n = (await U.findByPk(o))?.slug || o;
|
|
683
|
+
let r = e;
|
|
684
|
+
(!r || r.length === 0) && (r = s.pageIds ?? []), f.info(`[SiteState] clearing page cache for project ${o}, routes:`, r || []);
|
|
685
|
+
const l = s.supportedLocales.map((A) => A.locale), p = [], y = r.filter((A) => s.pageIds?.includes(A));
|
|
686
|
+
for (const A of y) {
|
|
687
|
+
const I = s.pages[A].slug;
|
|
688
|
+
n && n !== o && (n === "/" ? p.push(I) : p.push(`/${n}${I}`)), p.push(`/${o}${I}`);
|
|
664
689
|
}
|
|
665
690
|
if (p.length > 0)
|
|
666
691
|
try {
|
|
667
|
-
const
|
|
668
|
-
f.info(`[SiteState] cleared ${
|
|
692
|
+
const A = zt(p, l);
|
|
693
|
+
f.info(`[SiteState] cleared ${A} page cache entries for project ${o}, routes:`, r);
|
|
669
694
|
} catch {
|
|
670
695
|
}
|
|
671
696
|
O.pageUrlMapCache.delete(o);
|
|
@@ -695,17 +720,17 @@ class O extends N.Doc {
|
|
|
695
720
|
{
|
|
696
721
|
const a = D.createEncoder();
|
|
697
722
|
D.writeVarUint(a, Z), Rt(a, this), this.send(e, D.toUint8Array(a));
|
|
698
|
-
const
|
|
699
|
-
if (
|
|
700
|
-
const
|
|
701
|
-
D.writeVarUint(
|
|
723
|
+
const n = this.awareness.getStates();
|
|
724
|
+
if (n.size > 0) {
|
|
725
|
+
const r = D.createEncoder();
|
|
726
|
+
D.writeVarUint(r, me), D.writeVarUint8Array(r, Te(this.awareness, Array.from(n.keys()))), this.send(e, D.toUint8Array(r));
|
|
702
727
|
}
|
|
703
728
|
}
|
|
704
729
|
};
|
|
705
730
|
messageListener = (e, s) => {
|
|
706
731
|
try {
|
|
707
|
-
const o = D.createEncoder(), a = de.createDecoder(s),
|
|
708
|
-
switch (
|
|
732
|
+
const o = D.createEncoder(), a = de.createDecoder(s), n = de.readVarUint(a);
|
|
733
|
+
switch (n) {
|
|
709
734
|
case Z:
|
|
710
735
|
D.writeVarUint(o, Z), jt(a, o, this, null), D.length(o) > 1 && (this.ensureDataStructure(), this.send(e, D.toUint8Array(o)));
|
|
711
736
|
break;
|
|
@@ -714,7 +739,7 @@ class O extends N.Doc {
|
|
|
714
739
|
break;
|
|
715
740
|
}
|
|
716
741
|
default:
|
|
717
|
-
f.warn(`Unsupported messageType ${
|
|
742
|
+
f.warn(`Unsupported messageType ${n}`);
|
|
718
743
|
}
|
|
719
744
|
} catch (o) {
|
|
720
745
|
f.error(o);
|
|
@@ -727,26 +752,26 @@ class O extends N.Doc {
|
|
|
727
752
|
s ? o = [s] : o = await this.getProjectIds();
|
|
728
753
|
let a = {};
|
|
729
754
|
if (e === "production" && o?.length) {
|
|
730
|
-
const
|
|
731
|
-
for (const
|
|
732
|
-
const l = O.pageUrlMapCache.get(
|
|
733
|
-
l && (a = { ...a, ...l },
|
|
755
|
+
const n = new Map(o?.map((r) => [r, !0]) || []);
|
|
756
|
+
for (const r of o) {
|
|
757
|
+
const l = O.pageUrlMapCache.get(r);
|
|
758
|
+
l && (a = { ...a, ...l }, n.delete(r));
|
|
734
759
|
}
|
|
735
|
-
o = Array.from(
|
|
760
|
+
o = Array.from(n.keys());
|
|
736
761
|
}
|
|
737
762
|
if (o?.length) {
|
|
738
|
-
const
|
|
763
|
+
const n = await U.findAll({
|
|
739
764
|
where: {
|
|
740
765
|
id: {
|
|
741
|
-
[
|
|
766
|
+
[Pe.in]: o
|
|
742
767
|
}
|
|
743
768
|
}
|
|
744
769
|
});
|
|
745
770
|
await Promise.all(
|
|
746
|
-
|
|
747
|
-
const l =
|
|
771
|
+
n?.map(async (r) => {
|
|
772
|
+
const l = r.id, p = r.slug || l, y = {}, A = e === "production" && r?.productionState ? r.productionState : await O.getStateByProjectId(r.id, e), j = yt(
|
|
748
773
|
E.env.languages?.map((u) => u.code) || [],
|
|
749
|
-
|
|
774
|
+
A.supportedLocales?.map((u) => u.locale) || []
|
|
750
775
|
), I = (u, c) => {
|
|
751
776
|
p && (y[Y("/", p, u)] = {
|
|
752
777
|
...c,
|
|
@@ -763,8 +788,8 @@ class O extends N.Doc {
|
|
|
763
788
|
}
|
|
764
789
|
};
|
|
765
790
|
if (e === "draft")
|
|
766
|
-
for (const u of
|
|
767
|
-
const c =
|
|
791
|
+
for (const u of A.routeIds || []) {
|
|
792
|
+
const c = A?.routes?.[u];
|
|
768
793
|
if (!c) continue;
|
|
769
794
|
if (c.params && c.params.length > 0) {
|
|
770
795
|
const m = Ie({
|
|
@@ -778,7 +803,7 @@ class O extends N.Doc {
|
|
|
778
803
|
result: []
|
|
779
804
|
});
|
|
780
805
|
for (const d of m) {
|
|
781
|
-
const h = d.path,
|
|
806
|
+
const h = d.path, w = {
|
|
782
807
|
projectId: l,
|
|
783
808
|
projectSlug: p,
|
|
784
809
|
pageSlug: h,
|
|
@@ -787,10 +812,10 @@ class O extends N.Doc {
|
|
|
787
812
|
// default locale
|
|
788
813
|
defaultLocale: j?.[0],
|
|
789
814
|
locales: j,
|
|
790
|
-
publishedAt:
|
|
815
|
+
publishedAt: A.config.publishedAt,
|
|
791
816
|
isPublic: c.isPublic && d?.routeMetaData?.isPublic
|
|
792
817
|
};
|
|
793
|
-
I(h,
|
|
818
|
+
I(h, w);
|
|
794
819
|
}
|
|
795
820
|
}
|
|
796
821
|
const g = c.path, C = {
|
|
@@ -802,16 +827,16 @@ class O extends N.Doc {
|
|
|
802
827
|
// default locale
|
|
803
828
|
defaultLocale: j?.[0],
|
|
804
829
|
locales: j,
|
|
805
|
-
publishedAt:
|
|
830
|
+
publishedAt: A.config.publishedAt,
|
|
806
831
|
isPublic: c.isPublic
|
|
807
832
|
};
|
|
808
833
|
I(g, C);
|
|
809
834
|
}
|
|
810
|
-
for (const u of
|
|
811
|
-
const c =
|
|
835
|
+
for (const u of A.pageIds || []) {
|
|
836
|
+
const c = A.pages[u];
|
|
812
837
|
if (!c || e === "production" && !c.isPublic)
|
|
813
838
|
continue;
|
|
814
|
-
const g = c.slug, C =
|
|
839
|
+
const g = c.slug, C = r.slug || l, m = {
|
|
815
840
|
projectId: l,
|
|
816
841
|
projectSlug: C,
|
|
817
842
|
pageSlug: g,
|
|
@@ -819,7 +844,7 @@ class O extends N.Doc {
|
|
|
819
844
|
// default locale
|
|
820
845
|
defaultLocale: j?.[0],
|
|
821
846
|
locales: j,
|
|
822
|
-
publishedAt:
|
|
847
|
+
publishedAt: A.config.publishedAt,
|
|
823
848
|
isPublic: c.isPublic,
|
|
824
849
|
templateConfig: c.templateConfig
|
|
825
850
|
};
|
|
@@ -832,7 +857,7 @@ class O extends N.Doc {
|
|
|
832
857
|
return a;
|
|
833
858
|
}
|
|
834
859
|
getDocumentSize() {
|
|
835
|
-
return
|
|
860
|
+
return _.encodeStateAsUpdate(this).byteLength;
|
|
836
861
|
}
|
|
837
862
|
static getInstancesSizeInfo() {
|
|
838
863
|
const e = [];
|
|
@@ -862,21 +887,21 @@ class O extends N.Doc {
|
|
|
862
887
|
// 执行定期检查
|
|
863
888
|
static performPeriodicCheck() {
|
|
864
889
|
const e = Object.keys(O.sharedInstances).length, s = [], o = [];
|
|
865
|
-
for (const [a,
|
|
866
|
-
|
|
890
|
+
for (const [a, n] of Object.entries(O.sharedInstances))
|
|
891
|
+
n.conns.size === 0 ? s.push({ projectId: a, instance: n }) : o.push({ projectId: a, connections: n.conns.size });
|
|
867
892
|
if (f.info(
|
|
868
893
|
`[SiteState] periodic check summary: total instances: ${e}, with connections: ${o.length}, without connections: ${s.length}`
|
|
869
894
|
), s.length > 0) {
|
|
870
895
|
f.info(
|
|
871
896
|
`[SiteState] releasing ${s.length} instances without connections:`,
|
|
872
|
-
s.map((
|
|
897
|
+
s.map((n) => n.projectId)
|
|
873
898
|
);
|
|
874
899
|
let a = 0;
|
|
875
|
-
for (const { projectId:
|
|
900
|
+
for (const { projectId: n, instance: r } of s)
|
|
876
901
|
try {
|
|
877
|
-
f.info(`[SiteState] releasing instance due to periodic check: ${
|
|
902
|
+
f.info(`[SiteState] releasing instance due to periodic check: ${n}`), r.destroy(), a++;
|
|
878
903
|
} catch (l) {
|
|
879
|
-
f.error(`[SiteState] failed to release instance ${
|
|
904
|
+
f.error(`[SiteState] failed to release instance ${n} during periodic check:`, l);
|
|
880
905
|
}
|
|
881
906
|
f.info(
|
|
882
907
|
`[SiteState] periodic check completed: ${a}/${s.length} instances released successfully`
|
|
@@ -885,12 +910,12 @@ class O extends N.Doc {
|
|
|
885
910
|
}
|
|
886
911
|
}
|
|
887
912
|
async function Qt(t, e, s) {
|
|
888
|
-
if (!t || !M(t) || !
|
|
913
|
+
if (!t || !M(t) || !x(t).isFile())
|
|
889
914
|
return null;
|
|
890
915
|
let o = s[t];
|
|
891
916
|
return o || (o = (async () => {
|
|
892
917
|
try {
|
|
893
|
-
return (await
|
|
918
|
+
return (await Kt({
|
|
894
919
|
filePath: t,
|
|
895
920
|
fileName: e
|
|
896
921
|
}))?.data?.filename;
|
|
@@ -922,58 +947,58 @@ const Zt = async (t, e) => {
|
|
|
922
947
|
})
|
|
923
948
|
);
|
|
924
949
|
};
|
|
925
|
-
function
|
|
926
|
-
return
|
|
950
|
+
function qe(t) {
|
|
951
|
+
return Ce.test(t) ? [t] : X.test(t) ? ($e.lastIndex = 0, Array.from(t.matchAll($e)).map((s) => s[1]).filter((s) => !!s)) : [];
|
|
927
952
|
}
|
|
928
953
|
async function ee(t, e, s) {
|
|
929
|
-
const { getFilename: o, exportAssets: a } = s,
|
|
930
|
-
if (
|
|
954
|
+
const { getFilename: o, exportAssets: a } = s, n = b(e, o(t));
|
|
955
|
+
if (N(L(n), { recursive: !0 }), te(n, B.stringify(t)), a) {
|
|
931
956
|
const l = ae(
|
|
932
957
|
t,
|
|
933
|
-
(p) => typeof p == "string" && (
|
|
958
|
+
(p) => typeof p == "string" && (Ce.test(p) || X.test(p))
|
|
934
959
|
).map((p) => {
|
|
935
960
|
const y = be(t, p);
|
|
936
|
-
return
|
|
961
|
+
return qe(y);
|
|
937
962
|
}).flat().filter(Boolean);
|
|
938
|
-
await es(l, L(
|
|
963
|
+
await es(l, L(n));
|
|
939
964
|
}
|
|
940
965
|
}
|
|
941
|
-
const Se = new
|
|
966
|
+
const Se = new we({
|
|
942
967
|
max: 100,
|
|
943
968
|
ttl: 1 * 60 * 1e3
|
|
944
969
|
// 1 minute
|
|
945
970
|
});
|
|
946
|
-
async function
|
|
971
|
+
async function Me(t, e, s) {
|
|
947
972
|
const o = ae(
|
|
948
973
|
t,
|
|
949
|
-
(l) => typeof l == "string" && (
|
|
950
|
-
), a = St(2),
|
|
974
|
+
(l) => typeof l == "string" && (Ce.test(l) || X.test(l))
|
|
975
|
+
), a = St(2), n = o.map(
|
|
951
976
|
(l) => a(async () => {
|
|
952
977
|
try {
|
|
953
|
-
const p = be(t, l), y =
|
|
954
|
-
for (const
|
|
955
|
-
const j = k(
|
|
978
|
+
const p = be(t, l), y = qe(p);
|
|
979
|
+
for (const A of y) {
|
|
980
|
+
const j = k(A), I = s.getFilePath(A, l), u = I ? `${I}:${j}` : j, c = Se.get(u);
|
|
956
981
|
if (c) {
|
|
957
|
-
X.test(p) ||
|
|
982
|
+
X.test(p) || De(t, l, c);
|
|
958
983
|
return;
|
|
959
984
|
}
|
|
960
985
|
const g = await Qt(I, j, e);
|
|
961
|
-
g && (X.test(p) ||
|
|
986
|
+
g && (X.test(p) || De(t, l, g), Se.set(u, g));
|
|
962
987
|
}
|
|
963
988
|
} catch (p) {
|
|
964
989
|
f.error(`Failed to process upload for path ${l.join(".")}:`, p.message || p.reason);
|
|
965
990
|
}
|
|
966
991
|
})
|
|
967
|
-
),
|
|
968
|
-
s.onFinish?.(
|
|
992
|
+
), r = await Promise.allSettled(n);
|
|
993
|
+
s.onFinish?.(r);
|
|
969
994
|
}
|
|
970
995
|
async function ts(t, {
|
|
971
996
|
exportAssets: e,
|
|
972
997
|
pageIds: s = "all",
|
|
973
998
|
componentIds: o = "all",
|
|
974
999
|
rawConfig: a,
|
|
975
|
-
includeResources:
|
|
976
|
-
routeIds:
|
|
1000
|
+
includeResources: n = !1,
|
|
1001
|
+
routeIds: r = "all"
|
|
977
1002
|
} = {}) {
|
|
978
1003
|
const l = s === "all" ? t.pageIds : s, p = dt({
|
|
979
1004
|
state: t,
|
|
@@ -983,7 +1008,7 @@ async function ts(t, {
|
|
|
983
1008
|
Object.entries(t.components).forEach(([i, S]) => {
|
|
984
1009
|
S.data?.renderer?.type === "component-template" && p.push(i);
|
|
985
1010
|
});
|
|
986
|
-
const y =
|
|
1011
|
+
const y = r === "all" ? t.routeIds : r, A = (i) => ({
|
|
987
1012
|
id: i.id,
|
|
988
1013
|
name: i.name,
|
|
989
1014
|
isTemplateSection: i.isTemplateSection ?? !1,
|
|
@@ -996,7 +1021,7 @@ async function ts(t, {
|
|
|
996
1021
|
sections: i?.sectionIds ? T(
|
|
997
1022
|
i?.sectionIds?.map((S) => {
|
|
998
1023
|
const v = i.sections?.[S];
|
|
999
|
-
return v &&
|
|
1024
|
+
return v && A(v);
|
|
1000
1025
|
})
|
|
1001
1026
|
) : void 0
|
|
1002
1027
|
/** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
|
|
@@ -1011,13 +1036,13 @@ async function ts(t, {
|
|
|
1011
1036
|
meta: i.locales?.[S] ?? {},
|
|
1012
1037
|
sections: T(
|
|
1013
1038
|
i.sectionIds.map((v) => {
|
|
1014
|
-
const
|
|
1015
|
-
return
|
|
1039
|
+
const G = i.sections[v];
|
|
1040
|
+
return G && A(G);
|
|
1016
1041
|
})
|
|
1017
1042
|
),
|
|
1018
1043
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1019
1044
|
dataSource: Object.fromEntries(
|
|
1020
|
-
Object.entries(i.dataSource || {}).map(([v,
|
|
1045
|
+
Object.entries(i.dataSource || {}).map(([v, G]) => [v, G?.[S] ?? {}])
|
|
1021
1046
|
)
|
|
1022
1047
|
}), I = (i) => ({
|
|
1023
1048
|
id: i.id,
|
|
@@ -1048,20 +1073,20 @@ async function ts(t, {
|
|
|
1048
1073
|
})
|
|
1049
1074
|
)
|
|
1050
1075
|
), g = ze(), C = b(g, "pages");
|
|
1051
|
-
|
|
1076
|
+
N(C, { recursive: !0 });
|
|
1052
1077
|
const m = b(g, "components");
|
|
1053
|
-
|
|
1078
|
+
N(m, { recursive: !0 });
|
|
1054
1079
|
const d = b(g, "routes");
|
|
1055
|
-
|
|
1080
|
+
N(d, { recursive: !0 });
|
|
1056
1081
|
for (const { locale: i, slug: S, page: v } of c)
|
|
1057
1082
|
await ee(v, C, {
|
|
1058
|
-
getFilename: () => `${
|
|
1083
|
+
getFilename: () => `${ne(S) || "index"}.${i}.yml`,
|
|
1059
1084
|
exportAssets: e
|
|
1060
1085
|
});
|
|
1061
1086
|
for (const i of u)
|
|
1062
1087
|
await ee(i, d, {
|
|
1063
1088
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1064
|
-
getFilename: () => `${
|
|
1089
|
+
getFilename: () => `${ne(i.path) || "index"}.yml`,
|
|
1065
1090
|
exportAssets: e
|
|
1066
1091
|
});
|
|
1067
1092
|
for (const i of p) {
|
|
@@ -1072,8 +1097,8 @@ async function ts(t, {
|
|
|
1072
1097
|
});
|
|
1073
1098
|
}
|
|
1074
1099
|
const h = b(g, ".blocklet/pages/pages.config.yml");
|
|
1075
|
-
|
|
1076
|
-
const
|
|
1100
|
+
N(L(h), { recursive: !0 });
|
|
1101
|
+
const w = {
|
|
1077
1102
|
pages: T(
|
|
1078
1103
|
l.map((i) => {
|
|
1079
1104
|
const S = t.pages[i];
|
|
@@ -1095,7 +1120,7 @@ async function ts(t, {
|
|
|
1095
1120
|
};
|
|
1096
1121
|
})
|
|
1097
1122
|
),
|
|
1098
|
-
...
|
|
1123
|
+
...n ? {
|
|
1099
1124
|
resources: {
|
|
1100
1125
|
components: T(
|
|
1101
1126
|
Object.keys(t.resources?.components || {}).filter((i) => p.includes(i)).map((i) => ({
|
|
@@ -1108,34 +1133,34 @@ async function ts(t, {
|
|
|
1108
1133
|
supportedLocales: t.supportedLocales,
|
|
1109
1134
|
config: t.config
|
|
1110
1135
|
};
|
|
1111
|
-
te(h,
|
|
1136
|
+
te(h, B.stringify(w));
|
|
1112
1137
|
const P = b(g, "config.source.json");
|
|
1113
|
-
if (a && te(P, JSON.stringify(a)),
|
|
1138
|
+
if (a && te(P, JSON.stringify(a)), n) {
|
|
1114
1139
|
const i = b(g, "resources"), S = b(i, "components");
|
|
1115
|
-
|
|
1140
|
+
N(S, { recursive: !0 });
|
|
1116
1141
|
for (const z of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1117
1142
|
($) => p.includes($)
|
|
1118
1143
|
)) {
|
|
1119
1144
|
const $ = t.resources?.components?.[z]?.component;
|
|
1120
1145
|
$ && await ee($, S, {
|
|
1121
|
-
getFilename: (
|
|
1146
|
+
getFilename: (q) => `${q.name || "unnamed"}.${q.id}.yml`,
|
|
1122
1147
|
exportAssets: e
|
|
1123
1148
|
});
|
|
1124
1149
|
}
|
|
1125
1150
|
const v = b(g, "chunks");
|
|
1126
|
-
|
|
1127
|
-
const
|
|
1151
|
+
N(v, { recursive: !0 });
|
|
1152
|
+
const G = ss();
|
|
1128
1153
|
for (const z of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1129
1154
|
($) => p.includes($)
|
|
1130
1155
|
)) {
|
|
1131
1156
|
const $ = t.resources?.components?.[z]?.component;
|
|
1132
1157
|
if ($ && $.renderer?.type === "react-component") {
|
|
1133
|
-
const
|
|
1134
|
-
if (
|
|
1135
|
-
for (const pe of
|
|
1136
|
-
const
|
|
1158
|
+
const q = $.renderer?.chunks ?? [];
|
|
1159
|
+
if (q?.length > 0)
|
|
1160
|
+
for (const pe of q) {
|
|
1161
|
+
const ve = b(v, pe), ue = G?.[pe];
|
|
1137
1162
|
try {
|
|
1138
|
-
ue && M(ue) && !M(
|
|
1163
|
+
ue && M(ue) && !M(ve) && ct(ue, ve);
|
|
1139
1164
|
} catch (Ze) {
|
|
1140
1165
|
f.error(`copy chunk ${pe} error`, Ze.message);
|
|
1141
1166
|
}
|
|
@@ -1145,53 +1170,53 @@ async function ts(t, {
|
|
|
1145
1170
|
}
|
|
1146
1171
|
return g;
|
|
1147
1172
|
}
|
|
1148
|
-
async function
|
|
1173
|
+
async function Ke(t, { importAssets: e, includeResources: s } = {}) {
|
|
1149
1174
|
if (!M(t))
|
|
1150
1175
|
return null;
|
|
1151
1176
|
let o, a = !1;
|
|
1152
1177
|
try {
|
|
1153
|
-
|
|
1154
|
-
const
|
|
1155
|
-
if (!
|
|
1178
|
+
x(t).isDirectory() ? o = t : /\.(tgz|gz|tar)$/.test(t) && (a = !0, o = ze(), await bt({ file: t, C: o }));
|
|
1179
|
+
const n = se("**/.blocklet/pages/pages.config.yml", { cwd: o, absolute: !0 }).at(0), r = n && b(L(n), "../../pages"), l = n && b(L(n), "../../components"), p = n && b(L(n), "../../routes");
|
|
1180
|
+
if (!n)
|
|
1156
1181
|
return null;
|
|
1157
|
-
const y =
|
|
1158
|
-
let
|
|
1159
|
-
return (!M(
|
|
1182
|
+
const y = B.parse(J(n).toString()), A = (m, d, h) => {
|
|
1183
|
+
let w = b(m, `${d}${h ? `.${h}` : ""}.yml`);
|
|
1184
|
+
return (!M(w) || !x(w).isFile()) && (w = b(m, d, `index${h ? `.${h}` : ""}.yml`), !M(w) || !x(w)) ? null : B.parse(J(w).toString());
|
|
1160
1185
|
}, j = (m, d) => {
|
|
1161
1186
|
try {
|
|
1162
1187
|
const h = se(`*.${d}.yml`, { cwd: m, absolute: !0 })[0];
|
|
1163
|
-
return h ?
|
|
1188
|
+
return h ? B.parse(J(h).toString()) : null;
|
|
1164
1189
|
} catch (h) {
|
|
1165
1190
|
f.error("parse component error", h);
|
|
1166
1191
|
}
|
|
1167
1192
|
return null;
|
|
1168
1193
|
}, I = (m, d) => {
|
|
1169
1194
|
let h = b(m, `${d}.yml`);
|
|
1170
|
-
return (!M(h) || !
|
|
1195
|
+
return (!M(h) || !x(h).isFile()) && (h = b(m, d, "index.yml"), !M(h) || !x(h)) ? null : B.parse(J(h).toString());
|
|
1171
1196
|
}, u = T(
|
|
1172
1197
|
y.pages.map(({ slug: m }) => {
|
|
1173
1198
|
const d = T(
|
|
1174
1199
|
y.supportedLocales.map(({ locale: P }) => {
|
|
1175
|
-
const i =
|
|
1200
|
+
const i = r ? A(r, ne(m), P) : void 0;
|
|
1176
1201
|
if (i)
|
|
1177
1202
|
return { locale: P, page: i };
|
|
1178
|
-
const S =
|
|
1203
|
+
const S = r ? A(r, m, P) : void 0;
|
|
1179
1204
|
return S && { locale: P, page: S };
|
|
1180
1205
|
})
|
|
1181
1206
|
), h = d[0]?.page;
|
|
1182
1207
|
if (!h)
|
|
1183
1208
|
return null;
|
|
1184
|
-
const
|
|
1209
|
+
const w = h.sections.map(ut);
|
|
1185
1210
|
return {
|
|
1186
|
-
id: h.id ||
|
|
1211
|
+
id: h.id || je(),
|
|
1187
1212
|
createdAt: h.createdAt,
|
|
1188
1213
|
updatedAt: h.updatedAt,
|
|
1189
1214
|
publishedAt: h.publishedAt,
|
|
1190
1215
|
isPublic: h.isPublic ?? !0,
|
|
1191
1216
|
templateConfig: h.templateConfig,
|
|
1192
1217
|
slug: m,
|
|
1193
|
-
sections: Object.fromEntries(
|
|
1194
|
-
sectionIds:
|
|
1218
|
+
sections: Object.fromEntries(w.map((P) => [P.id, P])),
|
|
1219
|
+
sectionIds: w.map((P) => P.id),
|
|
1195
1220
|
locales: Object.fromEntries(d.map(({ locale: P, page: i }) => [P, i.meta])),
|
|
1196
1221
|
dataSource: h.dataSource ? Object.fromEntries(
|
|
1197
1222
|
// 获取 dataSource 中所有 section ID
|
|
@@ -1213,8 +1238,8 @@ async function qe(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1213
1238
|
const v = S.dataSource?.[P];
|
|
1214
1239
|
if (v)
|
|
1215
1240
|
return [i, v];
|
|
1216
|
-
const
|
|
1217
|
-
return [i,
|
|
1241
|
+
const G = S.sections.find((z) => z.id === P);
|
|
1242
|
+
return [i, G?.properties || {}];
|
|
1218
1243
|
})
|
|
1219
1244
|
)
|
|
1220
1245
|
])
|
|
@@ -1223,10 +1248,10 @@ async function qe(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1223
1248
|
})
|
|
1224
1249
|
), c = T(
|
|
1225
1250
|
y?.routes?.map(({ path: m }) => {
|
|
1226
|
-
const d = p ? I(p,
|
|
1251
|
+
const d = p ? I(p, ne(m)) : void 0;
|
|
1227
1252
|
return {
|
|
1228
1253
|
...d,
|
|
1229
|
-
id: d?.id ||
|
|
1254
|
+
id: d?.id || je(),
|
|
1230
1255
|
createdAt: d?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1231
1256
|
updatedAt: d?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1232
1257
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -1245,25 +1270,25 @@ async function qe(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1245
1270
|
f.info(`[${a ? k(t) : k(b(t, "../../../../"))}] importAssets:`, ...d);
|
|
1246
1271
|
};
|
|
1247
1272
|
try {
|
|
1248
|
-
m("wait image-bin api ready"), await
|
|
1273
|
+
m("wait image-bin api ready"), await wt({
|
|
1249
1274
|
resources: [`${ft(et)}/api/sdk/uploads`],
|
|
1250
|
-
validateStatus: (
|
|
1275
|
+
validateStatus: (w) => w >= 200 && w <= 500
|
|
1251
1276
|
}), m("image-bin api is ready");
|
|
1252
1277
|
const d = {}, h = {};
|
|
1253
1278
|
m("start to upload assets"), await Promise.allSettled([
|
|
1254
|
-
|
|
1255
|
-
getFilePath: (
|
|
1256
|
-
onFinish: (
|
|
1257
|
-
m(`upload ${
|
|
1279
|
+
Me(g, d, {
|
|
1280
|
+
getFilePath: (w) => l && b(l, w),
|
|
1281
|
+
onFinish: (w) => {
|
|
1282
|
+
m(`upload ${w.length} component assets`);
|
|
1258
1283
|
}
|
|
1259
1284
|
}),
|
|
1260
|
-
|
|
1261
|
-
getFilePath: (
|
|
1285
|
+
Me(u, h, {
|
|
1286
|
+
getFilePath: (w, P) => {
|
|
1262
1287
|
const i = be(u, P.slice(0, 1));
|
|
1263
|
-
return
|
|
1288
|
+
return r && b(r, L(i.slug), w);
|
|
1264
1289
|
},
|
|
1265
|
-
onFinish: (
|
|
1266
|
-
m(`upload ${
|
|
1290
|
+
onFinish: (w) => {
|
|
1291
|
+
m(`upload ${w.length} page assets`);
|
|
1267
1292
|
}
|
|
1268
1293
|
})
|
|
1269
1294
|
]), m("upload assets done"), Se.clear(), global.gc && global.gc();
|
|
@@ -1273,11 +1298,11 @@ async function qe(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1273
1298
|
}
|
|
1274
1299
|
const C = {};
|
|
1275
1300
|
if (s) {
|
|
1276
|
-
const m =
|
|
1301
|
+
const m = n && b(L(n), "../../resources/components"), d = T(
|
|
1277
1302
|
y.resources?.components?.map(({ id: h }) => j(m, h)) ?? []
|
|
1278
1303
|
);
|
|
1279
1304
|
d.length > 0 && (C.components = Object.fromEntries(
|
|
1280
|
-
d.map((h,
|
|
1305
|
+
d.map((h, w) => [h.id, { index: w, component: h }])
|
|
1281
1306
|
));
|
|
1282
1307
|
}
|
|
1283
1308
|
return {
|
|
@@ -1293,22 +1318,22 @@ async function qe(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1293
1318
|
dataSources: {}
|
|
1294
1319
|
};
|
|
1295
1320
|
} finally {
|
|
1296
|
-
a && o &&
|
|
1321
|
+
a && o && Fe(o, { force: !0, recursive: !0 });
|
|
1297
1322
|
}
|
|
1298
1323
|
}
|
|
1299
|
-
async function
|
|
1324
|
+
async function _e(t, e, {
|
|
1300
1325
|
routes: s,
|
|
1301
1326
|
mergeMode: o = "byUpdateTime",
|
|
1302
1327
|
deleteRoutes: a = !1,
|
|
1303
|
-
publishMode:
|
|
1328
|
+
publishMode: n = void 0
|
|
1304
1329
|
} = {}) {
|
|
1305
1330
|
try {
|
|
1306
|
-
|
|
1331
|
+
n && tt(n);
|
|
1307
1332
|
} catch (I) {
|
|
1308
1333
|
f.error("clear preload page cache error", { error: I });
|
|
1309
1334
|
}
|
|
1310
|
-
const { pages:
|
|
1311
|
-
if (
|
|
1335
|
+
const { pages: r, pageIds: l, routeIds: p, routes: y, supportedLocales: A } = t;
|
|
1336
|
+
if (n === "production") {
|
|
1312
1337
|
let I = s ?? [], u = null;
|
|
1313
1338
|
for (const c of p ?? []) {
|
|
1314
1339
|
const g = y?.[c];
|
|
@@ -1351,7 +1376,7 @@ async function Me(t, e, {
|
|
|
1351
1376
|
f.info("no display template", c);
|
|
1352
1377
|
continue;
|
|
1353
1378
|
}
|
|
1354
|
-
const m =
|
|
1379
|
+
const m = r[C.displayTemplateId];
|
|
1355
1380
|
if (!m) {
|
|
1356
1381
|
f.info("no template page", c);
|
|
1357
1382
|
continue;
|
|
@@ -1389,7 +1414,7 @@ async function Me(t, e, {
|
|
|
1389
1414
|
I?.includes(c) || (delete e.pages[c], f.info("delete page", c)), e.pageIds = [...e.pageIds].filter((g) => I?.includes(g));
|
|
1390
1415
|
} else {
|
|
1391
1416
|
for (const I of l) {
|
|
1392
|
-
const u =
|
|
1417
|
+
const u = r[I];
|
|
1393
1418
|
if (u)
|
|
1394
1419
|
if (e.pageIds.includes(u.id)) {
|
|
1395
1420
|
if (o === "replace")
|
|
@@ -1415,7 +1440,7 @@ async function Me(t, e, {
|
|
|
1415
1440
|
e.routeIds.push(u.id), e.routes[u.id] = u;
|
|
1416
1441
|
}
|
|
1417
1442
|
}
|
|
1418
|
-
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ee(
|
|
1443
|
+
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Ee(A)), a)
|
|
1419
1444
|
for (const I of Object.keys(e.components))
|
|
1420
1445
|
delete e.components[I];
|
|
1421
1446
|
let j = JSON.parse(JSON.stringify(t.components));
|
|
@@ -1432,11 +1457,11 @@ async function Me(t, e, {
|
|
|
1432
1457
|
];
|
|
1433
1458
|
})
|
|
1434
1459
|
)
|
|
1435
|
-
), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))),
|
|
1460
|
+
), Object.assign(e.components, j), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Ae(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1436
1461
|
}
|
|
1437
1462
|
const He = st(
|
|
1438
1463
|
async (t) => {
|
|
1439
|
-
if (!
|
|
1464
|
+
if (!Ae(t?.properties))
|
|
1440
1465
|
return t;
|
|
1441
1466
|
if (t?.renderer?.type === "react-component") {
|
|
1442
1467
|
const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
|
|
@@ -1448,9 +1473,9 @@ const He = st(
|
|
|
1448
1473
|
t.id,
|
|
1449
1474
|
s
|
|
1450
1475
|
);
|
|
1451
|
-
o && o.length > 0 && t && (t.properties = {}, o.forEach((a,
|
|
1476
|
+
o && o.length > 0 && t && (t.properties = {}, o.forEach((a, n) => {
|
|
1452
1477
|
t?.properties && (t.properties[a.id] = {
|
|
1453
|
-
index:
|
|
1478
|
+
index: n,
|
|
1454
1479
|
data: a
|
|
1455
1480
|
});
|
|
1456
1481
|
}));
|
|
@@ -1464,29 +1489,29 @@ const He = st(
|
|
|
1464
1489
|
subdir: "getPropertiesFromCode"
|
|
1465
1490
|
}
|
|
1466
1491
|
);
|
|
1467
|
-
let
|
|
1492
|
+
let re, Q, ie, ce;
|
|
1468
1493
|
const Je = () => mt({
|
|
1469
1494
|
types: [
|
|
1470
|
-
{ did: Ve, type:
|
|
1471
|
-
{ did: Lt, type:
|
|
1495
|
+
{ did: Ve, type: Le },
|
|
1496
|
+
{ did: Lt, type: Le }
|
|
1472
1497
|
]
|
|
1473
1498
|
}), ss = () => {
|
|
1474
1499
|
const t = Je(), e = {};
|
|
1475
1500
|
return t.forEach((s) => {
|
|
1476
1501
|
const o = se("**/.blocklet/pages/pages.config.yml", { cwd: s.path, absolute: !0 }).at(0), a = o && b(L(o), "../../chunks");
|
|
1477
1502
|
if (a && M(a)) {
|
|
1478
|
-
const
|
|
1479
|
-
for (const
|
|
1480
|
-
e[
|
|
1503
|
+
const n = lt(a);
|
|
1504
|
+
for (const r of n)
|
|
1505
|
+
e[r] = b(a, r);
|
|
1481
1506
|
}
|
|
1482
1507
|
}), e;
|
|
1483
1508
|
};
|
|
1484
1509
|
function Ye() {
|
|
1485
|
-
return
|
|
1510
|
+
return re = (async () => {
|
|
1486
1511
|
const t = Je();
|
|
1487
1512
|
Q = (await Promise.all(
|
|
1488
1513
|
t.map(async (s) => {
|
|
1489
|
-
const o = s.path ? await
|
|
1514
|
+
const o = s.path ? await Ke(s.path, { importAssets: !1 }) : void 0;
|
|
1490
1515
|
return o ? { blockletId: s.did, state: o, blockletTitle: s.title } : void 0;
|
|
1491
1516
|
})
|
|
1492
1517
|
)).filter((s) => !!s), ie = Q.reduce(
|
|
@@ -1521,10 +1546,10 @@ function Ye() {
|
|
|
1521
1546
|
})
|
|
1522
1547
|
)
|
|
1523
1548
|
);
|
|
1524
|
-
})(),
|
|
1549
|
+
})(), re;
|
|
1525
1550
|
}
|
|
1526
1551
|
function os(t) {
|
|
1527
|
-
const e =
|
|
1552
|
+
const e = Ge(
|
|
1528
1553
|
async () => {
|
|
1529
1554
|
await Ye().catch((s) => {
|
|
1530
1555
|
f.error("load resource states error", { error: s });
|
|
@@ -1597,8 +1622,8 @@ async function Qe({
|
|
|
1597
1622
|
if (o.syncedStore.resources.pages = e, (await U.findByPk(t))?.useAllResources)
|
|
1598
1623
|
o.syncedStore.resources.components = s;
|
|
1599
1624
|
else {
|
|
1600
|
-
const
|
|
1601
|
-
Object.entries(s || {}).filter(([p]) =>
|
|
1625
|
+
const r = (await Oe.findAll({ where: { projectId: t } })).map((p) => p.componentId), l = Object.fromEntries(
|
|
1626
|
+
Object.entries(s || {}).filter(([p]) => r.includes(p))
|
|
1602
1627
|
);
|
|
1603
1628
|
o.syncedStore.resources.components = l;
|
|
1604
1629
|
}
|
|
@@ -1614,30 +1639,30 @@ async function as(t) {
|
|
|
1614
1639
|
components: ce
|
|
1615
1640
|
});
|
|
1616
1641
|
}
|
|
1617
|
-
async function
|
|
1642
|
+
async function Ns() {
|
|
1618
1643
|
f.info("trigger reload all project resource"), E.events.emit(he);
|
|
1619
1644
|
}
|
|
1620
1645
|
async function Fs({
|
|
1621
1646
|
ensureLoaded: t = !0
|
|
1622
1647
|
} = {}) {
|
|
1623
|
-
return t && (
|
|
1648
|
+
return t && (re ??= Ye(), await re), { states: Q, pages: ie, components: ce };
|
|
1624
1649
|
}
|
|
1625
1650
|
export {
|
|
1626
1651
|
Ve as C,
|
|
1627
1652
|
U as P,
|
|
1628
|
-
|
|
1653
|
+
Le as R,
|
|
1629
1654
|
O as S,
|
|
1630
1655
|
H as a,
|
|
1631
1656
|
Ms as b,
|
|
1632
|
-
|
|
1657
|
+
_s as c,
|
|
1633
1658
|
Xt as d,
|
|
1634
1659
|
Zt as e,
|
|
1635
1660
|
es as f,
|
|
1636
1661
|
Fs as g,
|
|
1637
|
-
|
|
1662
|
+
Ke as h,
|
|
1638
1663
|
os as i,
|
|
1639
|
-
|
|
1640
|
-
|
|
1664
|
+
Ns as j,
|
|
1665
|
+
_e as m,
|
|
1641
1666
|
ts as t,
|
|
1642
1667
|
as as u
|
|
1643
1668
|
};
|