@blocklet/pages-kit-inner-components 0.7.22 → 0.7.23
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/add-component.js +13 -13
- package/lib/cjs/chunks/{draft-data-e1KnFlxv.js → draft-data-BYzGfJ7S.js} +1 -1
- package/lib/cjs/chunks/{home-BTdS1u5a.js → home-FbBl1G79.js} +2 -2
- package/lib/cjs/chunks/{index-DoTEfRgc.js → index-B-TdKJtn.js} +20 -20
- package/lib/cjs/chunks/{publish-button-JfvmgBSI.js → publish-button-JUoM34Aa.js} +1 -1
- package/lib/cjs/chunks/site-state-oC_X_C59.js +1 -0
- package/lib/cjs/chunks/state-BBnuCgyl.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +2 -2
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +1 -1
- package/lib/cjs/site-state.js +1 -1
- package/lib/es/add-component.js +102 -102
- package/lib/es/chunks/{draft-data-DRdPzuGm.js → draft-data-fMhhz4sh.js} +1 -1
- package/lib/es/chunks/{home-D3e7ljVw.js → home-BujeKjPf.js} +3 -3
- package/lib/es/chunks/{index-Dci_IgHn.js → index-BZ1MijZ6.js} +297 -297
- package/lib/es/chunks/{publish-button-CtlD3O0E.js → publish-button-BO4u_Nxb.js} +3 -3
- package/lib/es/chunks/{site-state-NvsHZBJX.js → site-state-D8_lRJeG.js} +510 -494
- package/lib/es/chunks/{state-qDCrgEMQ.js → state-CMRCtF-D.js} +47 -42
- package/lib/es/home.js +3 -3
- package/lib/es/locales.js +2 -0
- package/lib/es/resources.js +1 -1
- package/lib/es/setting.js +1 -1
- package/lib/es/site-state.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/chunks/site-state-B_SwLwSW.js +0 -1
- package/lib/cjs/chunks/state-DU3L5Lve.js +0 -1
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { getYjsValue as W, syncedStore as
|
|
3
|
-
import * as
|
|
4
|
-
import { setPageDataSource as
|
|
5
|
-
import { getRouteMetaDataByOptionIds as
|
|
6
|
-
import
|
|
7
|
-
import { DataTypes as
|
|
1
|
+
import { d as Je, l as p, m as ct, b as lt, I as pt, c as ut } from "./components-D4ywfyMi.js";
|
|
2
|
+
import { getYjsValue as W, syncedStore as dt } from "@syncedstore/core";
|
|
3
|
+
import * as x from "yjs";
|
|
4
|
+
import { setPageDataSource as ft } from "@blocklet/pages-kit/utils/data-source";
|
|
5
|
+
import { getRouteMetaDataByOptionIds as mt, generateParamCombinations as je } from "@blocklet/pages-kit/utils/route";
|
|
6
|
+
import Oe from "lodash/cloneDeep";
|
|
7
|
+
import { DataTypes as P, Sequelize as gt, Model as Re, Op as te } from "sequelize";
|
|
8
8
|
import "sqlite3";
|
|
9
9
|
import E from "@blocklet/sdk/lib/config";
|
|
10
|
-
import { withoutTrailingSlash as
|
|
11
|
-
import { union as
|
|
10
|
+
import { withoutTrailingSlash as Ce, withLeadingSlash as Ke, joinURL as B } from "ufo";
|
|
11
|
+
import { union as ht, debounce as yt } from "lodash";
|
|
12
12
|
import "crypto";
|
|
13
|
-
import z, { mkdtempSync as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { Worker as
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
13
|
+
import z, { mkdtempSync as St, existsSync as ye, readFileSync as wt, createWriteStream as It } from "fs";
|
|
14
|
+
import De from "p-limit";
|
|
15
|
+
import Ne, { join as A, basename as $, dirname as M } from "path";
|
|
16
|
+
import { Worker as Pt } from "worker_threads";
|
|
17
|
+
import * as q from "yaml";
|
|
18
|
+
import bt from "yaml";
|
|
19
|
+
import { nextId as Me } from "@blocklet/pages-kit/utils/common";
|
|
20
|
+
import { unzipSection as At } from "@blocklet/pages-kit/utils/page-model";
|
|
21
|
+
import { getComponentDependencies as Et } from "@blocklet/pages-kit/utils/property";
|
|
22
|
+
import { getComponentWebEndpoint as jt, getResources as Ot, call as Rt } from "@blocklet/sdk/lib/component";
|
|
23
|
+
import { reactive as Ct } from "@reactivedata/reactive";
|
|
24
|
+
import { rm as Se, rename as _e, mkdir as G, writeFile as ie, lstat as ne, readFile as ae, copyFile as Dt, readdir as kt } from "fs/promises";
|
|
25
|
+
import { globSync as vt, glob as we } from "glob";
|
|
24
26
|
import * as fe from "lib0/decoding";
|
|
25
27
|
import * as v from "lib0/encoding";
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import { LRUCache as
|
|
32
|
-
import { pipeline as
|
|
33
|
-
import { x as
|
|
34
|
-
import
|
|
35
|
-
import { Awareness as
|
|
36
|
-
import { writeUpdate as
|
|
37
|
-
import
|
|
38
|
-
import { m as _e } from "./html-DOgzvdOd.js";
|
|
28
|
+
import ke from "lodash/debounce";
|
|
29
|
+
import ve from "lodash/get";
|
|
30
|
+
import Te from "lodash/isEmpty";
|
|
31
|
+
import Fe from "lodash/set";
|
|
32
|
+
import Tt from "lodash/union";
|
|
33
|
+
import { LRUCache as He } from "lru-cache";
|
|
34
|
+
import { pipeline as Lt } from "stream/promises";
|
|
35
|
+
import { x as $t } from "tar";
|
|
36
|
+
import Ut from "wait-on";
|
|
37
|
+
import { Awareness as Nt, encodeAwarenessUpdate as xe, removeAwarenessStates as Mt, applyAwarenessUpdate as _t } from "y-protocols/awareness";
|
|
38
|
+
import { writeUpdate as Ft, writeSyncStep1 as xt, readSyncMessage as Bt } from "y-protocols/sync";
|
|
39
|
+
import { m as Be } from "./html-DOgzvdOd.js";
|
|
39
40
|
import "@blocklet/pages-kit/types/state";
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const _ = new
|
|
41
|
+
const Gt = P.sqlite.DATE.parse;
|
|
42
|
+
P.sqlite.DATE.parse = (t, e) => typeof t == "number" ? new Date(t) : Gt(t, e);
|
|
43
|
+
const _ = new gt({
|
|
43
44
|
dialect: "sqlite",
|
|
44
|
-
storage:
|
|
45
|
+
storage: Je,
|
|
45
46
|
benchmark: process.env.ENABLE_SEQUELIZE_BENCHMARK === "true",
|
|
46
47
|
retry: {
|
|
47
48
|
match: [/SQLITE_BUSY/],
|
|
@@ -62,7 +63,7 @@ process.on("SIGINT", async () => {
|
|
|
62
63
|
process.on("SIGTERM", async () => {
|
|
63
64
|
await _.close(), process.exit(0);
|
|
64
65
|
});
|
|
65
|
-
async function
|
|
66
|
+
async function Vt(t, e) {
|
|
66
67
|
try {
|
|
67
68
|
if (t.getDialect() !== "sqlite")
|
|
68
69
|
return;
|
|
@@ -76,54 +77,54 @@ async function Gt(t, e) {
|
|
|
76
77
|
console.error("Failed to cleanup SQLite memory", e, s);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
let Ie = null;
|
|
81
|
+
Ie && clearInterval(Ie);
|
|
82
|
+
Ie = setInterval(
|
|
82
83
|
async () => {
|
|
83
|
-
p.info("Start cleanupSqliteMemory"), await
|
|
84
|
+
p.info("Start cleanupSqliteMemory"), await Vt(_, Je), p.info("End cleanupSqliteMemory");
|
|
84
85
|
},
|
|
85
86
|
60 * 1e3 * 10
|
|
86
87
|
// 10 minutes
|
|
87
88
|
);
|
|
88
|
-
const
|
|
89
|
-
class
|
|
89
|
+
const zt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o", Ge = "page", Pe = "trigger-reload-project-resource", Ye = zt, qt = "z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM", Wt = "z8iZiDFg3vkkrPwsiba1TLXy3H9XHzFERsP8o";
|
|
90
|
+
class Le extends Re {
|
|
90
91
|
// Foreign key to Component
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
Le.init(
|
|
93
94
|
{
|
|
94
95
|
id: {
|
|
95
|
-
type:
|
|
96
|
+
type: P.UUID,
|
|
96
97
|
allowNull: !1,
|
|
97
98
|
primaryKey: !0,
|
|
98
|
-
defaultValue:
|
|
99
|
+
defaultValue: P.UUIDV4
|
|
99
100
|
},
|
|
100
101
|
projectId: {
|
|
101
|
-
type:
|
|
102
|
+
type: P.UUID,
|
|
102
103
|
allowNull: !1
|
|
103
104
|
},
|
|
104
105
|
componentId: {
|
|
105
|
-
type:
|
|
106
|
+
type: P.STRING,
|
|
106
107
|
allowNull: !1
|
|
107
108
|
}
|
|
108
109
|
},
|
|
109
110
|
{ sequelize: _, tableName: "ProjectComponents", timestamps: !1 }
|
|
110
111
|
);
|
|
111
|
-
const
|
|
112
|
+
const Jt = "SLUG_INVALID", Y = (t) => ({
|
|
112
113
|
error: "slugInvalid",
|
|
113
|
-
code:
|
|
114
|
+
code: Jt,
|
|
114
115
|
field: "slug",
|
|
115
116
|
message: t
|
|
116
|
-
}),
|
|
117
|
+
}), Kt = {
|
|
117
118
|
error: "slugRequired",
|
|
118
119
|
code: "SLUG_REQUIRED",
|
|
119
120
|
field: "slug",
|
|
120
121
|
message: () => "Project slug is required"
|
|
121
|
-
},
|
|
122
|
+
}, Ht = {
|
|
122
123
|
error: "slugAlreadyExists",
|
|
123
124
|
code: "SLUG_EXISTS",
|
|
124
125
|
field: "slug",
|
|
125
126
|
message: (t) => `Project slug "${t}" already exists`
|
|
126
|
-
},
|
|
127
|
+
}, Yt = [
|
|
127
128
|
/\.\./,
|
|
128
129
|
// Directory traversal
|
|
129
130
|
/<[^>]*>/,
|
|
@@ -139,17 +140,17 @@ const Wt = "SLUG_INVALID", K = (t) => ({
|
|
|
139
140
|
// Control characters
|
|
140
141
|
/[^a-zA-Z0-9-_@/\\:]/
|
|
141
142
|
// Only allow specific characters
|
|
142
|
-
],
|
|
143
|
+
], Ve = (t) => {
|
|
143
144
|
if (!t) return "";
|
|
144
145
|
if (t === "/") return "/";
|
|
145
|
-
const e =
|
|
146
|
-
return
|
|
147
|
-
},
|
|
148
|
-
class U extends
|
|
146
|
+
const e = Ce(t);
|
|
147
|
+
return Ke(e) || "/";
|
|
148
|
+
}, Xt = (t) => t.did === Wt;
|
|
149
|
+
class U extends Re {
|
|
149
150
|
static async getProjectByIdOrSlug(e, s) {
|
|
150
151
|
return e ? U.findOne({
|
|
151
152
|
where: {
|
|
152
|
-
[
|
|
153
|
+
[te.or]: [{ id: e }, { slug: e }],
|
|
153
154
|
...s?.createdBy ? { createdBy: s.createdBy } : {}
|
|
154
155
|
}
|
|
155
156
|
}) : null;
|
|
@@ -161,53 +162,53 @@ class U extends Ee {
|
|
|
161
162
|
if (e == null)
|
|
162
163
|
return null;
|
|
163
164
|
if (e === "")
|
|
164
|
-
return
|
|
165
|
-
const a = e === "/" ? "/" :
|
|
165
|
+
return Kt;
|
|
166
|
+
const a = e === "/" ? "/" : Ce(Ke(e)), o = Ve(a);
|
|
166
167
|
if (a !== "/" && a.endsWith("/"))
|
|
167
|
-
return
|
|
168
|
+
return Y((n) => `Project slug "${n}" cannot end with /`);
|
|
168
169
|
if (/\/{2,}/.test(a))
|
|
169
|
-
return
|
|
170
|
+
return Y((n) => `Project slug "${n}" cannot contain consecutive /`);
|
|
170
171
|
if (/\s/.test(a))
|
|
171
|
-
return
|
|
172
|
-
if (
|
|
173
|
-
return
|
|
174
|
-
if (E.components?.filter((n) => n.mountPoint && !
|
|
175
|
-
return
|
|
176
|
-
const
|
|
172
|
+
return Y((n) => `Project slug "${n}" cannot contain whitespace`);
|
|
173
|
+
if (Yt.some((n) => n.test(a)))
|
|
174
|
+
return Y((n) => `Project slug "${n}" contains invalid characters`);
|
|
175
|
+
if (E.components?.filter((n) => n.mountPoint && !Xt(n)).some((n) => Ve(n.mountPoint) === o))
|
|
176
|
+
return Y((n) => `Project slug "${n}" conflicts with existing blocklet`);
|
|
177
|
+
const i = await U.findOne({
|
|
177
178
|
where: { slug: a }
|
|
178
179
|
});
|
|
179
|
-
return
|
|
180
|
+
return i && i?.id !== s ? Ht : null;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
U.init(
|
|
183
184
|
{
|
|
184
185
|
id: {
|
|
185
|
-
type:
|
|
186
|
-
defaultValue:
|
|
186
|
+
type: P.UUID,
|
|
187
|
+
defaultValue: P.UUIDV4,
|
|
187
188
|
primaryKey: !0
|
|
188
189
|
},
|
|
189
190
|
name: {
|
|
190
|
-
type:
|
|
191
|
+
type: P.STRING,
|
|
191
192
|
allowNull: !1
|
|
192
193
|
},
|
|
193
|
-
description:
|
|
194
|
-
createdAt:
|
|
195
|
-
updatedAt:
|
|
194
|
+
description: P.TEXT,
|
|
195
|
+
createdAt: P.DATE,
|
|
196
|
+
updatedAt: P.DATE,
|
|
196
197
|
createdBy: {
|
|
197
|
-
type:
|
|
198
|
+
type: P.STRING,
|
|
198
199
|
allowNull: !1
|
|
199
200
|
},
|
|
200
201
|
updatedBy: {
|
|
201
|
-
type:
|
|
202
|
+
type: P.STRING,
|
|
202
203
|
allowNull: !1
|
|
203
204
|
},
|
|
204
|
-
slug:
|
|
205
|
-
icon:
|
|
206
|
-
pinnedAt:
|
|
207
|
-
useAllResources:
|
|
208
|
-
npmSecret:
|
|
205
|
+
slug: P.STRING,
|
|
206
|
+
icon: P.STRING,
|
|
207
|
+
pinnedAt: P.DATE,
|
|
208
|
+
useAllResources: P.BOOLEAN,
|
|
209
|
+
npmSecret: P.STRING,
|
|
209
210
|
relatedBlocklets: {
|
|
210
|
-
type:
|
|
211
|
+
type: P.JSON,
|
|
211
212
|
allowNull: !1,
|
|
212
213
|
defaultValue: {},
|
|
213
214
|
get() {
|
|
@@ -229,7 +230,7 @@ U.init(
|
|
|
229
230
|
}
|
|
230
231
|
},
|
|
231
232
|
productionState: {
|
|
232
|
-
type:
|
|
233
|
+
type: P.JSON,
|
|
233
234
|
allowNull: !1,
|
|
234
235
|
defaultValue: {},
|
|
235
236
|
get() {
|
|
@@ -251,7 +252,7 @@ U.init(
|
|
|
251
252
|
}
|
|
252
253
|
},
|
|
253
254
|
meta: {
|
|
254
|
-
type:
|
|
255
|
+
type: P.JSON,
|
|
255
256
|
allowNull: !0
|
|
256
257
|
}
|
|
257
258
|
},
|
|
@@ -276,119 +277,119 @@ U.init(
|
|
|
276
277
|
],
|
|
277
278
|
where: {
|
|
278
279
|
meta: {
|
|
279
|
-
[
|
|
280
|
+
[te.ne]: null
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
]
|
|
284
285
|
}
|
|
285
286
|
);
|
|
286
|
-
U.hasMany(
|
|
287
|
+
U.hasMany(Le, {
|
|
287
288
|
foreignKey: "projectId",
|
|
288
289
|
as: "components"
|
|
289
290
|
});
|
|
290
|
-
async function
|
|
291
|
+
async function F(t) {
|
|
291
292
|
try {
|
|
292
293
|
return await z.promises.access(t, z.constants.F_OK), !0;
|
|
293
294
|
} catch {
|
|
294
295
|
return !1;
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
|
-
function
|
|
298
|
+
function Xe(t, e) {
|
|
298
299
|
return new Promise((s, a) => {
|
|
299
300
|
const o = z.createReadStream(t), r = z.createWriteStream(e);
|
|
300
301
|
o.on("error", a), r.on("error", a), r.on("finish", s), o.pipe(r);
|
|
301
302
|
});
|
|
302
303
|
}
|
|
303
|
-
async function
|
|
304
|
+
async function Qe(t, e) {
|
|
304
305
|
await z.promises.mkdir(e, { recursive: !0 });
|
|
305
306
|
const s = await z.promises.readdir(t, { withFileTypes: !0 });
|
|
306
307
|
for (const a of s) {
|
|
307
|
-
const o =
|
|
308
|
-
a.isDirectory() ? await
|
|
308
|
+
const o = Ne.join(t, a.name), r = Ne.join(e, a.name);
|
|
309
|
+
a.isDirectory() ? await Qe(o, r) : await Xe(o, r);
|
|
309
310
|
}
|
|
310
311
|
}
|
|
311
|
-
async function
|
|
312
|
-
(await z.promises.stat(t)).isDirectory() ? await
|
|
312
|
+
async function oa(t, e) {
|
|
313
|
+
(await z.promises.stat(t)).isDirectory() ? await Qe(t, e) : await Xe(t, e);
|
|
313
314
|
}
|
|
314
|
-
class
|
|
315
|
+
class se extends Re {
|
|
315
316
|
}
|
|
316
|
-
|
|
317
|
+
se.init(
|
|
317
318
|
{
|
|
318
319
|
id: {
|
|
319
|
-
type:
|
|
320
|
+
type: P.UUID,
|
|
320
321
|
primaryKey: !0,
|
|
321
|
-
defaultValue:
|
|
322
|
+
defaultValue: P.UUIDV4
|
|
322
323
|
},
|
|
323
324
|
projectId: {
|
|
324
|
-
type:
|
|
325
|
+
type: P.UUID,
|
|
325
326
|
allowNull: !1,
|
|
326
327
|
comment: "Project ID"
|
|
327
328
|
},
|
|
328
329
|
urlPath: {
|
|
329
|
-
type:
|
|
330
|
+
type: P.STRING(512),
|
|
330
331
|
allowNull: !1,
|
|
331
332
|
unique: !0,
|
|
332
333
|
comment: "URL path, e.g. /project-slug/page-slug or /en/project-slug/page-slug"
|
|
333
334
|
},
|
|
334
335
|
projectSlug: {
|
|
335
|
-
type:
|
|
336
|
+
type: P.STRING,
|
|
336
337
|
allowNull: !0,
|
|
337
338
|
comment: "Project slug"
|
|
338
339
|
},
|
|
339
340
|
pageSlug: {
|
|
340
|
-
type:
|
|
341
|
+
type: P.STRING,
|
|
341
342
|
allowNull: !1,
|
|
342
343
|
comment: "Page slug"
|
|
343
344
|
},
|
|
344
345
|
pageId: {
|
|
345
|
-
type:
|
|
346
|
+
type: P.UUID,
|
|
346
347
|
allowNull: !1,
|
|
347
348
|
comment: "Page ID"
|
|
348
349
|
},
|
|
349
350
|
routeId: {
|
|
350
|
-
type:
|
|
351
|
+
type: P.UUID,
|
|
351
352
|
allowNull: !0,
|
|
352
353
|
comment: "Route ID (for draft mode)"
|
|
353
354
|
},
|
|
354
355
|
locale: {
|
|
355
|
-
type:
|
|
356
|
+
type: P.STRING(10),
|
|
356
357
|
allowNull: !0,
|
|
357
358
|
comment: "Locale code, e.g. en, zh"
|
|
358
359
|
},
|
|
359
360
|
defaultLocale: {
|
|
360
|
-
type:
|
|
361
|
+
type: P.STRING(10),
|
|
361
362
|
allowNull: !0,
|
|
362
363
|
comment: "Default locale"
|
|
363
364
|
},
|
|
364
365
|
shouldRedirect: {
|
|
365
|
-
type:
|
|
366
|
+
type: P.BOOLEAN,
|
|
366
367
|
defaultValue: !1,
|
|
367
368
|
comment: "Whether this URL should redirect"
|
|
368
369
|
},
|
|
369
370
|
mainPage: {
|
|
370
|
-
type:
|
|
371
|
+
type: P.BOOLEAN,
|
|
371
372
|
defaultValue: !1,
|
|
372
373
|
comment: "Whether this is the main page"
|
|
373
374
|
},
|
|
374
375
|
isPublic: {
|
|
375
|
-
type:
|
|
376
|
+
type: P.BOOLEAN,
|
|
376
377
|
allowNull: !1,
|
|
377
378
|
defaultValue: !0,
|
|
378
379
|
comment: "Whether the page is public"
|
|
379
380
|
},
|
|
380
381
|
publishedAt: {
|
|
381
|
-
type:
|
|
382
|
+
type: P.BIGINT,
|
|
382
383
|
allowNull: !0,
|
|
383
384
|
comment: "Published timestamp"
|
|
384
385
|
},
|
|
385
386
|
locales: {
|
|
386
|
-
type:
|
|
387
|
+
type: P.JSON,
|
|
387
388
|
allowNull: !0,
|
|
388
389
|
comment: "Supported locales array"
|
|
389
390
|
},
|
|
390
|
-
createdAt:
|
|
391
|
-
updatedAt:
|
|
391
|
+
createdAt: P.DATE,
|
|
392
|
+
updatedAt: P.DATE
|
|
392
393
|
},
|
|
393
394
|
{
|
|
394
395
|
sequelize: _,
|
|
@@ -411,30 +412,30 @@ ee.init(
|
|
|
411
412
|
]
|
|
412
413
|
}
|
|
413
414
|
);
|
|
414
|
-
function
|
|
415
|
-
const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r =
|
|
415
|
+
function Qt(t) {
|
|
416
|
+
const { projectId: e, projectSlug: s, state: a } = t, o = s || e, r = ht(
|
|
416
417
|
E.env.languages?.map((l) => l.code) || [],
|
|
417
418
|
a.supportedLocales?.map((l) => l.locale) || []
|
|
418
|
-
),
|
|
419
|
-
o && (
|
|
419
|
+
), i = {}, n = (l, h) => {
|
|
420
|
+
o && (i[B("/", o, l)] = {
|
|
420
421
|
...h,
|
|
421
422
|
shouldRedirect: !0,
|
|
422
423
|
mainPage: !0
|
|
423
|
-
}),
|
|
424
|
+
}), i[B("/", e, l)] = {
|
|
424
425
|
...h,
|
|
425
426
|
shouldRedirect: !0,
|
|
426
427
|
mainPage: !0
|
|
427
428
|
};
|
|
428
|
-
for (const
|
|
429
|
-
const O = { ...h, locale:
|
|
430
|
-
|
|
429
|
+
for (const b of r) {
|
|
430
|
+
const O = { ...h, locale: b };
|
|
431
|
+
i[B("/", b, e, l)] = O, o && (i[B("/", b, o, l)] = O);
|
|
431
432
|
}
|
|
432
433
|
};
|
|
433
434
|
for (const l of a.pageIds || []) {
|
|
434
435
|
const h = a.pages?.[l];
|
|
435
436
|
if (!h || !h.isPublic)
|
|
436
437
|
continue;
|
|
437
|
-
const
|
|
438
|
+
const b = {
|
|
438
439
|
projectId: e,
|
|
439
440
|
projectSlug: o,
|
|
440
441
|
pageSlug: h.slug,
|
|
@@ -444,18 +445,18 @@ function Xt(t) {
|
|
|
444
445
|
publishedAt: a.config?.publishedAt,
|
|
445
446
|
isPublic: h.isPublic
|
|
446
447
|
};
|
|
447
|
-
n(h.slug,
|
|
448
|
+
n(h.slug, b);
|
|
448
449
|
}
|
|
449
|
-
return
|
|
450
|
+
return i;
|
|
450
451
|
}
|
|
451
|
-
async function
|
|
452
|
-
const a = t.map((r) => r.urlPath), o = await
|
|
452
|
+
async function Zt(t, e, s) {
|
|
453
|
+
const a = t.map((r) => r.urlPath), o = await se.findAll({
|
|
453
454
|
where: {
|
|
454
455
|
urlPath: {
|
|
455
|
-
[
|
|
456
|
+
[te.in]: a
|
|
456
457
|
},
|
|
457
458
|
projectId: {
|
|
458
|
-
[
|
|
459
|
+
[te.ne]: e
|
|
459
460
|
}
|
|
460
461
|
},
|
|
461
462
|
attributes: ["urlPath", "projectId", "projectSlug", "pageSlug"],
|
|
@@ -467,11 +468,11 @@ async function Qt(t, e, s) {
|
|
|
467
468
|
`[URL Duplicate Warning] Found ${o.length} URL conflicts for project ${e}:`
|
|
468
469
|
);
|
|
469
470
|
for (const r of o) {
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
472
|
-
const n = r.projectSlug ?
|
|
471
|
+
const i = t.find((n) => n.urlPath === r.urlPath);
|
|
472
|
+
if (i) {
|
|
473
|
+
const n = r.projectSlug ? B(r.projectSlug, r.pageSlug) : r.pageSlug;
|
|
473
474
|
p.warn(
|
|
474
|
-
` - URL "${r.urlPath}" conflicts with project ${r.projectId} (${n}). Current project trying to use same URL for page: ${
|
|
475
|
+
` - URL "${r.urlPath}" conflicts with project ${r.projectId} (${n}). Current project trying to use same URL for page: ${i.pageSlug}`
|
|
475
476
|
);
|
|
476
477
|
}
|
|
477
478
|
}
|
|
@@ -480,42 +481,42 @@ async function Qt(t, e, s) {
|
|
|
480
481
|
);
|
|
481
482
|
}
|
|
482
483
|
}
|
|
483
|
-
async function
|
|
484
|
+
async function es(t) {
|
|
484
485
|
const { projectId: e, transaction: s } = t;
|
|
485
486
|
try {
|
|
486
|
-
await
|
|
487
|
+
await se.destroy({
|
|
487
488
|
where: { projectId: e },
|
|
488
489
|
transaction: s
|
|
489
490
|
});
|
|
490
|
-
const a =
|
|
491
|
+
const a = Qt(t), o = Object.entries(a).map(([r, i]) => ({
|
|
491
492
|
projectId: e,
|
|
492
493
|
urlPath: r,
|
|
493
|
-
projectSlug:
|
|
494
|
-
pageSlug:
|
|
495
|
-
pageId:
|
|
496
|
-
routeId:
|
|
497
|
-
locale:
|
|
498
|
-
defaultLocale:
|
|
499
|
-
shouldRedirect:
|
|
500
|
-
mainPage:
|
|
501
|
-
isPublic:
|
|
502
|
-
publishedAt: typeof
|
|
503
|
-
locales:
|
|
494
|
+
projectSlug: i.projectSlug,
|
|
495
|
+
pageSlug: i.pageSlug,
|
|
496
|
+
pageId: i.pageId,
|
|
497
|
+
routeId: i.routeId,
|
|
498
|
+
locale: i.locale,
|
|
499
|
+
defaultLocale: i.defaultLocale,
|
|
500
|
+
shouldRedirect: i.shouldRedirect,
|
|
501
|
+
mainPage: i.mainPage,
|
|
502
|
+
isPublic: i.isPublic,
|
|
503
|
+
publishedAt: typeof i.publishedAt == "number" ? i.publishedAt : void 0,
|
|
504
|
+
locales: i.locales
|
|
504
505
|
}));
|
|
505
506
|
if (o.length > 0) {
|
|
506
|
-
await
|
|
507
|
-
const r = 100,
|
|
507
|
+
await Zt(o, e, s);
|
|
508
|
+
const r = 100, i = [];
|
|
508
509
|
for (let n = 0; n < o.length; n += r) {
|
|
509
510
|
const l = o.slice(n, n + r);
|
|
510
|
-
|
|
511
|
-
|
|
511
|
+
i.push(
|
|
512
|
+
se.bulkCreate(l, {
|
|
512
513
|
transaction: s,
|
|
513
514
|
ignoreDuplicates: !0
|
|
514
515
|
// 忽略重复数据,避免因脏数据导致整批插入失败
|
|
515
516
|
})
|
|
516
517
|
);
|
|
517
518
|
}
|
|
518
|
-
await Promise.all(
|
|
519
|
+
await Promise.all(i), p.info(`Regenerated ${o.length} URL mappings for project ${e}`);
|
|
519
520
|
}
|
|
520
521
|
return o.length;
|
|
521
522
|
} catch (a) {
|
|
@@ -527,8 +528,8 @@ function ce(t) {
|
|
|
527
528
|
e.some((s) => s.changes.keys.has("updatedAt") || s.changes.keys.has("publishedAt")) || t.set("updatedAt", (/* @__PURE__ */ new Date()).toISOString());
|
|
528
529
|
});
|
|
529
530
|
}
|
|
530
|
-
function
|
|
531
|
-
return
|
|
531
|
+
function Ze() {
|
|
532
|
+
return St(A(E.env.dataDir, "tmp-"));
|
|
532
533
|
}
|
|
533
534
|
function le(t, e, s = []) {
|
|
534
535
|
return Array.isArray(t) ? t.flatMap((a, o) => le(a, e, [...s, o])) : typeof t == "object" ? t === null ? [] : Object.entries(t).flatMap(([a, o]) => le(o, e, [...s, a])) : e(t) ? [s] : [];
|
|
@@ -536,56 +537,64 @@ function le(t, e, s = []) {
|
|
|
536
537
|
function L(t) {
|
|
537
538
|
return t.filter((e) => e != null);
|
|
538
539
|
}
|
|
539
|
-
function
|
|
540
|
+
function ts(t) {
|
|
540
541
|
return new Promise((e, s) => {
|
|
541
542
|
let a;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
543
|
+
const o = A(__dirname, "api/dist/utils/yaml-worker.js"), r = A(__dirname, "yaml-worker.js");
|
|
544
|
+
if (ye(o))
|
|
545
|
+
a = o;
|
|
546
|
+
else if (ye(r))
|
|
547
|
+
a = r;
|
|
548
|
+
else {
|
|
549
|
+
p.error(`Worker file not found. Tried: ${o}, ${r}`), e(bt.stringify(t));
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const i = new Pt(a);
|
|
553
|
+
i.postMessage({ payload: t }), i.on("message", (n) => {
|
|
554
|
+
n.status === "success" ? e(n.result) : s(new Error(`YAML stringify failed in worker: ${n.message}`)), i.terminate();
|
|
555
|
+
}), i.on("error", (n) => {
|
|
556
|
+
s(n);
|
|
557
|
+
}), i.on("exit", (n) => {
|
|
558
|
+
n !== 0 && s(new Error(`Worker stopped with exit code ${n}`));
|
|
550
559
|
});
|
|
551
560
|
});
|
|
552
561
|
}
|
|
553
|
-
function
|
|
562
|
+
function ss(t) {
|
|
554
563
|
t.pages && Object.keys(t.pages).forEach((s) => {
|
|
555
564
|
const a = W(t.pages[s]);
|
|
556
|
-
a && a instanceof
|
|
565
|
+
a && a instanceof x.Map && ce(a);
|
|
557
566
|
});
|
|
558
567
|
const e = W(t.pages);
|
|
559
|
-
e && e instanceof
|
|
568
|
+
e && e instanceof x.Map && e.observe((s) => {
|
|
560
569
|
s.changes.keys.forEach((a, o) => {
|
|
561
570
|
if (a.action === "add") {
|
|
562
571
|
const r = W(t.pages[o]);
|
|
563
|
-
r && r instanceof
|
|
572
|
+
r && r instanceof x.Map && ce(r);
|
|
564
573
|
}
|
|
565
574
|
});
|
|
566
575
|
});
|
|
567
576
|
}
|
|
568
|
-
function
|
|
577
|
+
function as(t) {
|
|
569
578
|
t.routes && Object.keys(t.routes).forEach((s) => {
|
|
570
579
|
const a = W(t.routes?.[s]);
|
|
571
|
-
a && a instanceof
|
|
580
|
+
a && a instanceof x.Map && ce(a);
|
|
572
581
|
});
|
|
573
582
|
const e = W(t.routes);
|
|
574
|
-
e && e instanceof
|
|
583
|
+
e && e instanceof x.Map && e.observe((s) => {
|
|
575
584
|
s.changes.keys.forEach((a, o) => {
|
|
576
585
|
if (a.action === "add") {
|
|
577
586
|
const r = W(t.routes?.[o]);
|
|
578
|
-
r && r instanceof
|
|
587
|
+
r && r instanceof x.Map && ce(r);
|
|
579
588
|
}
|
|
580
589
|
});
|
|
581
590
|
});
|
|
582
591
|
}
|
|
583
|
-
function
|
|
592
|
+
function os(t, e) {
|
|
584
593
|
for (const s of e || Object.keys(t.routes || {})) {
|
|
585
594
|
let a = s, o = [];
|
|
586
595
|
if (s.includes("-")) {
|
|
587
|
-
const [r, ...
|
|
588
|
-
a = r, o =
|
|
596
|
+
const [r, ...i] = s.split("-");
|
|
597
|
+
a = r, o = i || [];
|
|
589
598
|
}
|
|
590
599
|
if (t.routes?.[a] !== void 0) {
|
|
591
600
|
t.routes[a].publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -593,11 +602,11 @@ function as(t, e) {
|
|
|
593
602
|
if (!r || !r.params || r.params.length === 0)
|
|
594
603
|
continue;
|
|
595
604
|
if (s.includes("-") && o.length > 0) {
|
|
596
|
-
const
|
|
597
|
-
|
|
605
|
+
const i = mt(o, r);
|
|
606
|
+
i && (i.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
598
607
|
}
|
|
599
608
|
if (!e) {
|
|
600
|
-
const
|
|
609
|
+
const i = je({
|
|
601
610
|
basePath: r.path,
|
|
602
611
|
params: r.params,
|
|
603
612
|
routeId: r.id,
|
|
@@ -607,7 +616,7 @@ function as(t, e) {
|
|
|
607
616
|
currentOptionIds: [],
|
|
608
617
|
result: []
|
|
609
618
|
});
|
|
610
|
-
for (const n of
|
|
619
|
+
for (const n of i)
|
|
611
620
|
n.routeMetaData ??= {}, n.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
612
621
|
}
|
|
613
622
|
}
|
|
@@ -624,7 +633,7 @@ function me({
|
|
|
624
633
|
`Executing datasource data assembly, routeId: ${a}, routePathInfo: ${JSON.stringify(o)}`
|
|
625
634
|
);
|
|
626
635
|
const r = {
|
|
627
|
-
...
|
|
636
|
+
...Oe(t),
|
|
628
637
|
id: a,
|
|
629
638
|
slug: o?.path ?? e.path,
|
|
630
639
|
createdAt: e.createdAt,
|
|
@@ -632,56 +641,56 @@ function me({
|
|
|
632
641
|
publishedAt: o?.routeMetaData?.publishedAt ?? e.publishedAt,
|
|
633
642
|
isPublic: (o?.routeMetaData?.isPublic ?? e.isPublic) && e.isPublic
|
|
634
643
|
};
|
|
635
|
-
for (const
|
|
644
|
+
for (const i of s.supportedLocales) {
|
|
636
645
|
if (e.dataSource) {
|
|
637
646
|
let n = e.id;
|
|
638
647
|
o && (n = o.paramOptionIds.join("-"));
|
|
639
|
-
const l = e.dataSource.pathDataMappings?.[n]?.dataCache?.[
|
|
648
|
+
const l = e.dataSource.pathDataMappings?.[n]?.dataCache?.[i.locale] ?? e.dataSource.pathDataMappings?.[n]?.dataCache?.[s.config.defaultLocale || "en"];
|
|
640
649
|
if (!l)
|
|
641
650
|
continue;
|
|
642
|
-
|
|
651
|
+
ft(r, s, i.locale, l);
|
|
643
652
|
}
|
|
644
653
|
o && o.routeMetaData && (o.routeMetaData.publishedAt = (/* @__PURE__ */ new Date()).toISOString());
|
|
645
654
|
}
|
|
646
655
|
return r;
|
|
647
656
|
}
|
|
648
657
|
["true", "1", "yes", "y"].includes(process.env.USE_FS_CACHE_HTML ?? "");
|
|
649
|
-
const
|
|
658
|
+
const rs = 60 * 60 * 1e3, Q = new He({
|
|
650
659
|
max: 300,
|
|
651
|
-
ttl:
|
|
660
|
+
ttl: rs,
|
|
652
661
|
ttlResolution: 10 * 1e3,
|
|
653
662
|
// 10 seconds
|
|
654
663
|
allowStale: !0
|
|
655
664
|
});
|
|
656
|
-
function
|
|
665
|
+
function ns(t, e = []) {
|
|
657
666
|
let s = 0;
|
|
658
|
-
const a = Array.from(
|
|
667
|
+
const a = Array.from(Q.keys()), o = t.map((r) => Ce(r));
|
|
659
668
|
for (const r of a)
|
|
660
|
-
for (const
|
|
661
|
-
if (
|
|
662
|
-
|
|
669
|
+
for (const i of o) {
|
|
670
|
+
if (Be(r, { currentPath: i })) {
|
|
671
|
+
Q.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
|
|
663
672
|
break;
|
|
664
673
|
}
|
|
665
674
|
for (const n of e)
|
|
666
|
-
if (
|
|
667
|
-
|
|
675
|
+
if (Be(r, { currentPath: `/${n}${i}` })) {
|
|
676
|
+
Q.delete(r), s++, p.info(`[Cache CLEAR] key: ${r}`);
|
|
668
677
|
break;
|
|
669
678
|
}
|
|
670
679
|
}
|
|
671
680
|
return p.info(`[Cache CLEAR] cleared ${s} entries for paths:`, o), s;
|
|
672
681
|
}
|
|
673
|
-
function
|
|
674
|
-
const t =
|
|
675
|
-
return
|
|
682
|
+
function is() {
|
|
683
|
+
const t = Q.size;
|
|
684
|
+
return Q.clear(), p.info(`[Cache CLEAR ALL] cleared ${t} entries`), t;
|
|
676
685
|
}
|
|
677
|
-
const
|
|
678
|
-
E.events.on(E.Events.envUpdate,
|
|
679
|
-
const { uploadToMediaKit:
|
|
686
|
+
const cs = yt(is, 300);
|
|
687
|
+
E.events.on(E.Events.envUpdate, cs);
|
|
688
|
+
const { uploadToMediaKit: ls } = require("@blocklet/uploader-server"), $e = /^\w+(\w|-|\.)+\w+\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm)$/, Z = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/i, ze = /mediakit:\/\/([a-f0-9]{32}\.(jpe?g|png|gif|svg|bmp|webp|mp4|m4v|webm))/gi, ps = 1e4, us = 3e4, oe = 0, ge = 1, ds = 0, fs = 1, be = E, X = A(process.env.BLOCKLET_DATA_DIR, "site-state"), ra = ["production", "draft"], na = ["production"];
|
|
680
689
|
function pe(t) {
|
|
681
690
|
return t?.replace(/\//g, "|") || "";
|
|
682
691
|
}
|
|
683
|
-
function
|
|
684
|
-
const t =
|
|
692
|
+
function ms() {
|
|
693
|
+
const t = be.env.languages?.map((s) => ({ locale: s.code, name: s.name })) || [], e = t[0]?.locale || "en";
|
|
685
694
|
return {
|
|
686
695
|
pageIds: [],
|
|
687
696
|
pages: {},
|
|
@@ -695,16 +704,16 @@ function fs() {
|
|
|
695
704
|
resources: {}
|
|
696
705
|
};
|
|
697
706
|
}
|
|
698
|
-
class D extends
|
|
707
|
+
class D extends x.Doc {
|
|
699
708
|
constructor(e) {
|
|
700
|
-
if (super(), this.options = e,
|
|
709
|
+
if (super(), this.options = e, ye(this.draftYjsFilePath))
|
|
701
710
|
try {
|
|
702
|
-
|
|
711
|
+
x.applyUpdate(this, wt(this.draftYjsFilePath));
|
|
703
712
|
} catch (s) {
|
|
704
713
|
p.error("Failed to apply update from draft.yjs:", s);
|
|
705
714
|
}
|
|
706
|
-
this.syncedStore =
|
|
707
|
-
|
|
715
|
+
this.syncedStore = Ct(
|
|
716
|
+
dt(
|
|
708
717
|
{
|
|
709
718
|
pages: {},
|
|
710
719
|
pageIds: [],
|
|
@@ -719,7 +728,7 @@ class D extends F.Doc {
|
|
|
719
728
|
},
|
|
720
729
|
this
|
|
721
730
|
)
|
|
722
|
-
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new
|
|
731
|
+
), this.initObserver(), this.on("update", this.updateHandler), this.awareness = new Nt(this), this.awareness.on("update", this.awarenessChangeHandler), this.ensureDataStructure();
|
|
723
732
|
}
|
|
724
733
|
// 延迟释放时间:5 分钟
|
|
725
734
|
static RELEASE_DELAY = 5 * 60 * 1e3;
|
|
@@ -734,8 +743,8 @@ class D extends F.Doc {
|
|
|
734
743
|
if (!e)
|
|
735
744
|
throw new Error("Should provide project context");
|
|
736
745
|
try {
|
|
737
|
-
const s = A(
|
|
738
|
-
await
|
|
746
|
+
const s = A(X, e), a = A(X, `@del-${e}`);
|
|
747
|
+
await F(a) && await Se(a, { recursive: !0, force: !0 }), await _e(s, a);
|
|
739
748
|
} catch (s) {
|
|
740
749
|
p.error("Failed to safe delete project state dir:", s);
|
|
741
750
|
}
|
|
@@ -745,8 +754,8 @@ class D extends F.Doc {
|
|
|
745
754
|
}
|
|
746
755
|
/** @deprecated 不再使用这个 getter 了,仅作为兼容性处理,请使用 getProjectIds 代替 */
|
|
747
756
|
static get projectIds() {
|
|
748
|
-
return
|
|
749
|
-
cwd:
|
|
757
|
+
return vt("*/", {
|
|
758
|
+
cwd: X,
|
|
750
759
|
ignore: ["@del-*", "@tmp-*", ".*", "staging", "production", "@backup-*", "undefined"]
|
|
751
760
|
// Ignore temp directories and hidden files
|
|
752
761
|
});
|
|
@@ -760,7 +769,7 @@ class D extends F.Doc {
|
|
|
760
769
|
throw new Error("Should provide project context");
|
|
761
770
|
let s = D.sharedInstances[e];
|
|
762
771
|
return s || (s = new D({
|
|
763
|
-
path: A(
|
|
772
|
+
path: A(X, e)
|
|
764
773
|
}), D.sharedInstances[e] = s, s);
|
|
765
774
|
}
|
|
766
775
|
// 轻量级 production 状态获取,不加载 draft 数据
|
|
@@ -768,11 +777,11 @@ class D extends F.Doc {
|
|
|
768
777
|
const s = await U.findByPk(e, {
|
|
769
778
|
attributes: ["productionState"]
|
|
770
779
|
});
|
|
771
|
-
if (
|
|
772
|
-
const a = A(
|
|
780
|
+
if (Te(s?.productionState)) {
|
|
781
|
+
const a = A(X, e, "production"), o = await tt(a, { includeResources: !0 }) ?? ms();
|
|
773
782
|
if (!o?.config?.defaultLocale) {
|
|
774
783
|
o.config ??= {};
|
|
775
|
-
const r =
|
|
784
|
+
const r = be.env.languages?.map((i) => ({ locale: i.code, name: i.name })) || [];
|
|
776
785
|
o.config.defaultLocale = r[0]?.locale;
|
|
777
786
|
}
|
|
778
787
|
return o;
|
|
@@ -785,7 +794,7 @@ class D extends F.Doc {
|
|
|
785
794
|
delete D.sharedInstances[e], super.destroy();
|
|
786
795
|
}
|
|
787
796
|
initObserver() {
|
|
788
|
-
|
|
797
|
+
ss(this.syncedStore), as(this.syncedStore);
|
|
789
798
|
}
|
|
790
799
|
get draftYjsFilePath() {
|
|
791
800
|
return A(this.options.path, "draft.yjs");
|
|
@@ -810,22 +819,22 @@ class D extends F.Doc {
|
|
|
810
819
|
async setState(e, s) {
|
|
811
820
|
if (e !== "production")
|
|
812
821
|
return;
|
|
813
|
-
const a = $(this.options.path), o =
|
|
822
|
+
const a = $(this.options.path), o = Oe(s);
|
|
814
823
|
await _.transaction(async (r) => {
|
|
815
824
|
await U.update({ productionState: o }, { where: { id: a }, transaction: r });
|
|
816
|
-
const
|
|
825
|
+
const i = await U.findByPk(a, {
|
|
817
826
|
attributes: ["slug"],
|
|
818
827
|
transaction: r
|
|
819
|
-
}), n = await
|
|
828
|
+
}), n = await es({
|
|
820
829
|
projectId: a,
|
|
821
|
-
projectSlug:
|
|
830
|
+
projectSlug: i?.slug,
|
|
822
831
|
state: s,
|
|
823
832
|
transaction: r
|
|
824
833
|
});
|
|
825
834
|
p.info(`[SiteState] saved ${n} URL mappings for project ${a}`);
|
|
826
835
|
}), await this.clearPageCacheForRoutes(void 0, s), setImmediate(async () => {
|
|
827
|
-
const r = await
|
|
828
|
-
await
|
|
836
|
+
const r = await Ss(s, { exportAssets: !1, includeResources: !0 }), i = this.getPublishDir(e);
|
|
837
|
+
await G(M(i), { recursive: !0 }), await Se(i, { force: !0, recursive: !0 }), await _e(r, i), p.info(`[SiteState] saved package for project ${a} in ${e} mode`);
|
|
829
838
|
});
|
|
830
839
|
}
|
|
831
840
|
getPublishDir(e) {
|
|
@@ -846,20 +855,20 @@ class D extends F.Doc {
|
|
|
846
855
|
l.delete(h);
|
|
847
856
|
}));
|
|
848
857
|
}
|
|
849
|
-
const
|
|
850
|
-
v.writeVarUint(
|
|
851
|
-
const n = v.toUint8Array(
|
|
858
|
+
const i = v.createEncoder();
|
|
859
|
+
v.writeVarUint(i, ge), v.writeVarUint8Array(i, xe(this.awareness, r));
|
|
860
|
+
const n = v.toUint8Array(i);
|
|
852
861
|
this.conns.forEach((l, h) => this.send(h, n));
|
|
853
862
|
};
|
|
854
863
|
updateHandler = (e) => {
|
|
855
864
|
const s = v.createEncoder();
|
|
856
|
-
v.writeVarUint(s, oe),
|
|
865
|
+
v.writeVarUint(s, oe), Ft(s, e);
|
|
857
866
|
const a = v.toUint8Array(s);
|
|
858
867
|
this.conns.forEach((o, r) => this.send(r, a));
|
|
859
868
|
};
|
|
860
869
|
ensureDataStructure = () => {
|
|
861
870
|
this.transact(() => {
|
|
862
|
-
const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds:
|
|
871
|
+
const { supportedLocales: e, pages: s, pageIds: a, config: o, routes: r, routeIds: i } = this.syncedStore;
|
|
863
872
|
{
|
|
864
873
|
const n = new Set(Object.keys(s));
|
|
865
874
|
let l = 0;
|
|
@@ -871,12 +880,12 @@ class D extends F.Doc {
|
|
|
871
880
|
{
|
|
872
881
|
const n = new Set(Object.keys(r));
|
|
873
882
|
let l = 0;
|
|
874
|
-
for (; l <
|
|
875
|
-
const h =
|
|
876
|
-
n.has(h) ? (n.delete(h), l++) :
|
|
883
|
+
for (; l < i.length; ) {
|
|
884
|
+
const h = i[l];
|
|
885
|
+
n.has(h) ? (n.delete(h), l++) : i.splice(l, 1);
|
|
877
886
|
}
|
|
878
887
|
}
|
|
879
|
-
e.splice(0, e.length), e.push(...
|
|
888
|
+
e.splice(0, e.length), e.push(...be.env.languages.map((n) => ({ locale: n.code, name: n.name }))), o.defaultLocale = e[0]?.locale;
|
|
880
889
|
{
|
|
881
890
|
let n = 0;
|
|
882
891
|
const l = /* @__PURE__ */ new Set();
|
|
@@ -888,7 +897,7 @@ class D extends F.Doc {
|
|
|
888
897
|
});
|
|
889
898
|
};
|
|
890
899
|
send = (e, s) => {
|
|
891
|
-
e.readyState !==
|
|
900
|
+
e.readyState !== ds && e.readyState !== fs && this.closeConn(e);
|
|
892
901
|
try {
|
|
893
902
|
e.send(s, (a) => {
|
|
894
903
|
a && this.closeConn(e);
|
|
@@ -900,7 +909,7 @@ class D extends F.Doc {
|
|
|
900
909
|
closeConn = (e) => {
|
|
901
910
|
if (e.removeAllListeners(), this.conns.has(e)) {
|
|
902
911
|
const s = this.conns.get(e);
|
|
903
|
-
this.conns.delete(e), s &&
|
|
912
|
+
this.conns.delete(e), s && Mt(this.awareness, Array.from(s), null);
|
|
904
913
|
}
|
|
905
914
|
e.close(), this.checkAndScheduleRelease();
|
|
906
915
|
};
|
|
@@ -924,19 +933,19 @@ class D extends F.Doc {
|
|
|
924
933
|
p.info(`[SiteState] cancelled scheduled release for project ${e}`);
|
|
925
934
|
}
|
|
926
935
|
}
|
|
927
|
-
autoSave =
|
|
928
|
-
await
|
|
929
|
-
},
|
|
936
|
+
autoSave = ke(async () => {
|
|
937
|
+
await G(M(this.draftYjsFilePath), { recursive: !0 }), await ie(this.draftYjsFilePath, x.encodeStateAsUpdate(this));
|
|
938
|
+
}, ps);
|
|
930
939
|
save = ({ flush: e = !1 } = {}) => {
|
|
931
940
|
this.autoSave(), e && this.autoSave.flush();
|
|
932
941
|
};
|
|
933
942
|
publish = async ({ mode: e, routes: s }) => {
|
|
934
943
|
const a = $(this.options.path);
|
|
935
|
-
await
|
|
944
|
+
await Ps(a, { immediate: !0 });
|
|
936
945
|
const o = await this.getState("draft"), r = await this.getState("production");
|
|
937
|
-
await
|
|
946
|
+
await We(o, r, { routes: s, mergeMode: "replace", deleteRoutes: !0, publishMode: e }), r.config.publishedAt = (/* @__PURE__ */ new Date()).getTime(), setImmediate(() => {
|
|
938
947
|
this.transact(() => {
|
|
939
|
-
|
|
948
|
+
os(this.syncedStore, s);
|
|
940
949
|
});
|
|
941
950
|
}), await this.setState(e, r);
|
|
942
951
|
};
|
|
@@ -944,11 +953,11 @@ class D extends F.Doc {
|
|
|
944
953
|
const a = JSON.parse(JSON.stringify(s));
|
|
945
954
|
e.config.fontFamily ??= {};
|
|
946
955
|
const o = a.config?.fontFamily, r = e.config?.fontFamily;
|
|
947
|
-
e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((
|
|
956
|
+
e.config.fontFamily.title = o?.title || r?.title, e.config.fontFamily.description = o?.description || r?.description, await new Promise((i, n) => {
|
|
948
957
|
this.transact(async () => {
|
|
949
958
|
try {
|
|
950
|
-
const l = await
|
|
951
|
-
|
|
959
|
+
const l = await We(e, s);
|
|
960
|
+
i(l);
|
|
952
961
|
} catch (l) {
|
|
953
962
|
n(l);
|
|
954
963
|
}
|
|
@@ -957,17 +966,17 @@ class D extends F.Doc {
|
|
|
957
966
|
};
|
|
958
967
|
clearPageCacheForRoutes = async (e, s) => {
|
|
959
968
|
const a = $(this.options.path), r = (await U.findByPk(a))?.slug || a;
|
|
960
|
-
let
|
|
961
|
-
(!
|
|
962
|
-
const n = s.supportedLocales.map((
|
|
963
|
-
for (const
|
|
964
|
-
const w = s.pages[
|
|
969
|
+
let i = e;
|
|
970
|
+
(!i || i.length === 0) && (i = s.pageIds ?? []), p.info(`[SiteState] clearing page cache for project ${a}, routes:`, i || []);
|
|
971
|
+
const n = s.supportedLocales.map((b) => b.locale), l = [], h = i.filter((b) => s.pageIds?.includes(b));
|
|
972
|
+
for (const b of h) {
|
|
973
|
+
const w = s.pages[b].slug;
|
|
965
974
|
r && r !== a && (r === "/" ? l.push(w) : l.push(`${r.startsWith("/") ? "" : "/"}${r}${w}`)), l.push(`/${a}${w}`);
|
|
966
975
|
}
|
|
967
976
|
if (l.length > 0)
|
|
968
977
|
try {
|
|
969
|
-
const
|
|
970
|
-
p.info(`[SiteState] cleared ${
|
|
978
|
+
const b = ns(l, n);
|
|
979
|
+
p.info(`[SiteState] cleared ${b} page cache entries for project ${a}, routes:`, i);
|
|
971
980
|
} catch {
|
|
972
981
|
}
|
|
973
982
|
};
|
|
@@ -987,7 +996,7 @@ class D extends F.Doc {
|
|
|
987
996
|
this.closeConn(e), clearInterval(a);
|
|
988
997
|
}
|
|
989
998
|
}
|
|
990
|
-
},
|
|
999
|
+
}, us);
|
|
991
1000
|
e.on("close", () => {
|
|
992
1001
|
this.closeConn(e), clearInterval(a);
|
|
993
1002
|
}), e.on("pong", () => {
|
|
@@ -995,11 +1004,11 @@ class D extends F.Doc {
|
|
|
995
1004
|
});
|
|
996
1005
|
{
|
|
997
1006
|
const o = v.createEncoder();
|
|
998
|
-
v.writeVarUint(o, oe),
|
|
1007
|
+
v.writeVarUint(o, oe), xt(o, this), this.send(e, v.toUint8Array(o));
|
|
999
1008
|
const r = this.awareness.getStates();
|
|
1000
1009
|
if (r.size > 0) {
|
|
1001
|
-
const
|
|
1002
|
-
v.writeVarUint(
|
|
1010
|
+
const i = v.createEncoder();
|
|
1011
|
+
v.writeVarUint(i, ge), v.writeVarUint8Array(i, xe(this.awareness, Array.from(r.keys()))), this.send(e, v.toUint8Array(i));
|
|
1003
1012
|
}
|
|
1004
1013
|
}
|
|
1005
1014
|
};
|
|
@@ -1008,10 +1017,10 @@ class D extends F.Doc {
|
|
|
1008
1017
|
const a = v.createEncoder(), o = fe.createDecoder(s), r = fe.readVarUint(o);
|
|
1009
1018
|
switch (p.info(`[SiteState] messageListener, messageType: ${r}`), r) {
|
|
1010
1019
|
case oe:
|
|
1011
|
-
v.writeVarUint(a, oe),
|
|
1020
|
+
v.writeVarUint(a, oe), Bt(o, a, this, null), p.info(`[SiteState] messageListener, encoder length: ${v.length(a)}`), v.length(a) > 1 && (this.ensureDataStructure(), this.send(e, v.toUint8Array(a)));
|
|
1012
1021
|
break;
|
|
1013
1022
|
case ge: {
|
|
1014
|
-
|
|
1023
|
+
_t(this.awareness, fe.readVarUint8Array(o), e);
|
|
1015
1024
|
break;
|
|
1016
1025
|
}
|
|
1017
1026
|
default:
|
|
@@ -1025,11 +1034,11 @@ class D extends F.Doc {
|
|
|
1025
1034
|
// 这个方法还是需要动态的,因为可能会动态修改 projectSlug、语言之类的
|
|
1026
1035
|
static async pageUrlMap(e, s) {
|
|
1027
1036
|
if (p.info(`[SiteState] get pageUrlMap, mode: ${e}, projectId: ${s}`), e === "production") {
|
|
1028
|
-
const r = s ? { projectId: s } : {},
|
|
1037
|
+
const r = s ? { projectId: s } : {}, i = await se.findAll({
|
|
1029
1038
|
where: r,
|
|
1030
1039
|
raw: !0
|
|
1031
1040
|
}), n = {};
|
|
1032
|
-
for (const l of
|
|
1041
|
+
for (const l of i)
|
|
1033
1042
|
n[l.urlPath] = {
|
|
1034
1043
|
projectId: l.projectId,
|
|
1035
1044
|
projectSlug: l.projectSlug,
|
|
@@ -1044,21 +1053,21 @@ class D extends F.Doc {
|
|
|
1044
1053
|
publishedAt: l.publishedAt,
|
|
1045
1054
|
locales: l.locales
|
|
1046
1055
|
};
|
|
1047
|
-
return p.info(`[SiteState] loaded ${
|
|
1056
|
+
return p.info(`[SiteState] loaded ${i.length} URL mappings from database`), n;
|
|
1048
1057
|
}
|
|
1049
1058
|
let a = [];
|
|
1050
1059
|
s ? a = [s] : a = await this.getProjectIds();
|
|
1051
1060
|
let o = {};
|
|
1052
1061
|
if (a?.length) {
|
|
1053
1062
|
p.info("[SiteState] find project infos from database, projectIds: ", a);
|
|
1054
|
-
const r = 30,
|
|
1063
|
+
const r = 30, i = De(5);
|
|
1055
1064
|
for (let n = 0; n < a.length; n += r) {
|
|
1056
1065
|
const l = a.slice(n, n + r);
|
|
1057
1066
|
p.info(`[SiteState] processing project batch ${n / r + 1}, ids: `, l);
|
|
1058
1067
|
const h = await U.findAll({
|
|
1059
1068
|
where: {
|
|
1060
1069
|
id: {
|
|
1061
|
-
[
|
|
1070
|
+
[te.in]: l
|
|
1062
1071
|
}
|
|
1063
1072
|
},
|
|
1064
1073
|
attributes: {
|
|
@@ -1067,23 +1076,23 @@ class D extends F.Doc {
|
|
|
1067
1076
|
});
|
|
1068
1077
|
await Promise.all(
|
|
1069
1078
|
h?.map(
|
|
1070
|
-
(
|
|
1071
|
-
const O =
|
|
1079
|
+
(b) => i(async () => {
|
|
1080
|
+
const O = b.id, w = b.slug || O, m = {}, u = await D.getStateByProjectId({ projectId: b.id, mode: e, clone: !1 }), I = Tt(
|
|
1072
1081
|
E.env.languages?.map((j) => j.code) || [],
|
|
1073
1082
|
u.supportedLocales?.map((j) => j.locale) || []
|
|
1074
1083
|
), R = (j, S) => {
|
|
1075
|
-
w && (m[
|
|
1084
|
+
w && (m[B("/", w, j)] = {
|
|
1076
1085
|
...S,
|
|
1077
1086
|
shouldRedirect: !0,
|
|
1078
1087
|
mainPage: !0
|
|
1079
|
-
}), m[
|
|
1088
|
+
}), m[B("/", O, j)] = {
|
|
1080
1089
|
...S,
|
|
1081
1090
|
shouldRedirect: !0,
|
|
1082
1091
|
mainPage: !0
|
|
1083
1092
|
};
|
|
1084
1093
|
for (const k of I) {
|
|
1085
1094
|
const g = { ...S, locale: k };
|
|
1086
|
-
m[
|
|
1095
|
+
m[B("/", k, O, j)] = g, w && (m[B("/", k, w, j)] = g);
|
|
1087
1096
|
}
|
|
1088
1097
|
};
|
|
1089
1098
|
if (e === "draft")
|
|
@@ -1091,7 +1100,7 @@ class D extends F.Doc {
|
|
|
1091
1100
|
const S = u?.routes?.[j];
|
|
1092
1101
|
if (!S) continue;
|
|
1093
1102
|
if (S.params && S.params.length > 0) {
|
|
1094
|
-
const y =
|
|
1103
|
+
const y = je({
|
|
1095
1104
|
basePath: S.path,
|
|
1096
1105
|
params: S.params,
|
|
1097
1106
|
routeId: S.id,
|
|
@@ -1101,8 +1110,8 @@ class D extends F.Doc {
|
|
|
1101
1110
|
currentOptionIds: [],
|
|
1102
1111
|
result: []
|
|
1103
1112
|
});
|
|
1104
|
-
for (const
|
|
1105
|
-
const d =
|
|
1113
|
+
for (const c of y) {
|
|
1114
|
+
const d = c.path, f = {
|
|
1106
1115
|
projectId: O,
|
|
1107
1116
|
projectSlug: w,
|
|
1108
1117
|
pageSlug: d,
|
|
@@ -1112,7 +1121,7 @@ class D extends F.Doc {
|
|
|
1112
1121
|
defaultLocale: I?.[0],
|
|
1113
1122
|
locales: I,
|
|
1114
1123
|
publishedAt: u.config.publishedAt,
|
|
1115
|
-
isPublic: S.isPublic &&
|
|
1124
|
+
isPublic: S.isPublic && c?.routeMetaData?.isPublic
|
|
1116
1125
|
};
|
|
1117
1126
|
R(d, f);
|
|
1118
1127
|
}
|
|
@@ -1134,7 +1143,7 @@ class D extends F.Doc {
|
|
|
1134
1143
|
for (const j of u.pageIds || []) {
|
|
1135
1144
|
const S = u.pages[j];
|
|
1136
1145
|
if (!S) continue;
|
|
1137
|
-
const k = S.slug, g =
|
|
1146
|
+
const k = S.slug, g = b.slug || O, y = {
|
|
1138
1147
|
projectId: O,
|
|
1139
1148
|
projectSlug: g,
|
|
1140
1149
|
pageSlug: k,
|
|
@@ -1157,7 +1166,7 @@ class D extends F.Doc {
|
|
|
1157
1166
|
return p.info("[SiteState] success get pageUrlMap"), o;
|
|
1158
1167
|
}
|
|
1159
1168
|
getDocumentSize() {
|
|
1160
|
-
return
|
|
1169
|
+
return x.encodeStateAsUpdate(this).byteLength;
|
|
1161
1170
|
}
|
|
1162
1171
|
static getInstancesSizeInfo() {
|
|
1163
1172
|
const e = [];
|
|
@@ -1197,9 +1206,9 @@ class D extends F.Doc {
|
|
|
1197
1206
|
s.map((r) => r.projectId)
|
|
1198
1207
|
);
|
|
1199
1208
|
let o = 0;
|
|
1200
|
-
for (const { projectId: r, instance:
|
|
1209
|
+
for (const { projectId: r, instance: i } of s)
|
|
1201
1210
|
try {
|
|
1202
|
-
p.info(`[SiteState] releasing instance due to periodic check: ${r}`),
|
|
1211
|
+
p.info(`[SiteState] releasing instance due to periodic check: ${r}`), i.destroy(), o++;
|
|
1203
1212
|
} catch (n) {
|
|
1204
1213
|
p.error(`[SiteState] failed to release instance ${r} during periodic check:`, n);
|
|
1205
1214
|
}
|
|
@@ -1209,216 +1218,217 @@ class D extends F.Doc {
|
|
|
1209
1218
|
} else e > 0 ? p.debug("[SiteState] periodic check: all instances have active connections") : p.debug("[SiteState] periodic check: no instances exist");
|
|
1210
1219
|
}
|
|
1211
1220
|
}
|
|
1212
|
-
async function
|
|
1213
|
-
if (!t || !await
|
|
1221
|
+
async function gs(t, e, s) {
|
|
1222
|
+
if (!t || !await F(t) || !(await ne(t)).isFile())
|
|
1214
1223
|
return null;
|
|
1215
1224
|
let o = s[t];
|
|
1216
1225
|
return o || (o = (async () => {
|
|
1217
1226
|
try {
|
|
1218
|
-
|
|
1227
|
+
const r = (await ls({
|
|
1219
1228
|
filePath: t,
|
|
1220
1229
|
fileName: e
|
|
1221
|
-
}))?.data
|
|
1230
|
+
}))?.data;
|
|
1231
|
+
return r?.filename || r?.dataValues?.filename;
|
|
1222
1232
|
} catch (r) {
|
|
1223
1233
|
return p.error(`Failed to upload asset ${t}:`, r), null;
|
|
1224
1234
|
}
|
|
1225
1235
|
})(), s[t] = o), o;
|
|
1226
1236
|
}
|
|
1227
|
-
const
|
|
1228
|
-
const s = $(t), a = await
|
|
1229
|
-
name:
|
|
1230
|
-
path:
|
|
1237
|
+
const hs = async (t, e) => {
|
|
1238
|
+
const s = $(t), a = await Rt({
|
|
1239
|
+
name: Ye,
|
|
1240
|
+
path: B("/uploads", s),
|
|
1231
1241
|
responseType: "stream",
|
|
1232
1242
|
method: "GET"
|
|
1233
1243
|
});
|
|
1234
1244
|
if (a.status >= 200 && a.status < 400) {
|
|
1235
1245
|
const o = It(e);
|
|
1236
|
-
await
|
|
1246
|
+
await Lt(a.data, o);
|
|
1237
1247
|
} else
|
|
1238
1248
|
throw new Error(`download asset failed ${a.status}`);
|
|
1239
|
-
},
|
|
1249
|
+
}, ys = async (t, e) => {
|
|
1240
1250
|
await Promise.all(
|
|
1241
1251
|
t.map(async (s) => {
|
|
1242
1252
|
try {
|
|
1243
|
-
await
|
|
1253
|
+
await hs(s, A(e, $(s)));
|
|
1244
1254
|
} catch (a) {
|
|
1245
1255
|
p.error(`Failed to export assets: ${s}, ${a}`);
|
|
1246
1256
|
}
|
|
1247
1257
|
})
|
|
1248
1258
|
);
|
|
1249
1259
|
};
|
|
1250
|
-
function
|
|
1251
|
-
return
|
|
1260
|
+
function et(t) {
|
|
1261
|
+
return $e.test(t) ? [t] : Z.test(t) ? (ze.lastIndex = 0, Array.from(t.matchAll(ze)).map((s) => s[1]).filter((s) => !!s)) : [];
|
|
1252
1262
|
}
|
|
1253
1263
|
async function re(t, e, s) {
|
|
1254
|
-
const { getFilename: a, exportAssets: o, useWorker: r } = s,
|
|
1255
|
-
await
|
|
1256
|
-
const n = r ? await
|
|
1257
|
-
if (await ie(
|
|
1264
|
+
const { getFilename: a, exportAssets: o, useWorker: r } = s, i = A(e, a(t));
|
|
1265
|
+
await G(M(i), { recursive: !0 });
|
|
1266
|
+
const n = r ? await ts(t) : q.stringify(t);
|
|
1267
|
+
if (await ie(i, n), o) {
|
|
1258
1268
|
const h = le(
|
|
1259
1269
|
t,
|
|
1260
|
-
(
|
|
1261
|
-
).map((
|
|
1262
|
-
const O =
|
|
1263
|
-
return
|
|
1270
|
+
(b) => typeof b == "string" && ($e.test(b) || Z.test(b))
|
|
1271
|
+
).map((b) => {
|
|
1272
|
+
const O = ve(t, b);
|
|
1273
|
+
return et(O);
|
|
1264
1274
|
}).flat().filter(Boolean);
|
|
1265
|
-
await
|
|
1275
|
+
await ys(h, M(i));
|
|
1266
1276
|
}
|
|
1267
1277
|
}
|
|
1268
|
-
const
|
|
1278
|
+
const Ae = new He({
|
|
1269
1279
|
max: 100,
|
|
1270
1280
|
ttl: 1 * 60 * 1e3
|
|
1271
1281
|
// 1 minute
|
|
1272
1282
|
});
|
|
1273
|
-
async function
|
|
1283
|
+
async function qe(t, e, s) {
|
|
1274
1284
|
const a = le(
|
|
1275
1285
|
t,
|
|
1276
|
-
(n) => typeof n == "string" && (
|
|
1277
|
-
), o =
|
|
1286
|
+
(n) => typeof n == "string" && ($e.test(n) || Z.test(n))
|
|
1287
|
+
), o = De(2), r = a.map(
|
|
1278
1288
|
(n) => o(async () => {
|
|
1279
1289
|
try {
|
|
1280
|
-
const l =
|
|
1281
|
-
for (const
|
|
1282
|
-
const O = $(
|
|
1290
|
+
const l = ve(t, n), h = et(l);
|
|
1291
|
+
for (const b of h) {
|
|
1292
|
+
const O = $(b), w = s.getFilePath(b, n), m = w ? `${w}:${O}` : O, u = Ae.get(m);
|
|
1283
1293
|
if (u) {
|
|
1284
|
-
|
|
1294
|
+
Z.test(l) || Fe(t, n, u);
|
|
1285
1295
|
return;
|
|
1286
1296
|
}
|
|
1287
|
-
const I = await
|
|
1288
|
-
I && (
|
|
1297
|
+
const I = await gs(w, O, e);
|
|
1298
|
+
I && (Z.test(l) || Fe(t, n, I), Ae.set(m, I));
|
|
1289
1299
|
}
|
|
1290
1300
|
} catch (l) {
|
|
1291
1301
|
p.error(`Failed to process upload for path ${n.join(".")}:`, l.message || l.reason);
|
|
1292
1302
|
}
|
|
1293
1303
|
})
|
|
1294
|
-
),
|
|
1295
|
-
s.onFinish?.(
|
|
1304
|
+
), i = await Promise.allSettled(r);
|
|
1305
|
+
s.onFinish?.(i);
|
|
1296
1306
|
}
|
|
1297
|
-
async function
|
|
1307
|
+
async function Ss(t, {
|
|
1298
1308
|
exportAssets: e,
|
|
1299
1309
|
pageIds: s = "all",
|
|
1300
1310
|
componentIds: a = "all",
|
|
1301
1311
|
rawConfig: o,
|
|
1302
1312
|
includeResources: r = !1,
|
|
1303
|
-
routeIds:
|
|
1313
|
+
routeIds: i = "all"
|
|
1304
1314
|
} = {}) {
|
|
1305
|
-
const n = s === "all" ? t.pageIds : s, l =
|
|
1315
|
+
const n = s === "all" ? t.pageIds : s, l = Et({
|
|
1306
1316
|
state: t,
|
|
1307
1317
|
pageIds: n,
|
|
1308
1318
|
componentIds: a === "all" ? Object.keys(t.components) : a
|
|
1309
1319
|
});
|
|
1310
|
-
Object.entries(t.components).forEach(([
|
|
1311
|
-
d.data?.renderer?.type === "component-template" && l.push(
|
|
1320
|
+
Object.entries(t.components).forEach(([c, d]) => {
|
|
1321
|
+
d.data?.renderer?.type === "component-template" && l.push(c);
|
|
1312
1322
|
});
|
|
1313
|
-
const h =
|
|
1314
|
-
id:
|
|
1315
|
-
name:
|
|
1316
|
-
isTemplateSection:
|
|
1317
|
-
templateDescription:
|
|
1323
|
+
const h = i === "all" ? t.routeIds : i, b = (c) => ({
|
|
1324
|
+
id: c.id,
|
|
1325
|
+
name: c.name,
|
|
1326
|
+
isTemplateSection: c.isTemplateSection ?? !1,
|
|
1327
|
+
templateDescription: c.templateDescription,
|
|
1318
1328
|
/** @deprecated 已经废弃,llmConfig 从 component / resources.component 中获取 */
|
|
1319
1329
|
// llmConfig: section.llmConfig,
|
|
1320
|
-
component:
|
|
1321
|
-
config:
|
|
1322
|
-
visibility:
|
|
1323
|
-
sections:
|
|
1324
|
-
|
|
1325
|
-
const f =
|
|
1326
|
-
return f &&
|
|
1330
|
+
component: c.component,
|
|
1331
|
+
config: c.config,
|
|
1332
|
+
visibility: c.visibility,
|
|
1333
|
+
sections: c?.sectionIds ? L(
|
|
1334
|
+
c?.sectionIds?.map((d) => {
|
|
1335
|
+
const f = c.sections?.[d];
|
|
1336
|
+
return f && b(f);
|
|
1327
1337
|
})
|
|
1328
1338
|
) : void 0
|
|
1329
1339
|
/** @deprecated 已经废弃,数据在 page.dataSource 中管理 */
|
|
1330
1340
|
// properties: section.locales?.[locale] ?? {},
|
|
1331
|
-
}), O = (
|
|
1332
|
-
id:
|
|
1333
|
-
createdAt:
|
|
1334
|
-
updatedAt:
|
|
1335
|
-
publishedAt:
|
|
1336
|
-
isPublic:
|
|
1337
|
-
templateConfig:
|
|
1338
|
-
meta:
|
|
1341
|
+
}), O = (c, d) => ({
|
|
1342
|
+
id: c.id,
|
|
1343
|
+
createdAt: c.createdAt,
|
|
1344
|
+
updatedAt: c.updatedAt,
|
|
1345
|
+
publishedAt: c.publishedAt,
|
|
1346
|
+
isPublic: c.isPublic ?? !0,
|
|
1347
|
+
templateConfig: c.templateConfig,
|
|
1348
|
+
meta: c.locales?.[d] ?? {},
|
|
1339
1349
|
sections: L(
|
|
1340
|
-
|
|
1341
|
-
const C =
|
|
1342
|
-
return C &&
|
|
1350
|
+
c.sectionIds.map((f) => {
|
|
1351
|
+
const C = c.sections[f];
|
|
1352
|
+
return C && b(C);
|
|
1343
1353
|
})
|
|
1344
1354
|
),
|
|
1345
1355
|
// 将 dataSource.sectionId.locale 转换为 dataSource.sectionId
|
|
1346
1356
|
dataSource: Object.fromEntries(
|
|
1347
|
-
Object.entries(
|
|
1357
|
+
Object.entries(c.dataSource || {}).map(([f, C]) => [f, C?.[d] ?? {}])
|
|
1348
1358
|
)
|
|
1349
|
-
}), w = (
|
|
1350
|
-
id:
|
|
1351
|
-
createdAt:
|
|
1352
|
-
updatedAt:
|
|
1353
|
-
publishedAt:
|
|
1354
|
-
path:
|
|
1355
|
-
handler:
|
|
1356
|
-
isPublic:
|
|
1357
|
-
params:
|
|
1358
|
-
enabledGenerate:
|
|
1359
|
-
displayTemplateId:
|
|
1360
|
-
dataSource:
|
|
1359
|
+
}), w = (c) => ({
|
|
1360
|
+
id: c.id,
|
|
1361
|
+
createdAt: c.createdAt,
|
|
1362
|
+
updatedAt: c.updatedAt,
|
|
1363
|
+
publishedAt: c.publishedAt,
|
|
1364
|
+
path: c.path,
|
|
1365
|
+
handler: c.handler,
|
|
1366
|
+
isPublic: c.isPublic ?? !0,
|
|
1367
|
+
params: c.params ?? [],
|
|
1368
|
+
enabledGenerate: c.enabledGenerate ?? !1,
|
|
1369
|
+
displayTemplateId: c.displayTemplateId,
|
|
1370
|
+
dataSource: c.dataSource
|
|
1361
1371
|
}), m = L(
|
|
1362
|
-
h.map((
|
|
1363
|
-
const d = t.routes[
|
|
1372
|
+
h.map((c) => {
|
|
1373
|
+
const d = t.routes[c];
|
|
1364
1374
|
return d && w(d);
|
|
1365
1375
|
})
|
|
1366
1376
|
), u = L(
|
|
1367
|
-
t.supportedLocales.map((
|
|
1368
|
-
(
|
|
1377
|
+
t.supportedLocales.map((c) => c.locale).flatMap(
|
|
1378
|
+
(c) => n.map((d) => {
|
|
1369
1379
|
const f = t.pages[d];
|
|
1370
1380
|
return f && {
|
|
1371
|
-
locale:
|
|
1381
|
+
locale: c,
|
|
1372
1382
|
slug: f.slug,
|
|
1373
|
-
page: O(f,
|
|
1383
|
+
page: O(f, c)
|
|
1374
1384
|
};
|
|
1375
1385
|
})
|
|
1376
1386
|
)
|
|
1377
|
-
), I =
|
|
1378
|
-
await
|
|
1387
|
+
), I = Ze(), R = A(I, "pages");
|
|
1388
|
+
await G(R, { recursive: !0 });
|
|
1379
1389
|
const j = A(I, "components");
|
|
1380
|
-
await
|
|
1390
|
+
await G(j, { recursive: !0 });
|
|
1381
1391
|
const S = A(I, "routes");
|
|
1382
|
-
await
|
|
1383
|
-
for (const { locale:
|
|
1392
|
+
await G(S, { recursive: !0 });
|
|
1393
|
+
for (const { locale: c, slug: d, page: f } of u)
|
|
1384
1394
|
await re(f, R, {
|
|
1385
|
-
getFilename: () => `${pe(d) || "index"}.${
|
|
1395
|
+
getFilename: () => `${pe(d) || "index"}.${c}.yml`,
|
|
1386
1396
|
exportAssets: e,
|
|
1387
1397
|
useWorker: !0
|
|
1388
1398
|
});
|
|
1389
|
-
for (const
|
|
1390
|
-
await re(
|
|
1399
|
+
for (const c of m)
|
|
1400
|
+
await re(c, S, {
|
|
1391
1401
|
// getFilename: () => `${sanitizeSlug(route.path)}.yml`,
|
|
1392
|
-
getFilename: () => `${pe(
|
|
1402
|
+
getFilename: () => `${pe(c.path) || "index"}.yml`,
|
|
1393
1403
|
exportAssets: e
|
|
1394
1404
|
});
|
|
1395
|
-
for (const
|
|
1396
|
-
const d = t.components[
|
|
1405
|
+
for (const c of l) {
|
|
1406
|
+
const d = t.components[c]?.data;
|
|
1397
1407
|
d && await re(d, j, {
|
|
1398
1408
|
getFilename: (f) => `${f.name || "unnamed"}.${f.id}.yml`,
|
|
1399
1409
|
exportAssets: e
|
|
1400
1410
|
});
|
|
1401
1411
|
}
|
|
1402
1412
|
const k = A(I, ".blocklet/pages/pages.config.yml");
|
|
1403
|
-
await
|
|
1413
|
+
await G(M(k), { recursive: !0 });
|
|
1404
1414
|
const g = {
|
|
1405
1415
|
pages: L(
|
|
1406
|
-
n.map((
|
|
1407
|
-
const d = t.pages[
|
|
1408
|
-
return d && { id:
|
|
1416
|
+
n.map((c) => {
|
|
1417
|
+
const d = t.pages[c];
|
|
1418
|
+
return d && { id: c, slug: d.slug };
|
|
1409
1419
|
})
|
|
1410
1420
|
),
|
|
1411
1421
|
routes: L(
|
|
1412
|
-
h.map((
|
|
1413
|
-
const d = t.routes[
|
|
1414
|
-
return d && { id:
|
|
1422
|
+
h.map((c) => {
|
|
1423
|
+
const d = t.routes[c];
|
|
1424
|
+
return d && { id: c, path: d.path };
|
|
1415
1425
|
})
|
|
1416
1426
|
),
|
|
1417
1427
|
components: L(
|
|
1418
|
-
l.map((
|
|
1419
|
-
const d = t.components[
|
|
1428
|
+
l.map((c) => {
|
|
1429
|
+
const d = t.components[c]?.data;
|
|
1420
1430
|
return d && {
|
|
1421
|
-
id:
|
|
1431
|
+
id: c,
|
|
1422
1432
|
name: d.name
|
|
1423
1433
|
};
|
|
1424
1434
|
})
|
|
@@ -1426,9 +1436,9 @@ async function ys(t, {
|
|
|
1426
1436
|
...r ? {
|
|
1427
1437
|
resources: {
|
|
1428
1438
|
components: L(
|
|
1429
|
-
Object.keys(t.resources?.components || {}).filter((
|
|
1430
|
-
id:
|
|
1431
|
-
name: t.resources?.components?.[
|
|
1439
|
+
Object.keys(t.resources?.components || {}).filter((c) => l.includes(c)).map((c) => ({
|
|
1440
|
+
id: c,
|
|
1441
|
+
name: t.resources?.components?.[c]?.component?.name
|
|
1432
1442
|
}))
|
|
1433
1443
|
)
|
|
1434
1444
|
}
|
|
@@ -1439,8 +1449,8 @@ async function ys(t, {
|
|
|
1439
1449
|
await ie(k, q.stringify(g));
|
|
1440
1450
|
const y = A(I, "config.source.json");
|
|
1441
1451
|
if (o && await ie(y, JSON.stringify(o)), r) {
|
|
1442
|
-
const
|
|
1443
|
-
await
|
|
1452
|
+
const c = A(I, "resources"), d = A(c, "components");
|
|
1453
|
+
await G(d, { recursive: !0 });
|
|
1444
1454
|
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1445
1455
|
(T) => l.includes(T)
|
|
1446
1456
|
)) {
|
|
@@ -1451,8 +1461,8 @@ async function ys(t, {
|
|
|
1451
1461
|
});
|
|
1452
1462
|
}
|
|
1453
1463
|
const f = A(I, "chunks");
|
|
1454
|
-
await
|
|
1455
|
-
const C = await
|
|
1464
|
+
await G(f, { recursive: !0 });
|
|
1465
|
+
const C = await ws();
|
|
1456
1466
|
for (const N of Object.keys(t?.resources?.components ?? {}).filter(
|
|
1457
1467
|
(T) => l.includes(T)
|
|
1458
1468
|
)) {
|
|
@@ -1460,12 +1470,12 @@ async function ys(t, {
|
|
|
1460
1470
|
if (T && T.renderer?.type === "react-component") {
|
|
1461
1471
|
const V = T.renderer?.chunks ?? [];
|
|
1462
1472
|
if (V?.length > 0)
|
|
1463
|
-
for (const
|
|
1464
|
-
const
|
|
1473
|
+
for (const H of V) {
|
|
1474
|
+
const Ue = A(f, H), de = C?.[H];
|
|
1465
1475
|
try {
|
|
1466
|
-
de && await
|
|
1467
|
-
} catch (
|
|
1468
|
-
p.error(`copy chunk ${
|
|
1476
|
+
de && await F(de) && !await F(Ue) && await Dt(de, Ue);
|
|
1477
|
+
} catch (it) {
|
|
1478
|
+
p.error(`copy chunk ${H} error`, it.message);
|
|
1469
1479
|
}
|
|
1470
1480
|
}
|
|
1471
1481
|
}
|
|
@@ -1473,36 +1483,36 @@ async function ys(t, {
|
|
|
1473
1483
|
}
|
|
1474
1484
|
return I;
|
|
1475
1485
|
}
|
|
1476
|
-
async function
|
|
1477
|
-
if (!await
|
|
1486
|
+
async function tt(t, { importAssets: e, includeResources: s } = {}) {
|
|
1487
|
+
if (!await F(t))
|
|
1478
1488
|
return null;
|
|
1479
1489
|
let a, o = !1;
|
|
1480
1490
|
try {
|
|
1481
|
-
(await ne(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a =
|
|
1482
|
-
const n = (await
|
|
1491
|
+
(await ne(t)).isDirectory() ? a = t : /\.(tgz|gz|tar)$/.test(t) && (o = !0, a = Ze(), await $t({ file: t, C: a }));
|
|
1492
|
+
const n = (await we("**/.blocklet/pages/pages.config.yml", { cwd: a, absolute: !0 }))[0], l = n && A(M(n), "../../pages"), h = n && A(M(n), "../../components"), b = n && A(M(n), "../../routes");
|
|
1483
1493
|
if (!n)
|
|
1484
1494
|
return null;
|
|
1485
|
-
const O = await ae(n, "utf-8"), w = q.parse(O), m = async (g, y,
|
|
1486
|
-
let d = A(g, `${y}${
|
|
1487
|
-
if (!await
|
|
1495
|
+
const O = await ae(n, "utf-8"), w = q.parse(O), m = async (g, y, c) => {
|
|
1496
|
+
let d = A(g, `${y}${c ? `.${c}` : ""}.yml`);
|
|
1497
|
+
if (!await F(d) && (d = A(g, y, `index${c ? `.${c}` : ""}.yml`), !await F(d)) || !(await ne(d)).isFile())
|
|
1488
1498
|
return null;
|
|
1489
1499
|
const C = await ae(d, "utf-8");
|
|
1490
1500
|
return q.parse(C);
|
|
1491
1501
|
}, u = async (g, y) => {
|
|
1492
1502
|
try {
|
|
1493
|
-
const d = (await
|
|
1503
|
+
const d = (await we(`*.${y}.yml`, { cwd: g, absolute: !0 }))[0];
|
|
1494
1504
|
if (!d) return null;
|
|
1495
1505
|
const f = await ae(d, "utf-8");
|
|
1496
1506
|
return q.parse(f);
|
|
1497
|
-
} catch (
|
|
1498
|
-
p.error("parse component error",
|
|
1507
|
+
} catch (c) {
|
|
1508
|
+
p.error("parse component error", c);
|
|
1499
1509
|
}
|
|
1500
1510
|
return null;
|
|
1501
1511
|
}, I = async (g, y) => {
|
|
1502
|
-
let
|
|
1503
|
-
if (!await
|
|
1512
|
+
let c = A(g, `${y}.yml`);
|
|
1513
|
+
if (!await F(c) && (c = A(g, y, "index.yml"), !await F(c)) || !(await ne(c)).isFile())
|
|
1504
1514
|
return null;
|
|
1505
|
-
const f = await ae(
|
|
1515
|
+
const f = await ae(c, "utf-8");
|
|
1506
1516
|
return q.parse(f);
|
|
1507
1517
|
}, R = L(
|
|
1508
1518
|
await Promise.all(
|
|
@@ -1517,22 +1527,22 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1517
1527
|
return N && { locale: f, page: N };
|
|
1518
1528
|
})
|
|
1519
1529
|
)
|
|
1520
|
-
),
|
|
1521
|
-
if (!
|
|
1530
|
+
), c = y[0]?.page;
|
|
1531
|
+
if (!c)
|
|
1522
1532
|
return null;
|
|
1523
|
-
const d =
|
|
1533
|
+
const d = c.sections.map(At);
|
|
1524
1534
|
return {
|
|
1525
|
-
id:
|
|
1526
|
-
createdAt:
|
|
1527
|
-
updatedAt:
|
|
1528
|
-
publishedAt:
|
|
1529
|
-
isPublic:
|
|
1530
|
-
templateConfig:
|
|
1535
|
+
id: c.id || Me(),
|
|
1536
|
+
createdAt: c.createdAt,
|
|
1537
|
+
updatedAt: c.updatedAt,
|
|
1538
|
+
publishedAt: c.publishedAt,
|
|
1539
|
+
isPublic: c.isPublic ?? !0,
|
|
1540
|
+
templateConfig: c.templateConfig,
|
|
1531
1541
|
slug: g,
|
|
1532
1542
|
sections: Object.fromEntries(d.map((f) => [f.id, f])),
|
|
1533
1543
|
sectionIds: d.map((f) => f.id),
|
|
1534
1544
|
locales: Object.fromEntries(y.map(({ locale: f, page: C }) => [f, C.meta])),
|
|
1535
|
-
dataSource:
|
|
1545
|
+
dataSource: c.dataSource ? Object.fromEntries(
|
|
1536
1546
|
// 获取 dataSource 中所有 section ID
|
|
1537
1547
|
[...new Set(y.flatMap(({ page: f }) => Object.keys(f.dataSource ?? {})))].map((f) => [
|
|
1538
1548
|
f,
|
|
@@ -1552,7 +1562,7 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1552
1562
|
const T = N.dataSource?.[f];
|
|
1553
1563
|
if (T)
|
|
1554
1564
|
return [C, T];
|
|
1555
|
-
const V = N.sections.find((
|
|
1565
|
+
const V = N.sections.find((H) => H.id === f);
|
|
1556
1566
|
return [C, V?.properties || {}];
|
|
1557
1567
|
})
|
|
1558
1568
|
)
|
|
@@ -1564,10 +1574,10 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1564
1574
|
), j = L(
|
|
1565
1575
|
await Promise.all(
|
|
1566
1576
|
(w?.routes || []).map(async ({ path: g }) => {
|
|
1567
|
-
const y =
|
|
1577
|
+
const y = b ? await I(b, pe(g)) : void 0;
|
|
1568
1578
|
return {
|
|
1569
1579
|
...y,
|
|
1570
|
-
id: y?.id ||
|
|
1580
|
+
id: y?.id || Me(),
|
|
1571
1581
|
createdAt: y?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1572
1582
|
updatedAt: y?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1573
1583
|
publishedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -1589,28 +1599,28 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1589
1599
|
p.info(`[${o ? $(t) : $(A(t, "../../../../"))}] importAssets:`, ...y);
|
|
1590
1600
|
};
|
|
1591
1601
|
try {
|
|
1592
|
-
g("wait image-bin api ready"), await
|
|
1593
|
-
resources: [`${
|
|
1602
|
+
g("wait image-bin api ready"), await Ut({
|
|
1603
|
+
resources: [`${jt(pt)}/api/sdk/uploads`],
|
|
1594
1604
|
validateStatus: (d) => d >= 200 && d <= 500
|
|
1595
1605
|
}), g("image-bin api is ready");
|
|
1596
|
-
const y = {},
|
|
1606
|
+
const y = {}, c = {};
|
|
1597
1607
|
g("start to upload assets"), await Promise.allSettled([
|
|
1598
|
-
|
|
1608
|
+
qe(S, y, {
|
|
1599
1609
|
getFilePath: (d) => h && A(h, d),
|
|
1600
1610
|
onFinish: (d) => {
|
|
1601
1611
|
g(`upload ${d.length} component assets`);
|
|
1602
1612
|
}
|
|
1603
1613
|
}),
|
|
1604
|
-
|
|
1614
|
+
qe(R, c, {
|
|
1605
1615
|
getFilePath: (d, f) => {
|
|
1606
|
-
const C =
|
|
1616
|
+
const C = ve(R, f.slice(0, 1));
|
|
1607
1617
|
return l && A(l, M(C.slug), d);
|
|
1608
1618
|
},
|
|
1609
1619
|
onFinish: (d) => {
|
|
1610
1620
|
g(`upload ${d.length} page assets`);
|
|
1611
1621
|
}
|
|
1612
1622
|
})
|
|
1613
|
-
]), g("upload assets done"),
|
|
1623
|
+
]), g("upload assets done"), Ae.clear(), global.gc && global.gc();
|
|
1614
1624
|
} catch (y) {
|
|
1615
1625
|
g("Error during asset import:", y);
|
|
1616
1626
|
}
|
|
@@ -1619,11 +1629,11 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1619
1629
|
if (s) {
|
|
1620
1630
|
const g = n && A(M(n), "../../resources/components"), y = L(
|
|
1621
1631
|
await Promise.all(
|
|
1622
|
-
(w.resources?.components || []).map(async ({ id:
|
|
1632
|
+
(w.resources?.components || []).map(async ({ id: c }) => u(g, c))
|
|
1623
1633
|
)
|
|
1624
1634
|
);
|
|
1625
1635
|
y.length > 0 && (k.components = Object.fromEntries(
|
|
1626
|
-
y.map((
|
|
1636
|
+
y.map((c, d) => [c.id, { index: d, component: c }])
|
|
1627
1637
|
));
|
|
1628
1638
|
}
|
|
1629
1639
|
return {
|
|
@@ -1639,27 +1649,27 @@ async function Ze(t, { importAssets: e, includeResources: s } = {}) {
|
|
|
1639
1649
|
dataSources: {}
|
|
1640
1650
|
};
|
|
1641
1651
|
} finally {
|
|
1642
|
-
o && a && await
|
|
1652
|
+
o && a && await Se(a, { force: !0, recursive: !0 });
|
|
1643
1653
|
}
|
|
1644
1654
|
}
|
|
1645
|
-
async function
|
|
1655
|
+
async function We(t, e, {
|
|
1646
1656
|
routes: s,
|
|
1647
1657
|
mergeMode: a = "byUpdateTime",
|
|
1648
1658
|
deleteRoutes: o = !1,
|
|
1649
1659
|
publishMode: r = void 0
|
|
1650
1660
|
} = {}) {
|
|
1651
1661
|
try {
|
|
1652
|
-
r &&
|
|
1662
|
+
r && ut(r);
|
|
1653
1663
|
} catch (w) {
|
|
1654
1664
|
p.error("clear preload page cache error", { error: w });
|
|
1655
1665
|
}
|
|
1656
|
-
const { pages:
|
|
1666
|
+
const { pages: i, pageIds: n, routeIds: l, routes: h, supportedLocales: b } = t;
|
|
1657
1667
|
if (r === "production") {
|
|
1658
1668
|
let w = s ?? [], m = null;
|
|
1659
1669
|
for (const u of l ?? []) {
|
|
1660
1670
|
const I = h?.[u];
|
|
1661
1671
|
if (I?.params && I?.params.length > 0 && I?.paramsOptions && I?.paramsOptions.length > 0) {
|
|
1662
|
-
const R =
|
|
1672
|
+
const R = je({
|
|
1663
1673
|
basePath: I.path,
|
|
1664
1674
|
params: I.params,
|
|
1665
1675
|
routeId: I.id,
|
|
@@ -1697,7 +1707,7 @@ async function Ve(t, e, {
|
|
|
1697
1707
|
p.info("no display template", u);
|
|
1698
1708
|
continue;
|
|
1699
1709
|
}
|
|
1700
|
-
const j =
|
|
1710
|
+
const j = i[R.displayTemplateId];
|
|
1701
1711
|
if (!j) {
|
|
1702
1712
|
p.info("no template page", u);
|
|
1703
1713
|
continue;
|
|
@@ -1735,7 +1745,7 @@ async function Ve(t, e, {
|
|
|
1735
1745
|
w?.includes(u) || (delete e.pages[u], p.info("delete page", u)), e.pageIds = [...e.pageIds].filter((I) => w?.includes(I));
|
|
1736
1746
|
} else {
|
|
1737
1747
|
for (const w of n) {
|
|
1738
|
-
const m =
|
|
1748
|
+
const m = i[w];
|
|
1739
1749
|
if (m)
|
|
1740
1750
|
if (e.pageIds.includes(m.id)) {
|
|
1741
1751
|
if (a === "replace")
|
|
@@ -1761,14 +1771,14 @@ async function Ve(t, e, {
|
|
|
1761
1771
|
e.routeIds.push(m.id), e.routes[m.id] = m;
|
|
1762
1772
|
}
|
|
1763
1773
|
}
|
|
1764
|
-
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...
|
|
1774
|
+
if (e.supportedLocales.splice(0, e.supportedLocales.length), e.supportedLocales.push(...Oe(b)), o)
|
|
1765
1775
|
for (const w of Object.keys(e.components))
|
|
1766
1776
|
delete e.components[w];
|
|
1767
1777
|
let O = JSON.parse(JSON.stringify(t.components));
|
|
1768
1778
|
O = Object.fromEntries(
|
|
1769
1779
|
await Promise.all(
|
|
1770
1780
|
Object.entries(O).map(async ([w, m]) => {
|
|
1771
|
-
const u = await
|
|
1781
|
+
const u = await st(m?.data);
|
|
1772
1782
|
return [
|
|
1773
1783
|
w,
|
|
1774
1784
|
{
|
|
@@ -1778,17 +1788,17 @@ async function Ve(t, e, {
|
|
|
1778
1788
|
];
|
|
1779
1789
|
})
|
|
1780
1790
|
)
|
|
1781
|
-
), Object.assign(e.components, O), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))),
|
|
1791
|
+
), Object.assign(e.components, O), Object.assign(e.config, JSON.parse(JSON.stringify(t.config))), Te(t.resources.components) || (e.resources.components = JSON.parse(JSON.stringify(t.resources.components || {})));
|
|
1782
1792
|
}
|
|
1783
|
-
const
|
|
1793
|
+
const st = ct(
|
|
1784
1794
|
async (t) => {
|
|
1785
|
-
if (!
|
|
1795
|
+
if (!Te(t?.properties))
|
|
1786
1796
|
return t;
|
|
1787
1797
|
if (t?.renderer?.type === "react-component") {
|
|
1788
1798
|
const { script: e, PROPERTIES_SCHEMA: s } = t?.renderer || {};
|
|
1789
1799
|
if (s || e && e.includes("PROPERTIES_SCHEMA"))
|
|
1790
1800
|
try {
|
|
1791
|
-
const a = await
|
|
1801
|
+
const a = await lt(
|
|
1792
1802
|
e ?? "",
|
|
1793
1803
|
"PROPERTIES_SCHEMA",
|
|
1794
1804
|
t.id,
|
|
@@ -1810,36 +1820,36 @@ const et = it(
|
|
|
1810
1820
|
subdir: "getPropertiesFromCode"
|
|
1811
1821
|
}
|
|
1812
1822
|
);
|
|
1813
|
-
let ue,
|
|
1814
|
-
const
|
|
1823
|
+
let ue, ee, J, K;
|
|
1824
|
+
const at = () => Ot({
|
|
1815
1825
|
types: [
|
|
1816
|
-
{ did:
|
|
1817
|
-
{ did:
|
|
1826
|
+
{ did: Ye, type: Ge },
|
|
1827
|
+
{ did: qt, type: Ge }
|
|
1818
1828
|
]
|
|
1819
|
-
}),
|
|
1820
|
-
const t =
|
|
1829
|
+
}), ws = async () => {
|
|
1830
|
+
const t = at(), e = {};
|
|
1821
1831
|
for (const s of t) {
|
|
1822
|
-
const o = (await
|
|
1832
|
+
const o = (await we("**/.blocklet/pages/pages.config.yml", {
|
|
1823
1833
|
cwd: s.path,
|
|
1824
1834
|
absolute: !0
|
|
1825
1835
|
}))[0], r = o && A(M(o), "../../chunks");
|
|
1826
|
-
if (r && await
|
|
1827
|
-
const
|
|
1828
|
-
for (const n of
|
|
1836
|
+
if (r && await F(r)) {
|
|
1837
|
+
const i = await kt(r);
|
|
1838
|
+
for (const n of i)
|
|
1829
1839
|
e[n] = A(r, n);
|
|
1830
1840
|
}
|
|
1831
1841
|
}
|
|
1832
1842
|
return e;
|
|
1833
1843
|
};
|
|
1834
|
-
function
|
|
1844
|
+
function ot() {
|
|
1835
1845
|
return ue = (async () => {
|
|
1836
|
-
const t =
|
|
1837
|
-
|
|
1846
|
+
const t = at();
|
|
1847
|
+
ee = (await Promise.all(
|
|
1838
1848
|
t.map(async (s) => {
|
|
1839
|
-
const a = s.path ? await
|
|
1849
|
+
const a = s.path ? await tt(s.path, { importAssets: !1 }) : void 0;
|
|
1840
1850
|
return a ? { blockletId: s.did, state: a, blockletTitle: s.title } : void 0;
|
|
1841
1851
|
})
|
|
1842
|
-
)).filter((s) => !!s),
|
|
1852
|
+
)).filter((s) => !!s), J = ee.reduce(
|
|
1843
1853
|
(s, a) => Object.assign(
|
|
1844
1854
|
s,
|
|
1845
1855
|
Object.fromEntries(
|
|
@@ -1848,7 +1858,7 @@ function st() {
|
|
|
1848
1858
|
),
|
|
1849
1859
|
{}
|
|
1850
1860
|
);
|
|
1851
|
-
const e =
|
|
1861
|
+
const e = ee.reduce(
|
|
1852
1862
|
(s, a) => Object.assign(
|
|
1853
1863
|
s,
|
|
1854
1864
|
Object.fromEntries(
|
|
@@ -1857,10 +1867,10 @@ function st() {
|
|
|
1857
1867
|
),
|
|
1858
1868
|
{}
|
|
1859
1869
|
);
|
|
1860
|
-
|
|
1870
|
+
K = Object.fromEntries(
|
|
1861
1871
|
await Promise.all(
|
|
1862
1872
|
Object.entries(e).map(async ([s, a]) => {
|
|
1863
|
-
const o = await
|
|
1873
|
+
const o = await st(a.component);
|
|
1864
1874
|
return [
|
|
1865
1875
|
s,
|
|
1866
1876
|
{
|
|
@@ -1871,35 +1881,35 @@ function st() {
|
|
|
1871
1881
|
})
|
|
1872
1882
|
)
|
|
1873
1883
|
), p.info(
|
|
1874
|
-
`reloadResourceStates success: ${Object.keys(
|
|
1884
|
+
`reloadResourceStates success: ${Object.keys(K || {}).length} components, ${Object.keys(J || {}).length} pages`
|
|
1875
1885
|
);
|
|
1876
1886
|
})(), ue;
|
|
1877
1887
|
}
|
|
1878
|
-
function
|
|
1879
|
-
const e =
|
|
1888
|
+
function Is(t) {
|
|
1889
|
+
const e = ke(
|
|
1880
1890
|
async () => {
|
|
1881
|
-
await
|
|
1891
|
+
await ot().catch((s) => {
|
|
1882
1892
|
p.error("load resource states error", { error: s });
|
|
1883
1893
|
}), await t?.({
|
|
1884
|
-
states:
|
|
1885
|
-
pages:
|
|
1886
|
-
components:
|
|
1894
|
+
states: ee,
|
|
1895
|
+
pages: J,
|
|
1896
|
+
components: K
|
|
1887
1897
|
});
|
|
1888
1898
|
},
|
|
1889
1899
|
3e3,
|
|
1890
1900
|
// 3s
|
|
1891
1901
|
{ leading: !1, trailing: !0 }
|
|
1892
1902
|
);
|
|
1893
|
-
return 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(
|
|
1894
|
-
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(
|
|
1903
|
+
return 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(Pe, e), e(), () => {
|
|
1904
|
+
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(Pe, e);
|
|
1895
1905
|
};
|
|
1896
1906
|
}
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
|
|
1907
|
+
const rt = Symbol.for("GLOBAL_RESOURCE_STATES_LISTENER_KEY"), nt = globalThis;
|
|
1908
|
+
nt[rt]?.();
|
|
1909
|
+
nt[rt] = Is(async ({ pages: t, components: e }) => {
|
|
1900
1910
|
const s = await D.getProjectIds();
|
|
1901
1911
|
p.info(`start update resource states projects(${s.length})`, s);
|
|
1902
|
-
const a =
|
|
1912
|
+
const a = De(10);
|
|
1903
1913
|
await Promise.race([
|
|
1904
1914
|
new Promise((o) => {
|
|
1905
1915
|
setTimeout(() => {
|
|
@@ -1909,7 +1919,7 @@ ot[at] = ws(async ({ pages: t, components: e }) => {
|
|
|
1909
1919
|
Promise.all(
|
|
1910
1920
|
s.map(
|
|
1911
1921
|
(o) => a(async () => {
|
|
1912
|
-
|
|
1922
|
+
Ee({
|
|
1913
1923
|
projectId: o,
|
|
1914
1924
|
pages: t,
|
|
1915
1925
|
components: e
|
|
@@ -1931,7 +1941,7 @@ process.on("SIGINT", () => {
|
|
|
1931
1941
|
process.on("SIGTERM", () => {
|
|
1932
1942
|
D.stopPeriodicCheck(), process.exit(0);
|
|
1933
1943
|
});
|
|
1934
|
-
async function
|
|
1944
|
+
async function Ee({
|
|
1935
1945
|
projectId: t,
|
|
1936
1946
|
pages: e,
|
|
1937
1947
|
components: s
|
|
@@ -1948,7 +1958,7 @@ async function rt({
|
|
|
1948
1958
|
if (o?.useAllResources)
|
|
1949
1959
|
r = s;
|
|
1950
1960
|
else {
|
|
1951
|
-
const n = (await
|
|
1961
|
+
const n = (await Le.findAll({ where: { projectId: t } })).map((l) => l.componentId);
|
|
1952
1962
|
r = Object.fromEntries(Object.entries(s || {}).filter(([l]) => n.includes(l)));
|
|
1953
1963
|
}
|
|
1954
1964
|
a.transact(() => {
|
|
@@ -1959,42 +1969,48 @@ async function rt({
|
|
|
1959
1969
|
});
|
|
1960
1970
|
}
|
|
1961
1971
|
const he = /* @__PURE__ */ new Map();
|
|
1962
|
-
async function
|
|
1972
|
+
async function Ps(t, { immediate: e = !1 } = {}) {
|
|
1973
|
+
if (e)
|
|
1974
|
+
return Ee({
|
|
1975
|
+
projectId: t,
|
|
1976
|
+
pages: J,
|
|
1977
|
+
components: K
|
|
1978
|
+
});
|
|
1963
1979
|
if (!he.has(t)) {
|
|
1964
|
-
const
|
|
1965
|
-
projectId:
|
|
1966
|
-
pages:
|
|
1967
|
-
components:
|
|
1980
|
+
const s = ke(async (a) => Ee({
|
|
1981
|
+
projectId: a,
|
|
1982
|
+
pages: J,
|
|
1983
|
+
components: K
|
|
1968
1984
|
}), 3e3);
|
|
1969
|
-
he.set(t,
|
|
1985
|
+
he.set(t, s);
|
|
1970
1986
|
}
|
|
1971
1987
|
return he.get(t)(t);
|
|
1972
1988
|
}
|
|
1973
|
-
async function
|
|
1974
|
-
p.info("trigger reload all project resource"), E.events.emit(
|
|
1989
|
+
async function ia() {
|
|
1990
|
+
p.info("trigger reload all project resource"), E.events.emit(Pe);
|
|
1975
1991
|
}
|
|
1976
|
-
async function
|
|
1992
|
+
async function ca({
|
|
1977
1993
|
ensureLoaded: t = !0
|
|
1978
1994
|
} = {}) {
|
|
1979
|
-
return t && (ue ??=
|
|
1995
|
+
return t && (ue ??= ot(), await ue), { states: ee, pages: J, components: K };
|
|
1980
1996
|
}
|
|
1981
1997
|
export {
|
|
1982
|
-
|
|
1998
|
+
Ye as C,
|
|
1983
1999
|
U as P,
|
|
1984
|
-
|
|
2000
|
+
Ge as R,
|
|
1985
2001
|
D as S,
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2002
|
+
X as a,
|
|
2003
|
+
ra as b,
|
|
2004
|
+
oa as c,
|
|
2005
|
+
na as d,
|
|
2006
|
+
ms as e,
|
|
2007
|
+
hs as f,
|
|
2008
|
+
ca as g,
|
|
2009
|
+
ys as h,
|
|
2010
|
+
tt as i,
|
|
2011
|
+
Is as j,
|
|
2012
|
+
ia as k,
|
|
2013
|
+
We as m,
|
|
2014
|
+
Ss as t,
|
|
2015
|
+
Ps as u
|
|
2000
2016
|
};
|