@blocklet/pages-kit-inner-components 0.6.2 → 0.6.4
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 +420 -1
- package/lib/cjs/chunks/draft-data-D44_IEV2.js +1 -0
- package/lib/cjs/chunks/home-BYk01EUy.js +39 -0
- package/lib/cjs/chunks/index-BRgYwvuv.js +475 -0
- package/lib/cjs/chunks/publish-button-C8XPA4g_.js +1 -0
- package/lib/cjs/chunks/session-BRtsDvA-.js +1 -0
- package/lib/cjs/chunks/site-state-BlQzwACl.js +57 -0
- package/lib/cjs/chunks/state-B6BF5wJ-.js +1 -0
- package/lib/cjs/components.js +1 -0
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/locales.js +3 -0
- package/lib/cjs/project-html.js +4 -4
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +11 -0
- package/lib/cjs/site-state.js +1 -0
- package/lib/cjs/theme.js +1 -0
- package/lib/cjs/uploader.js +1 -0
- package/lib/es/add-component.js +1089 -2
- package/lib/es/chunks/{draft-data-bRUHvvzp.js → draft-data-CafrGKeh.js} +4 -5
- package/lib/es/chunks/home-DW8SdyfO.js +594 -0
- package/lib/es/chunks/index-D5gXPe_7.js +2326 -0
- package/lib/es/chunks/{publish-button-Ceet-m88.js → publish-button-XSZrDaTQ.js} +140 -158
- package/lib/es/chunks/session-C72Dq8zg.js +19 -0
- package/lib/es/chunks/{site-state-Bh8guIeX.js → site-state-BdLTu3Od.js} +201 -170
- package/lib/es/chunks/state-0gvZF3k2.js +573 -0
- package/lib/es/components.js +24 -0
- package/lib/es/home.js +28 -3
- package/lib/es/locales.js +1032 -0
- package/lib/es/project-html.js +155 -79
- package/lib/es/resources.js +137 -93
- package/lib/es/setting.js +2294 -0
- package/lib/es/site-state.js +48 -0
- package/lib/es/theme.js +484 -0
- package/lib/es/uploader.js +8 -0
- package/package.json +3 -3
- package/lib/cjs/chunks/draft-data-CfIMszE7.js +0 -1
- package/lib/cjs/chunks/home-DUjl5PbP.js +0 -6
- package/lib/cjs/chunks/publish-button-C522nNv6.js +0 -1
- package/lib/cjs/chunks/site-state-DDXqWF74.js +0 -57
- package/lib/cjs/chunks/state-CtNs8GrN.js +0 -1
- package/lib/es/chunks/home-VWWdvIPQ.js +0 -69
- package/lib/es/chunks/state-BdNIIXJP.js +0 -502
package/lib/es/project-html.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import r, { getBlockletJs as
|
|
1
|
+
import L from "@arcblock/did-auth-storage-nedb";
|
|
2
|
+
import r, { getBlockletJs as B } from "@blocklet/sdk/lib/config";
|
|
3
3
|
import H from "@blocklet/sdk/lib/service/auth";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { l as _,
|
|
9
|
-
import { createHash as
|
|
10
|
-
import { createSnapshotMiddleware as
|
|
11
|
-
import { PreloadComponentScriptModule as
|
|
12
|
-
import { isMuiColorKey as
|
|
13
|
-
import { injectPreloadComponents as
|
|
14
|
-
import { getComponentMountPoint as
|
|
15
|
-
import { Router as
|
|
16
|
-
import { readFileSync as
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import { withQuery as
|
|
4
|
+
import W from "@blocklet/sdk/lib/wallet";
|
|
5
|
+
import D from "@blocklet/sdk/lib/wallet-authenticator";
|
|
6
|
+
import N from "@blocklet/sdk/lib/wallet-handler";
|
|
7
|
+
import U, { resolve as T } from "path";
|
|
8
|
+
import { l as _, g as O } from "./chunks/site-state-BdLTu3Od.js";
|
|
9
|
+
import { createHash as R } from "crypto";
|
|
10
|
+
import { createSnapshotMiddleware as F } from "@arcblock/crawler-middleware";
|
|
11
|
+
import { PreloadComponentScriptModule as J } from "@blocklet/pages-kit/types";
|
|
12
|
+
import { isMuiColorKey as z } from "@blocklet/pages-kit/utils/common";
|
|
13
|
+
import { injectPreloadComponents as G, safeJSONStringify as Y } from "@blocklet/pages-kit/utils/preload";
|
|
14
|
+
import { getComponentMountPoint as Q } from "@blocklet/sdk/lib/component";
|
|
15
|
+
import { Router as V } from "express";
|
|
16
|
+
import { readFileSync as j } from "fs";
|
|
17
|
+
import X from "lodash/get";
|
|
18
|
+
import Z from "mustache";
|
|
19
|
+
import { withQuery as q, joinURL as P } from "ufo";
|
|
20
20
|
const ee = (o = {}) => {
|
|
21
21
|
const e = {
|
|
22
22
|
data: /* @__PURE__ */ new Map(),
|
|
23
23
|
timers: /* @__PURE__ */ new Map(),
|
|
24
|
-
set: (t,
|
|
24
|
+
set: (t, s, i = o.ttl || 36e5) => {
|
|
25
25
|
o.max && e.data.size >= o.max && e.delete(e.data.keys().next().value), e.timers.has(t) && clearTimeout(e.timers.get(t)), e.timers.set(
|
|
26
26
|
t,
|
|
27
|
-
setTimeout(() => e.delete(t),
|
|
28
|
-
), e.data.set(t,
|
|
27
|
+
setTimeout(() => e.delete(t), i)
|
|
28
|
+
), e.data.set(t, s);
|
|
29
29
|
},
|
|
30
30
|
get: (t) => e.data.get(t),
|
|
31
31
|
has: (t) => e.data.has(t),
|
|
@@ -43,12 +43,12 @@ const ee = (o = {}) => {
|
|
|
43
43
|
ttl: 1e3 * 30
|
|
44
44
|
// 30 seconds
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
const te = new
|
|
48
|
-
new
|
|
46
|
+
W();
|
|
47
|
+
const te = new D();
|
|
48
|
+
new N({
|
|
49
49
|
authenticator: te,
|
|
50
|
-
tokenStorage: new
|
|
51
|
-
dbPath:
|
|
50
|
+
tokenStorage: new L({
|
|
51
|
+
dbPath: U.join(r.env.dataDir, "auth.db")
|
|
52
52
|
})
|
|
53
53
|
});
|
|
54
54
|
const oe = new H(), ne = async () => {
|
|
@@ -62,93 +62,143 @@ const oe = new H(), ne = async () => {
|
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
64
|
}, re = async () => await import("cheerio"), C = {};
|
|
65
|
-
function
|
|
65
|
+
function ce(o, e) {
|
|
66
66
|
const t = JSON.stringify([o, e]);
|
|
67
|
-
return
|
|
67
|
+
return R("md5").update(t).digest("hex");
|
|
68
68
|
}
|
|
69
|
-
async function
|
|
69
|
+
async function se(o, e) {
|
|
70
70
|
{
|
|
71
|
-
const
|
|
72
|
-
return e.forEach((
|
|
73
|
-
i
|
|
74
|
-
}),
|
|
71
|
+
const s = (await re()).load(o);
|
|
72
|
+
return e.forEach((i) => {
|
|
73
|
+
s(i.selector.cheerio).replaceWith(i.value);
|
|
74
|
+
}), s.html();
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
async function
|
|
77
|
+
async function ie(o, e) {
|
|
78
78
|
if (!e || e.length === 0)
|
|
79
79
|
return o;
|
|
80
|
-
const t =
|
|
81
|
-
return C[t] ??=
|
|
80
|
+
const t = ce(o, e);
|
|
81
|
+
return C[t] ??= se(o, e).finally(() => {
|
|
82
82
|
setTimeout(() => {
|
|
83
83
|
delete C[t];
|
|
84
84
|
}, 2 * 1e3);
|
|
85
85
|
}), C[t];
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function ae(o) {
|
|
88
88
|
return o.match(/<body[^>]*>(.*?)<\/body>/s)?.[1] || "";
|
|
89
89
|
}
|
|
90
90
|
const le = ["/assets/"];
|
|
91
|
-
function
|
|
92
|
-
|
|
91
|
+
function $e({
|
|
92
|
+
app: o,
|
|
93
|
+
viteDevServer: e,
|
|
94
|
+
// projectId,
|
|
95
|
+
state: t
|
|
96
|
+
}) {
|
|
97
|
+
let s;
|
|
93
98
|
if (e) {
|
|
94
|
-
const n =
|
|
95
|
-
o.use(async (u,
|
|
99
|
+
const n = j(T(process.cwd(), "./index.html"), "utf-8");
|
|
100
|
+
o.use(async (u, b, v) => {
|
|
96
101
|
const S = u.originalUrl;
|
|
97
|
-
|
|
102
|
+
s = await e.transformIndexHtml(S, n), v();
|
|
98
103
|
});
|
|
99
|
-
} else
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
} else
|
|
105
|
+
s = j(T(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
106
|
+
const i = V();
|
|
107
|
+
i.use((n, u, b) => {
|
|
102
108
|
if (n.headers["x-unique-record"] === "dial_http") {
|
|
103
109
|
_.info("[html] dial http request, return 200 status code"), u.status(200).send("ok");
|
|
104
110
|
return;
|
|
105
111
|
}
|
|
106
|
-
|
|
107
|
-
}), r.env.preferences.snapkitEnabled && r.env.preferences.snapkitEndpoint && r.env.SNAP_KIT_ACCESS_KEY &&
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
b();
|
|
113
|
+
}), r.env.preferences.snapkitEnabled && r.env.preferences.snapkitEndpoint && r.env.SNAP_KIT_ACCESS_KEY && i.use(
|
|
114
|
+
F({
|
|
115
|
+
endpoint: r.env.preferences.snapkitEndpoint,
|
|
116
|
+
accessKey: r.env.SNAP_KIT_ACCESS_KEY,
|
|
117
|
+
cacheMax: r.env.preferences.snapkitCacheSize || 100
|
|
118
|
+
})
|
|
119
|
+
), i.get("/:path(*)?", async (n, u, b) => {
|
|
120
|
+
if (le.some((c) => n.path?.startsWith(c))) {
|
|
121
|
+
b();
|
|
110
122
|
return;
|
|
111
123
|
}
|
|
112
|
-
const
|
|
113
|
-
let f,
|
|
124
|
+
const v = performance.now(), S = () => Math.round(performance.now() - v), A = "production";
|
|
125
|
+
let f, k, g = s;
|
|
114
126
|
if (n.path.startsWith("/pages")) {
|
|
115
|
-
const
|
|
116
|
-
let d = (
|
|
127
|
+
const c = n.params.lang, y = n.cookies.nf_lang, w = /* @__PURE__ */ new Set([...r.env.languages.map((h) => h.code)]);
|
|
128
|
+
let d = (c && w.has(c) ? c : void 0) || (w.has(y) ? y : void 0) || [...w][0];
|
|
117
129
|
if ((!d || !t.supportedLocales?.find((h) => h.locale === d)) && (d = t.supportedLocales?.[0]?.locale || ""), d) {
|
|
118
130
|
const h = [];
|
|
119
|
-
Object.values(t.pages).forEach((
|
|
120
|
-
const
|
|
121
|
-
|
|
131
|
+
Object.values(t.pages).forEach((a) => {
|
|
132
|
+
const K = Object.values(a?.sections ?? {}).filter(
|
|
133
|
+
(m) => m.component === "custom-component" && m.config?.componentId
|
|
134
|
+
).map((m) => ({
|
|
135
|
+
id: m.id,
|
|
136
|
+
componentId: m.config.componentId,
|
|
137
|
+
useCache: m.config.useCache,
|
|
138
|
+
cacheDuration: m.config.cacheDuration,
|
|
139
|
+
properties: a?.dataSource?.[m.id]?.[d]
|
|
140
|
+
// ?? i.locales?.[respectLocale!]?.properties,
|
|
141
|
+
}));
|
|
142
|
+
h.push(...K);
|
|
122
143
|
});
|
|
123
|
-
const M = new Promise((
|
|
144
|
+
const M = new Promise((a) => {
|
|
124
145
|
setTimeout(() => {
|
|
125
|
-
|
|
146
|
+
a({});
|
|
126
147
|
}, 30 * 1e3);
|
|
127
148
|
});
|
|
128
149
|
try {
|
|
129
|
-
await Promise.race([
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
await Promise.race([
|
|
151
|
+
M,
|
|
152
|
+
O({
|
|
153
|
+
mode: A,
|
|
154
|
+
req: n,
|
|
155
|
+
state: t,
|
|
156
|
+
locale: d,
|
|
157
|
+
instances: h,
|
|
158
|
+
module: J.UMD_FN
|
|
159
|
+
}).then((a) => {
|
|
160
|
+
a && (k = G(a));
|
|
161
|
+
})
|
|
162
|
+
]);
|
|
163
|
+
} catch (a) {
|
|
164
|
+
_.warn("getPreloadComponents timeout in promise race, skip inject html elements", a);
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
167
|
}
|
|
137
168
|
try {
|
|
138
|
-
const
|
|
139
|
-
|
|
169
|
+
const c = f?.title || r.env.appName, y = f?.description || r.env.appDescription, w = q(P(r.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
170
|
+
title: c,
|
|
171
|
+
description: y
|
|
172
|
+
});
|
|
173
|
+
g = Z.render(s, {
|
|
174
|
+
ogTitle: c,
|
|
175
|
+
ogDescription: y,
|
|
176
|
+
ogImage: me(f?.image) || w,
|
|
177
|
+
pagesPublishedAt: t?.config.publishedAt || (/* @__PURE__ */ new Date()).getTime()
|
|
178
|
+
});
|
|
140
179
|
} catch {
|
|
141
180
|
}
|
|
142
|
-
const
|
|
181
|
+
const p = t?.config.fontFamily, $ = n.query.mode === "draft" || n.url.includes("preview") || n.path?.startsWith("/admin");
|
|
143
182
|
let l = f?.backgroundColor;
|
|
144
|
-
if (l &&
|
|
145
|
-
const
|
|
146
|
-
l =
|
|
183
|
+
if (l && z(l)) {
|
|
184
|
+
const c = await ne();
|
|
185
|
+
l = X(
|
|
186
|
+
c,
|
|
187
|
+
// 目前 dark 和 light 还是前端行为,后端通过 从 light 中获取
|
|
188
|
+
`settings.theme.light.palette.${l}`,
|
|
189
|
+
l
|
|
190
|
+
);
|
|
147
191
|
}
|
|
148
|
-
const I =
|
|
192
|
+
const I = B(), x = [
|
|
193
|
+
{
|
|
194
|
+
selector: {
|
|
195
|
+
cheerio: "#injected-head-elements",
|
|
196
|
+
pattern: /<script[^>]*id=["']injected-head-elements["'][^>]*><\/script>/gis
|
|
197
|
+
},
|
|
198
|
+
value: `
|
|
149
199
|
${l ? `<meta name="theme-color" content="${l}" /><style>html,body,#app {background-color: ${l};}</style>` : ""}
|
|
150
|
-
${
|
|
151
|
-
${
|
|
200
|
+
${p?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${p.title}&display=swap">` : ""}
|
|
201
|
+
${p?.description && p?.description !== p?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${p.description}&display=swap">` : ""}
|
|
152
202
|
|
|
153
203
|
|
|
154
204
|
<script>
|
|
@@ -168,20 +218,46 @@ function je({ app: o, viteDevServer: e, state: t }) {
|
|
|
168
218
|
|
|
169
219
|
<\/script>
|
|
170
220
|
|
|
171
|
-
${
|
|
221
|
+
${$ ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
172
222
|
<script>
|
|
173
223
|
window.tailwind.config = {
|
|
174
224
|
darkMode: "class",
|
|
175
225
|
};
|
|
176
226
|
<\/script>` : ""}
|
|
177
|
-
`
|
|
178
|
-
|
|
179
|
-
|
|
227
|
+
`
|
|
228
|
+
},
|
|
229
|
+
// blocklet.js script
|
|
230
|
+
I && {
|
|
231
|
+
selector: {
|
|
232
|
+
cheerio: 'script[src="__blocklet__.js"]',
|
|
233
|
+
pattern: /<script[^>]*src=["']__blocklet__\.js["'][^>]*><\/script>/gis
|
|
234
|
+
},
|
|
235
|
+
value: `<script>${I}<\/script>`
|
|
236
|
+
},
|
|
237
|
+
// injected-html-elements
|
|
238
|
+
k?.html && {
|
|
239
|
+
selector: {
|
|
240
|
+
cheerio: "#injected-html-elements",
|
|
241
|
+
pattern: /<script[^>]*id=["']injected-html-elements["'][^>]*><\/script>/gis
|
|
242
|
+
},
|
|
243
|
+
value: k.html
|
|
244
|
+
},
|
|
245
|
+
// cachedHtml body content
|
|
246
|
+
n.cachedHtml && {
|
|
247
|
+
selector: {
|
|
248
|
+
cheerio: "body",
|
|
249
|
+
pattern: /(<body[^>]*>).*?(<\/body>)/gis
|
|
250
|
+
},
|
|
251
|
+
value: `<body>${ae(n.cachedHtml)}</body>`
|
|
252
|
+
}
|
|
253
|
+
].filter(Boolean);
|
|
254
|
+
g = await ie(g, x), u.send(g), _.info(`[html] render: ${n.path}, ${S()}ms`), g = null, f = null, k = null;
|
|
255
|
+
}), o.use(i);
|
|
180
256
|
}
|
|
181
|
-
function
|
|
182
|
-
const e =
|
|
257
|
+
function me(o) {
|
|
258
|
+
const e = Q("image-bin");
|
|
183
259
|
return e && o && !/^(https?:\/\/|\/)/.test(o) ? r.env.appUrl + P(e, "uploads", o) : o;
|
|
184
260
|
}
|
|
185
261
|
export {
|
|
186
|
-
|
|
262
|
+
$e as default
|
|
187
263
|
};
|
package/lib/es/resources.js
CHANGED
|
@@ -1,123 +1,167 @@
|
|
|
1
|
-
import { P as
|
|
2
|
-
import { AsyncLocalStorage as
|
|
3
|
-
import { Router as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { getResourceExportDir as
|
|
11
|
-
new
|
|
12
|
-
const Q = async (
|
|
1
|
+
import { P as w, i as A, a as M, l as b, C as J, R as X, S as x, t as W, b as G } from "./chunks/site-state-BdLTu3Od.js";
|
|
2
|
+
import { AsyncLocalStorage as K } from "async_hooks";
|
|
3
|
+
import { Router as Y } from "express";
|
|
4
|
+
import a from "fs";
|
|
5
|
+
import m from "joi";
|
|
6
|
+
import C from "lodash/groupBy";
|
|
7
|
+
import $ from "lodash/sortBy";
|
|
8
|
+
import O, { join as z } from "path";
|
|
9
|
+
import _ from "@blocklet/sdk/lib/middlewares/auth";
|
|
10
|
+
import { getResourceExportDir as H } from "@blocklet/sdk/lib/component";
|
|
11
|
+
new K();
|
|
12
|
+
const Q = async (e, t, o) => {
|
|
13
13
|
try {
|
|
14
|
-
const { projectId:
|
|
15
|
-
if (!n)
|
|
16
|
-
return r();
|
|
17
|
-
const s = await S.findByPk(n);
|
|
14
|
+
const { projectId: s } = e.params;
|
|
18
15
|
if (!s)
|
|
19
|
-
return
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
return o();
|
|
17
|
+
const n = await w.findByPk(s);
|
|
18
|
+
if (!n)
|
|
19
|
+
return t?.status(404).json({ error: "Project not found" });
|
|
20
|
+
const r = e.user?.did, c = e.user?.role || "UNKNOWN_ROLE";
|
|
21
|
+
if (!r)
|
|
22
|
+
return t?.status(401).json({ error: "Authentication required" });
|
|
23
|
+
if (A()) {
|
|
24
|
+
const j = n.createdBy === r, I = M()?.includes?.(c);
|
|
25
|
+
if (!j && !I)
|
|
26
|
+
return t?.status(403).json({ error: "No permission to access this project in multi-tenant mode" });
|
|
27
27
|
} else if (!["owner", "admin", "pagesEditor"].includes(c))
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
28
|
+
return t?.status(403).json({ error: "No permission to access this project in single-tenant mode" });
|
|
29
|
+
e.project = n, e.projectId = s, o();
|
|
30
|
+
} catch (s) {
|
|
31
|
+
b.error("Project middleware error:", s), t?.status(400).json({ error: "Internal server error" });
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
function
|
|
35
|
-
return new Promise((
|
|
36
|
-
const
|
|
37
|
-
|
|
34
|
+
function N(e, t) {
|
|
35
|
+
return new Promise((o, s) => {
|
|
36
|
+
const n = a.createReadStream(e), r = a.createWriteStream(t);
|
|
37
|
+
n.on("error", s), r.on("error", s), r.on("finish", o), n.pipe(r);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
async function
|
|
41
|
-
await
|
|
42
|
-
const
|
|
43
|
-
for (const
|
|
44
|
-
const
|
|
45
|
-
|
|
40
|
+
async function U(e, t) {
|
|
41
|
+
await a.promises.mkdir(t, { recursive: !0 });
|
|
42
|
+
const o = await a.promises.readdir(e, { withFileTypes: !0 });
|
|
43
|
+
for (const s of o) {
|
|
44
|
+
const n = O.join(e, s.name), r = O.join(t, s.name);
|
|
45
|
+
s.isDirectory() ? await U(n, r) : await N(n, r);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async function V(
|
|
49
|
-
(await
|
|
48
|
+
async function V(e, t) {
|
|
49
|
+
(await a.promises.stat(e)).isDirectory() ? await U(e, t) : await N(e, t);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
const [
|
|
56
|
-
if (
|
|
57
|
-
},
|
|
58
|
-
const [
|
|
59
|
-
if (
|
|
60
|
-
},
|
|
61
|
-
const [
|
|
62
|
-
if (
|
|
63
|
-
},
|
|
51
|
+
const E = (e, t, o) => A() ? _()(e, t, o) : _({ roles: ["owner", "admin", "pagesEditor"] })(e, t, o), Z = (e, t) => {
|
|
52
|
+
const o = H({ projectId: e, releaseId: t });
|
|
53
|
+
return z(o, J, X);
|
|
54
|
+
}, S = Y(), B = "@page", T = "@component", l = ":", P = "ALL", L = "@project", D = ({ pageId: e, projectId: t }) => [B, t, e].join(l), q = (e) => {
|
|
55
|
+
const [t, o, s] = e.split(l);
|
|
56
|
+
if (t === B) return { pageId: s, projectId: o };
|
|
57
|
+
}, k = ({ componentId: e, projectId: t }) => [T, t, e].join(l), ee = (e) => {
|
|
58
|
+
const [t, o, s] = e.split(l);
|
|
59
|
+
if (t === T) return { componentId: s, projectId: o };
|
|
60
|
+
}, te = (e) => [L, e].join(l), oe = (e) => {
|
|
61
|
+
const [t, o] = e.split(l);
|
|
62
|
+
if (t === L) return o;
|
|
63
|
+
}, re = (e) => {
|
|
64
64
|
try {
|
|
65
|
-
return JSON.parse(
|
|
65
|
+
return JSON.parse(e);
|
|
66
66
|
} catch {
|
|
67
67
|
}
|
|
68
68
|
return {};
|
|
69
69
|
};
|
|
70
|
-
async function
|
|
71
|
-
const
|
|
72
|
-
const c =
|
|
73
|
-
if (c)
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
async function v(e) {
|
|
71
|
+
const t = await x.getStateByProjectId(e, "production"), o = await w.findByPk(e), s = t.pageIds.map((r) => {
|
|
72
|
+
const c = t.pages[r];
|
|
73
|
+
if (c)
|
|
74
|
+
return { id: D({ pageId: r, projectId: e }), name: c.slug };
|
|
75
|
+
}).filter(Boolean), n = $(Object.values(t.components), (r) => r.index).map(({ data: r }) => ({
|
|
76
|
+
id: k({ componentId: r.id, projectId: e }),
|
|
77
|
+
name: r.name || r.id
|
|
78
|
+
}));
|
|
79
|
+
return {
|
|
80
|
+
id: te(e),
|
|
81
|
+
name: o?.name || "Unnamed Project",
|
|
82
|
+
children: [
|
|
83
|
+
{ id: D({ pageId: P, projectId: e }), name: "Pages", children: s },
|
|
84
|
+
{
|
|
85
|
+
id: k({ componentId: P, projectId: e }),
|
|
86
|
+
name: "Components",
|
|
87
|
+
children: n
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
};
|
|
76
91
|
}
|
|
77
|
-
|
|
78
|
-
const { projectId:
|
|
79
|
-
if (
|
|
80
|
-
|
|
92
|
+
S.get("/resources", E, async (e, t) => {
|
|
93
|
+
const { projectId: o } = re(e.query.resourcesParams);
|
|
94
|
+
if (o) {
|
|
95
|
+
e.params = { ...e.params, projectId: o }, await Q(e, t, () => {
|
|
81
96
|
});
|
|
82
|
-
const
|
|
83
|
-
|
|
97
|
+
const r = await v(o);
|
|
98
|
+
t.json({ resources: [r] });
|
|
84
99
|
return;
|
|
85
100
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
101
|
+
const s = await w.findAll({
|
|
102
|
+
where: {
|
|
103
|
+
// Add your permission check conditions here
|
|
104
|
+
// For example: userId: req.user.id
|
|
105
|
+
}
|
|
106
|
+
}), n = await Promise.all(s.map((r) => v(r.id)));
|
|
107
|
+
t.json({ resources: n });
|
|
88
108
|
});
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
const se = m.object({
|
|
110
|
+
projectId: m.string().required().min(1),
|
|
111
|
+
releaseId: m.string().allow(""),
|
|
112
|
+
resources: m.array().items(m.string()).required(),
|
|
113
|
+
locale: m.string().allow("")
|
|
114
|
+
});
|
|
115
|
+
S.post("/resources", E, async (e, t) => {
|
|
116
|
+
const { resources: o, projectId: s, releaseId: n } = await se.validateAsync(e.body), r = "production", c = [], j = [];
|
|
117
|
+
for (const i of o) {
|
|
118
|
+
if (oe(i))
|
|
119
|
+
continue;
|
|
120
|
+
const { pageId: p, projectId: g } = q(i) || {};
|
|
121
|
+
if (p)
|
|
122
|
+
p === P || p && g && c.push({
|
|
123
|
+
pageId: p,
|
|
124
|
+
projectId: g
|
|
125
|
+
});
|
|
96
126
|
else {
|
|
97
|
-
const { componentId:
|
|
98
|
-
|
|
127
|
+
const { componentId: f, projectId: d } = ee(i) || {};
|
|
128
|
+
f === P || f && d && j.push({
|
|
129
|
+
componentId: f,
|
|
130
|
+
projectId: d
|
|
131
|
+
});
|
|
99
132
|
}
|
|
100
133
|
}
|
|
101
|
-
const I =
|
|
102
|
-
|
|
103
|
-
for (const
|
|
104
|
-
const p = await
|
|
105
|
-
if (d?.length ||
|
|
106
|
-
const
|
|
107
|
-
|
|
134
|
+
const I = C(c, "projectId"), h = C(j, "projectId"), F = /* @__PURE__ */ new Set([...Object.keys(I), ...Object.keys(h)]), y = Z(s, n);
|
|
135
|
+
a.rmSync(y, { recursive: !0, force: !0 }), a.mkdirSync(y, { recursive: !0 });
|
|
136
|
+
for (const i of F) {
|
|
137
|
+
const p = await x.getStateByProjectId(i, r), g = I[i], f = h[i], d = g?.map((u) => u.pageId), R = f?.map((u) => u.componentId);
|
|
138
|
+
if (d?.length || R?.length) {
|
|
139
|
+
const u = await W(p, {
|
|
140
|
+
exportAssets: !0,
|
|
141
|
+
pageIds: d,
|
|
142
|
+
componentIds: R
|
|
143
|
+
});
|
|
144
|
+
await V(u, y), a.rmSync(u, { recursive: !0, force: !0 });
|
|
108
145
|
}
|
|
109
|
-
|
|
146
|
+
b.info(`Exported resources for project ${i}`, {
|
|
147
|
+
pageIds: d,
|
|
148
|
+
componentIds: R
|
|
149
|
+
});
|
|
110
150
|
}
|
|
111
|
-
|
|
151
|
+
t.json({});
|
|
112
152
|
});
|
|
113
|
-
|
|
114
|
-
const { states:
|
|
115
|
-
const
|
|
116
|
-
|
|
153
|
+
S.get("/all-resources", E, async (e, t) => {
|
|
154
|
+
const { states: o } = await G(), s = o?.map((n) => {
|
|
155
|
+
const r = {
|
|
156
|
+
blockletId: n.blockletId,
|
|
157
|
+
blockletTitle: n.blockletTitle,
|
|
158
|
+
components: {}
|
|
159
|
+
};
|
|
160
|
+
if (n.state.components && (r.components = n.state.components), Object.keys(r.components).length !== 0)
|
|
161
|
+
return r;
|
|
117
162
|
}).filter(Boolean);
|
|
118
|
-
|
|
163
|
+
t.json(s);
|
|
119
164
|
});
|
|
120
|
-
var ft = w;
|
|
121
165
|
export {
|
|
122
|
-
|
|
166
|
+
S as default
|
|
123
167
|
};
|