@blocklet/pages-kit-inner-components 0.5.56 → 0.6.1
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 +21 -23
- package/lib/cjs/chunks/{draft-data-CuZfaQ4s.js → draft-data-D44_IEV2.js} +1 -1
- 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-gSkcvhcV.js +57 -0
- package/lib/cjs/chunks/state-B6BF5wJ-.js +1 -0
- package/lib/cjs/components.js +1 -1
- package/lib/cjs/home.js +1 -1
- package/lib/cjs/project-html.js +7 -7
- package/lib/cjs/resources.js +1 -1
- package/lib/cjs/setting.js +3 -3
- package/lib/cjs/site-state.js +1 -1
- package/lib/cjs/theme.js +1 -1
- package/lib/es/add-component.js +385 -2356
- package/lib/es/chunks/{draft-data-CWM--ooz.js → draft-data-CafrGKeh.js} +1 -1
- 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-XSZrDaTQ.js +498 -0
- package/lib/es/chunks/session-C72Dq8zg.js +19 -0
- package/lib/es/chunks/site-state-W2H7XCSQ.js +2077 -0
- package/lib/es/chunks/state-0gvZF3k2.js +573 -0
- package/lib/es/components.js +1 -1
- package/lib/es/home.js +5 -5
- package/lib/es/project-html.js +131 -141
- package/lib/es/resources.js +106 -107
- package/lib/es/setting.js +1772 -1489
- package/lib/es/site-state.js +1 -1
- package/lib/es/theme.js +50 -51
- package/package.json +46 -47
- package/lib/cjs/chunks/array-BqHuYyfx.js +0 -475
- package/lib/cjs/chunks/config-string-4bVR9Vc8.js +0 -1
- package/lib/cjs/chunks/home-BMjMYgq3.js +0 -38
- package/lib/cjs/chunks/publish-button-CGfGqrov.js +0 -1
- package/lib/cjs/chunks/session-BA7Qrcia.js +0 -1
- package/lib/cjs/chunks/site-state-BtZ8o3J2.js +0 -57
- package/lib/cjs/chunks/state-BVdbNJCA.js +0 -1
- package/lib/es/chunks/array-c6HYTLze.js +0 -2224
- package/lib/es/chunks/config-string-WMpFf-7V.js +0 -88
- package/lib/es/chunks/home-PDsc59QG.js +0 -566
- package/lib/es/chunks/publish-button-Ds7OBvxV.js +0 -462
- package/lib/es/chunks/session-CVblGhSp.js +0 -21
- package/lib/es/chunks/site-state-D-moj9fA.js +0 -2125
- package/lib/es/chunks/state-l--dTdHq.js +0 -603
package/lib/es/project-html.js
CHANGED
|
@@ -1,185 +1,175 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { l as
|
|
9
|
-
import { createSnapshotMiddleware as
|
|
10
|
-
import { PreloadComponentScriptModule as
|
|
11
|
-
import { isMuiColorKey as
|
|
12
|
-
import { injectPreloadComponents as
|
|
13
|
-
import { getComponentMountPoint as
|
|
14
|
-
import * as
|
|
15
|
-
import { Router as
|
|
16
|
-
import { readFileSync as
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import { withQuery as
|
|
20
|
-
const
|
|
21
|
-
const
|
|
1
|
+
import W from "@arcblock/did-auth-storage-nedb";
|
|
2
|
+
import i, { getBlockletJs as D } from "@blocklet/sdk/lib/config";
|
|
3
|
+
import K from "@blocklet/sdk/lib/service/auth";
|
|
4
|
+
import U from "@blocklet/sdk/lib/wallet";
|
|
5
|
+
import B from "@blocklet/sdk/lib/wallet-authenticator";
|
|
6
|
+
import N from "@blocklet/sdk/lib/wallet-handler";
|
|
7
|
+
import H, { resolve as I } from "path";
|
|
8
|
+
import { l as C, g as O } from "./chunks/site-state-W2H7XCSQ.js";
|
|
9
|
+
import { createSnapshotMiddleware as R } from "@arcblock/crawler-middleware";
|
|
10
|
+
import { PreloadComponentScriptModule as F } from "@blocklet/pages-kit/types";
|
|
11
|
+
import { isMuiColorKey as J } from "@blocklet/pages-kit/utils/common";
|
|
12
|
+
import { injectPreloadComponents as z, safeJSONStringify as G } from "@blocklet/pages-kit/utils/preload";
|
|
13
|
+
import { getComponentMountPoint as Y } from "@blocklet/sdk/lib/component";
|
|
14
|
+
import * as E from "cheerio/slim";
|
|
15
|
+
import { Router as Q } from "express";
|
|
16
|
+
import { readFileSync as P } from "fs";
|
|
17
|
+
import V from "lodash/get";
|
|
18
|
+
import X from "mustache";
|
|
19
|
+
import { withQuery as Z, joinURL as $ } from "ufo";
|
|
20
|
+
const q = (o = {}) => {
|
|
21
|
+
const e = {
|
|
22
22
|
data: /* @__PURE__ */ new Map(),
|
|
23
23
|
timers: /* @__PURE__ */ new Map(),
|
|
24
|
-
set: (
|
|
25
|
-
o.max &&
|
|
26
|
-
|
|
27
|
-
setTimeout(() =>
|
|
28
|
-
),
|
|
24
|
+
set: (t, l, m = o.ttl || 36e5) => {
|
|
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
|
+
t,
|
|
27
|
+
setTimeout(() => e.delete(t), m)
|
|
28
|
+
), e.data.set(t, l);
|
|
29
29
|
},
|
|
30
|
-
get: (
|
|
31
|
-
has: (
|
|
32
|
-
delete: (
|
|
30
|
+
get: (t) => e.data.get(t),
|
|
31
|
+
has: (t) => e.data.has(t),
|
|
32
|
+
delete: (t) => (e.timers.has(t) && clearTimeout(e.timers.get(t)), e.timers.delete(t), e.data.delete(t)),
|
|
33
33
|
clear: () => {
|
|
34
|
-
|
|
35
|
-
for (const
|
|
36
|
-
clearTimeout(
|
|
37
|
-
|
|
34
|
+
e.data.clear();
|
|
35
|
+
for (const t of e.timers.values())
|
|
36
|
+
clearTimeout(t);
|
|
37
|
+
e.timers.clear();
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
return
|
|
41
|
-
},
|
|
40
|
+
return e;
|
|
41
|
+
}, A = q({
|
|
42
42
|
max: 1,
|
|
43
43
|
ttl: 1e3 * 30
|
|
44
44
|
// 30 seconds
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
new
|
|
49
|
-
authenticator:
|
|
50
|
-
tokenStorage: new
|
|
51
|
-
dbPath:
|
|
46
|
+
U();
|
|
47
|
+
const ee = new B();
|
|
48
|
+
new N({
|
|
49
|
+
authenticator: ee,
|
|
50
|
+
tokenStorage: new W({
|
|
51
|
+
dbPath: H.join(i.env.dataDir, "auth.db")
|
|
52
52
|
})
|
|
53
53
|
});
|
|
54
|
-
const
|
|
54
|
+
const te = new K(), oe = async () => {
|
|
55
55
|
try {
|
|
56
|
-
const o =
|
|
56
|
+
const o = A.get("blockletInfo");
|
|
57
57
|
if (o)
|
|
58
58
|
return o;
|
|
59
|
-
const { blocklet:
|
|
60
|
-
return
|
|
59
|
+
const { blocklet: e } = await te.getBlocklet();
|
|
60
|
+
return A.set("blockletInfo", e), e;
|
|
61
61
|
} catch {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
-
},
|
|
65
|
-
function
|
|
64
|
+
}, ne = ["/assets/"];
|
|
65
|
+
function Ce({
|
|
66
66
|
app: o,
|
|
67
|
-
viteDevServer:
|
|
67
|
+
viteDevServer: e,
|
|
68
68
|
// projectId,
|
|
69
|
-
state:
|
|
69
|
+
state: t
|
|
70
70
|
}) {
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
const n =
|
|
74
|
-
o.use(async (
|
|
75
|
-
const
|
|
76
|
-
|
|
71
|
+
let l;
|
|
72
|
+
if (e) {
|
|
73
|
+
const n = P(I(process.cwd(), "./index.html"), "utf-8");
|
|
74
|
+
o.use(async (u, S, v) => {
|
|
75
|
+
const _ = u.originalUrl;
|
|
76
|
+
l = await e.transformIndexHtml(_, n), v();
|
|
77
77
|
});
|
|
78
78
|
} else
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
79
|
+
l = P(I(process.env.BLOCKLET_APP_DIR, "dist/index.html"), "utf-8");
|
|
80
|
+
const m = Q();
|
|
81
|
+
m.use((n, u, S) => {
|
|
82
82
|
if (n.headers["x-unique-record"] === "dial_http") {
|
|
83
|
-
|
|
83
|
+
C.info("[html] dial http request, return 200 status code"), u.status(200).send("ok");
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
}),
|
|
88
|
-
|
|
89
|
-
endpoint:
|
|
90
|
-
accessKey:
|
|
91
|
-
cacheMax:
|
|
86
|
+
S();
|
|
87
|
+
}), i.env.preferences.snapkitEnabled && i.env.preferences.snapkitEndpoint && i.env.SNAP_KIT_ACCESS_KEY && m.use(
|
|
88
|
+
R({
|
|
89
|
+
endpoint: i.env.preferences.snapkitEndpoint,
|
|
90
|
+
accessKey: i.env.SNAP_KIT_ACCESS_KEY,
|
|
91
|
+
cacheMax: i.env.preferences.snapkitCacheSize || 100
|
|
92
92
|
})
|
|
93
|
-
),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var m;
|
|
97
|
-
return (m = n.path) == null ? void 0 : m.startsWith(s);
|
|
98
|
-
})) {
|
|
99
|
-
_();
|
|
93
|
+
), m.get("/:path(*)?", async (n, u, S) => {
|
|
94
|
+
if (ne.some((a) => n.path?.startsWith(a))) {
|
|
95
|
+
S();
|
|
100
96
|
return;
|
|
101
97
|
}
|
|
102
|
-
const
|
|
103
|
-
let
|
|
98
|
+
const v = performance.now(), _ = () => Math.round(performance.now() - v), j = "production";
|
|
99
|
+
let g, b, w = l;
|
|
104
100
|
if (n.path.startsWith("/pages")) {
|
|
105
|
-
const
|
|
106
|
-
let
|
|
107
|
-
if ((!
|
|
108
|
-
const
|
|
109
|
-
Object.values(
|
|
110
|
-
const
|
|
111
|
-
(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
cacheDuration: p.config.cacheDuration,
|
|
122
|
-
properties: (x = (v = c == null ? void 0 : c.dataSource) == null ? void 0 : v[p.id]) == null ? void 0 : x[g]
|
|
123
|
-
// ?? i.locales?.[respectLocale!]?.properties,
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
w.push(...N);
|
|
101
|
+
const a = n.params.lang, y = n.cookies.nf_lang, k = /* @__PURE__ */ new Set([...i.env.languages.map((f) => f.code)]);
|
|
102
|
+
let h = (a && k.has(a) ? a : void 0) || (k.has(y) ? y : void 0) || [...k][0];
|
|
103
|
+
if ((!h || !t.supportedLocales?.find((f) => f.locale === h)) && (h = t.supportedLocales?.[0]?.locale || ""), h) {
|
|
104
|
+
const f = [];
|
|
105
|
+
Object.values(t.pages).forEach((r) => {
|
|
106
|
+
const L = Object.values(r?.sections ?? {}).filter(
|
|
107
|
+
(c) => c.component === "custom-component" && c.config?.componentId
|
|
108
|
+
).map((c) => ({
|
|
109
|
+
id: c.id,
|
|
110
|
+
componentId: c.config.componentId,
|
|
111
|
+
useCache: c.config.useCache,
|
|
112
|
+
cacheDuration: c.config.cacheDuration,
|
|
113
|
+
properties: r?.dataSource?.[c.id]?.[h]
|
|
114
|
+
// ?? i.locales?.[respectLocale!]?.properties,
|
|
115
|
+
}));
|
|
116
|
+
f.push(...L);
|
|
127
117
|
});
|
|
128
|
-
const
|
|
118
|
+
const M = new Promise((r) => {
|
|
129
119
|
setTimeout(() => {
|
|
130
|
-
|
|
120
|
+
r({});
|
|
131
121
|
}, 90 * 1e3);
|
|
132
122
|
});
|
|
133
123
|
try {
|
|
134
124
|
await Promise.race([
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
mode:
|
|
125
|
+
M,
|
|
126
|
+
O({
|
|
127
|
+
mode: j,
|
|
138
128
|
req: n,
|
|
139
|
-
state:
|
|
140
|
-
locale:
|
|
141
|
-
instances:
|
|
142
|
-
module:
|
|
143
|
-
}).then((
|
|
144
|
-
|
|
129
|
+
state: t,
|
|
130
|
+
locale: h,
|
|
131
|
+
instances: f,
|
|
132
|
+
module: F.UMD_FN
|
|
133
|
+
}).then((r) => {
|
|
134
|
+
r && (b = z(r));
|
|
145
135
|
})
|
|
146
136
|
]);
|
|
147
|
-
} catch (
|
|
148
|
-
|
|
137
|
+
} catch (r) {
|
|
138
|
+
C.warn("getPreloadComponents timeout in promise race, skip inject html elements", r);
|
|
149
139
|
}
|
|
150
140
|
}
|
|
151
141
|
}
|
|
152
142
|
try {
|
|
153
|
-
const
|
|
154
|
-
title:
|
|
155
|
-
description:
|
|
143
|
+
const a = g?.title || i.env.appName, y = g?.description || i.env.appDescription, k = Z($(i.env.appUrl, "/.well-known/service/blocklet/og.png"), {
|
|
144
|
+
title: a,
|
|
145
|
+
description: y
|
|
156
146
|
});
|
|
157
|
-
|
|
158
|
-
ogTitle:
|
|
159
|
-
ogDescription:
|
|
160
|
-
ogImage:
|
|
161
|
-
pagesPublishedAt:
|
|
147
|
+
w = X.render(l, {
|
|
148
|
+
ogTitle: a,
|
|
149
|
+
ogDescription: y,
|
|
150
|
+
ogImage: ae(g?.image) || k,
|
|
151
|
+
pagesPublishedAt: t?.config.publishedAt || (/* @__PURE__ */ new Date()).getTime()
|
|
162
152
|
});
|
|
163
153
|
} catch {
|
|
164
154
|
}
|
|
165
|
-
const
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
const p = t?.config.fontFamily, x = n.query.mode === "draft" || n.url.includes("preview") || n.path?.startsWith("/admin"), d = E.load(w);
|
|
156
|
+
let s = g?.backgroundColor;
|
|
157
|
+
if (s && J(s)) {
|
|
158
|
+
const a = await oe();
|
|
159
|
+
s = V(
|
|
160
|
+
a,
|
|
171
161
|
// 目前 dark 和 light 还是前端行为,后端通过 从 light 中获取
|
|
172
|
-
`settings.theme.light.palette.${
|
|
173
|
-
|
|
162
|
+
`settings.theme.light.palette.${s}`,
|
|
163
|
+
s
|
|
174
164
|
);
|
|
175
165
|
}
|
|
176
|
-
|
|
177
|
-
${
|
|
178
|
-
${
|
|
179
|
-
${
|
|
166
|
+
d("head").find("#injected-head-elements").replaceWith(`
|
|
167
|
+
${s ? `<meta name="theme-color" content="${s}" /><style>html,body,#app {background-color: ${s};}</style>` : ""}
|
|
168
|
+
${p?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${p.title}&display=swap">` : ""}
|
|
169
|
+
${p?.description && p?.description !== p?.title ? `<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=${p.description}&display=swap">` : ""}
|
|
180
170
|
<script>
|
|
181
171
|
|
|
182
|
-
window.__PAGE_STATE__ = ${
|
|
172
|
+
window.__PAGE_STATE__ = ${G(t || null)};
|
|
183
173
|
|
|
184
174
|
document.querySelectorAll('link[rel="preload"][as="style"]').forEach(function (link) {
|
|
185
175
|
const l = document.createElement('link');
|
|
@@ -189,25 +179,25 @@ function $e({
|
|
|
189
179
|
});
|
|
190
180
|
<\/script>
|
|
191
181
|
|
|
192
|
-
${
|
|
182
|
+
${x ? `<script src="https://cdn.tailwindcss.com"><\/script>
|
|
193
183
|
<script>
|
|
194
184
|
window.tailwind.config = {
|
|
195
185
|
darkMode: "class",
|
|
196
186
|
};
|
|
197
187
|
<\/script>` : ""}
|
|
198
188
|
`);
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
const
|
|
202
|
-
|
|
189
|
+
const T = D();
|
|
190
|
+
if (T && d('script[src="__blocklet__.js"]').replaceWith(`<script>${T}<\/script>`), b?.html && d("head").find("#injected-html-elements").replaceWith(b.html), n.cachedHtml) {
|
|
191
|
+
const a = E.load(n.cachedHtml);
|
|
192
|
+
d("body").html(a("body").html() || "");
|
|
203
193
|
}
|
|
204
|
-
|
|
205
|
-
}), o.use(
|
|
194
|
+
w = d.html(), u.send(w), C.info(`[html] render: ${n.path}, ${_()}ms`), d.root().children().remove(), w = null, g = null, b = null;
|
|
195
|
+
}), o.use(m);
|
|
206
196
|
}
|
|
207
|
-
function
|
|
208
|
-
const
|
|
209
|
-
return
|
|
197
|
+
function ae(o) {
|
|
198
|
+
const e = Y("image-bin");
|
|
199
|
+
return e && o && !/^(https?:\/\/|\/)/.test(o) ? i.env.appUrl + $(e, "uploads", o) : o;
|
|
210
200
|
}
|
|
211
201
|
export {
|
|
212
|
-
|
|
202
|
+
Ce as default
|
|
213
203
|
};
|
package/lib/es/resources.js
CHANGED
|
@@ -1,168 +1,167 @@
|
|
|
1
|
-
import { P as
|
|
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-W2H7XCSQ.js";
|
|
2
2
|
import { AsyncLocalStorage as K } from "async_hooks";
|
|
3
3
|
import { Router as Y } from "express";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import a from "fs";
|
|
5
|
+
import m from "joi";
|
|
6
|
+
import C from "lodash/groupBy";
|
|
7
7
|
import $ from "lodash/sortBy";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import O, { join as z } from "path";
|
|
9
|
+
import _ from "@blocklet/sdk/lib/middlewares/auth";
|
|
10
10
|
import { getResourceExportDir as H } from "@blocklet/sdk/lib/component";
|
|
11
11
|
new K();
|
|
12
|
-
const Q = async (
|
|
13
|
-
var n, s, r, i;
|
|
12
|
+
const Q = async (e, t, o) => {
|
|
14
13
|
try {
|
|
15
|
-
const { projectId:
|
|
16
|
-
if (!
|
|
17
|
-
return
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
return t
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
return t
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
27
|
-
return t
|
|
28
|
-
} else if (!["owner", "admin", "pagesEditor"].includes(
|
|
29
|
-
return t
|
|
30
|
-
|
|
31
|
-
} catch (
|
|
32
|
-
|
|
14
|
+
const { projectId: s } = e.params;
|
|
15
|
+
if (!s)
|
|
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
|
+
} else if (!["owner", "admin", "pagesEditor"].includes(c))
|
|
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" });
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
function
|
|
36
|
-
return new Promise((
|
|
37
|
-
const
|
|
38
|
-
|
|
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);
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
async function
|
|
42
|
-
await
|
|
43
|
-
const
|
|
44
|
-
for (const
|
|
45
|
-
const
|
|
46
|
-
|
|
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);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
async function V(
|
|
50
|
-
(await
|
|
48
|
+
async function V(e, t) {
|
|
49
|
+
(await a.promises.stat(e)).isDirectory() ? await U(e, t) : await N(e, t);
|
|
51
50
|
}
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
return z(
|
|
55
|
-
},
|
|
56
|
-
const [t,
|
|
57
|
-
if (t ===
|
|
58
|
-
},
|
|
59
|
-
const [t,
|
|
60
|
-
if (t ===
|
|
61
|
-
},
|
|
62
|
-
const [t,
|
|
63
|
-
if (t ===
|
|
64
|
-
},
|
|
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) => {
|
|
65
64
|
try {
|
|
66
|
-
return JSON.parse(
|
|
65
|
+
return JSON.parse(e);
|
|
67
66
|
} catch {
|
|
68
67
|
}
|
|
69
68
|
return {};
|
|
70
69
|
};
|
|
71
|
-
async function
|
|
72
|
-
const t = await
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
return { id:
|
|
76
|
-
}).filter(Boolean),
|
|
77
|
-
id:
|
|
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 }),
|
|
78
77
|
name: r.name || r.id
|
|
79
78
|
}));
|
|
80
79
|
return {
|
|
81
|
-
id:
|
|
82
|
-
name:
|
|
80
|
+
id: te(e),
|
|
81
|
+
name: o?.name || "Unnamed Project",
|
|
83
82
|
children: [
|
|
84
|
-
{ id:
|
|
83
|
+
{ id: D({ pageId: P, projectId: e }), name: "Pages", children: s },
|
|
85
84
|
{
|
|
86
|
-
id:
|
|
85
|
+
id: k({ componentId: P, projectId: e }),
|
|
87
86
|
name: "Components",
|
|
88
|
-
children:
|
|
87
|
+
children: n
|
|
89
88
|
}
|
|
90
89
|
]
|
|
91
90
|
};
|
|
92
91
|
}
|
|
93
|
-
|
|
94
|
-
const { projectId:
|
|
95
|
-
if (
|
|
96
|
-
|
|
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, () => {
|
|
97
96
|
});
|
|
98
|
-
const r = await
|
|
97
|
+
const r = await v(o);
|
|
99
98
|
t.json({ resources: [r] });
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
|
-
const
|
|
101
|
+
const s = await w.findAll({
|
|
103
102
|
where: {
|
|
104
103
|
// Add your permission check conditions here
|
|
105
104
|
// For example: userId: req.user.id
|
|
106
105
|
}
|
|
107
|
-
}),
|
|
108
|
-
t.json({ resources:
|
|
106
|
+
}), n = await Promise.all(s.map((r) => v(r.id)));
|
|
107
|
+
t.json({ resources: n });
|
|
109
108
|
});
|
|
110
|
-
const
|
|
111
|
-
projectId:
|
|
112
|
-
releaseId:
|
|
113
|
-
resources:
|
|
114
|
-
locale:
|
|
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("")
|
|
115
114
|
});
|
|
116
|
-
|
|
117
|
-
const { resources:
|
|
118
|
-
for (const
|
|
119
|
-
if (
|
|
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))
|
|
120
119
|
continue;
|
|
121
|
-
const { pageId:
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
pageId:
|
|
125
|
-
projectId:
|
|
120
|
+
const { pageId: p, projectId: g } = q(i) || {};
|
|
121
|
+
if (p)
|
|
122
|
+
p === P || p && g && c.push({
|
|
123
|
+
pageId: p,
|
|
124
|
+
projectId: g
|
|
126
125
|
});
|
|
127
126
|
else {
|
|
128
|
-
const { componentId:
|
|
129
|
-
|
|
130
|
-
componentId:
|
|
131
|
-
projectId:
|
|
127
|
+
const { componentId: f, projectId: d } = ee(i) || {};
|
|
128
|
+
f === P || f && d && j.push({
|
|
129
|
+
componentId: f,
|
|
130
|
+
projectId: d
|
|
132
131
|
});
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
for (const
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
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, {
|
|
141
140
|
exportAssets: !0,
|
|
142
|
-
pageIds:
|
|
141
|
+
pageIds: d,
|
|
143
142
|
componentIds: R
|
|
144
143
|
});
|
|
145
|
-
await V(
|
|
144
|
+
await V(u, y), a.rmSync(u, { recursive: !0, force: !0 });
|
|
146
145
|
}
|
|
147
|
-
|
|
148
|
-
pageIds:
|
|
146
|
+
b.info(`Exported resources for project ${i}`, {
|
|
147
|
+
pageIds: d,
|
|
149
148
|
componentIds: R
|
|
150
149
|
});
|
|
151
150
|
}
|
|
152
151
|
t.json({});
|
|
153
152
|
});
|
|
154
|
-
|
|
155
|
-
const { states:
|
|
153
|
+
S.get("/all-resources", E, async (e, t) => {
|
|
154
|
+
const { states: o } = await G(), s = o?.map((n) => {
|
|
156
155
|
const r = {
|
|
157
|
-
blockletId:
|
|
158
|
-
blockletTitle:
|
|
156
|
+
blockletId: n.blockletId,
|
|
157
|
+
blockletTitle: n.blockletTitle,
|
|
159
158
|
components: {}
|
|
160
159
|
};
|
|
161
|
-
if (
|
|
160
|
+
if (n.state.components && (r.components = n.state.components), Object.keys(r.components).length !== 0)
|
|
162
161
|
return r;
|
|
163
162
|
}).filter(Boolean);
|
|
164
|
-
t.json(
|
|
163
|
+
t.json(s);
|
|
165
164
|
});
|
|
166
165
|
export {
|
|
167
|
-
|
|
166
|
+
S as default
|
|
168
167
|
};
|