@brightsideoy/kama 0.1.0-alpha.142 → 0.1.0-alpha.143
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/bin/cli.js +7 -12
- package/dist/assets/index-BcbVkck_.js +162 -0
- package/dist/index.html +1 -1
- package/dist/index.js +153 -143
- package/package.json +1 -1
- package/dist/assets/index-SWBz-Fr1.js +0 -162
package/dist/index.js
CHANGED
|
@@ -6033,10 +6033,20 @@ function Di(e) {
|
|
|
6033
6033
|
]) e === "id" && typeof t[e] == "string" && t[e].startsWith("ast_") || delete t[e];
|
|
6034
6034
|
return t;
|
|
6035
6035
|
}
|
|
6036
|
-
|
|
6036
|
+
function Oi(e) {
|
|
6037
|
+
if (!e.publishedAt || e.status === "draft") return !0;
|
|
6038
|
+
if (!e.draftDataJson) return !1;
|
|
6039
|
+
if (!e.publishedDataJson) return !0;
|
|
6040
|
+
try {
|
|
6041
|
+
return (typeof e.draftDataJson == "string" ? e.draftDataJson : JSON.stringify(e.draftDataJson)) !== (typeof e.publishedDataJson == "string" ? e.publishedDataJson : JSON.stringify(e.publishedDataJson));
|
|
6042
|
+
} catch {
|
|
6043
|
+
return !1;
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
async function ki(e, t, n) {
|
|
6037
6047
|
let r = {}, i = null;
|
|
6038
6048
|
if (t && t !== "0" && t !== 0 && t !== "null") {
|
|
6039
|
-
let n = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, draftDataJson, dataJson, level) AS (\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, 0 \n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id \n WHERE t.id = ? AND t.id IS NOT NULL AND t.id != 0\n
|
|
6049
|
+
let n = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, draftDataJson, dataJson, level) AS (\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, 0 \n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id \n WHERE t.id = ? AND t.id IS NOT NULL AND t.id != 0\n\n UNION ALL\n\n SELECT t.id, t.parentId, c.draftDataJson, c.dataJson, ap.level + 1 \n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id \n INNER JOIN ancestor_path ap ON t.id = ap.parentId\n WHERE ap.parentId IS NOT NULL AND ap.parentId != 0 AND ap.parentId != '0' AND ap.parentId != 'null' AND ap.level < 20\n ) SELECT draftDataJson, dataJson FROM ancestor_path ORDER BY level ASC\n ").all(t), a = Array.isArray(n) ? n : n?.results || [], o = /* @__PURE__ */ new Set([
|
|
6040
6050
|
"subpageLayoutId",
|
|
6041
6051
|
"layoutId",
|
|
6042
6052
|
"slug",
|
|
@@ -6078,7 +6088,7 @@ Y.get("/", async (e) => {
|
|
|
6078
6088
|
if (isNaN(r)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
6079
6089
|
let i = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(r);
|
|
6080
6090
|
if (!i) return e.json({ error: "Node not found" }, 404);
|
|
6081
|
-
let a = (i
|
|
6091
|
+
let a = Oi(i), o = {
|
|
6082
6092
|
id: i.id,
|
|
6083
6093
|
title: i.title,
|
|
6084
6094
|
slug: i.slug,
|
|
@@ -6106,7 +6116,7 @@ Y.get("/", async (e) => {
|
|
|
6106
6116
|
if (d && f && f.length === 1 && f[0] !== "inherit") u = f[0];
|
|
6107
6117
|
else if (!d && c.defaultLayout) u = c.defaultLayout;
|
|
6108
6118
|
else if (a) {
|
|
6109
|
-
let { resolvedLayoutId: e, inheritedFields: n } = await
|
|
6119
|
+
let { resolvedLayoutId: e, inheritedFields: n } = await ki(t, a.parentId, a.treeId);
|
|
6110
6120
|
(u === "inherit" || !u) && (u = e && (!f || f.includes(e) || f.includes("inherit")) ? e : c.defaultLayout || null);
|
|
6111
6121
|
for (let [e, t] of Object.entries(n)) (l[e] === void 0 || l[e] === null || l[e] === "" || l[e] === "inherit") && (l[e] = t);
|
|
6112
6122
|
} else (u === "inherit" || !u) && (u = c.defaultLayout || null);
|
|
@@ -6183,7 +6193,7 @@ Y.get("/", async (e) => {
|
|
|
6183
6193
|
});
|
|
6184
6194
|
}
|
|
6185
6195
|
let w = b.map((e) => {
|
|
6186
|
-
let t = (e
|
|
6196
|
+
let t = Oi(e);
|
|
6187
6197
|
return {
|
|
6188
6198
|
id: e.id,
|
|
6189
6199
|
title: e.title,
|
|
@@ -6476,8 +6486,8 @@ Y.get("/", async (e) => {
|
|
|
6476
6486
|
});
|
|
6477
6487
|
//#endregion
|
|
6478
6488
|
//#region server/routes/admin/trees.ts
|
|
6479
|
-
var
|
|
6480
|
-
function
|
|
6489
|
+
var Ai = new e();
|
|
6490
|
+
function ji(e, t) {
|
|
6481
6491
|
let n = Promise.resolve(typeof t == "function" ? t() : t).catch((e) => console.error("[Background Task Error]:", e));
|
|
6482
6492
|
try {
|
|
6483
6493
|
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
@@ -6500,7 +6510,7 @@ async function Q(e, t, n = []) {
|
|
|
6500
6510
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
6501
6511
|
if (typeof r.run == "function") return r.run(...n);
|
|
6502
6512
|
}
|
|
6503
|
-
function
|
|
6513
|
+
function Mi(e, t = null, n = 0) {
|
|
6504
6514
|
if (n > 50) return [];
|
|
6505
6515
|
let r = [];
|
|
6506
6516
|
for (let i = 0; i < e.length; i++) {
|
|
@@ -6513,19 +6523,19 @@ function ji(e, t = null, n = 0) {
|
|
|
6513
6523
|
id: s,
|
|
6514
6524
|
parentId: t,
|
|
6515
6525
|
sortOrder: i
|
|
6516
|
-
}), a.children && Array.isArray(a.children) && a.children.length > 0 && r.push(...
|
|
6526
|
+
}), a.children && Array.isArray(a.children) && a.children.length > 0 && r.push(...Mi(a.children, s, n + 1)));
|
|
6517
6527
|
}
|
|
6518
6528
|
return r;
|
|
6519
6529
|
}
|
|
6520
|
-
function
|
|
6530
|
+
function Ni(e) {
|
|
6521
6531
|
if (e == null || e === "null" || e === "" || e === 0 || e === "0" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6522
6532
|
let t = Number(e);
|
|
6523
6533
|
return isNaN(t) ? null : t;
|
|
6524
6534
|
}
|
|
6525
|
-
function
|
|
6535
|
+
function Pi(e) {
|
|
6526
6536
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6527
6537
|
}
|
|
6528
|
-
|
|
6538
|
+
Ai.get("/tree.json", async (e) => {
|
|
6529
6539
|
try {
|
|
6530
6540
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
6531
6541
|
if (isNaN(Number(n))) {
|
|
@@ -6583,7 +6593,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6583
6593
|
} catch (t) {
|
|
6584
6594
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
6585
6595
|
}
|
|
6586
|
-
}),
|
|
6596
|
+
}), Ai.post("/tree.json", async (e) => {
|
|
6587
6597
|
try {
|
|
6588
6598
|
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = 1;
|
|
6589
6599
|
if (isNaN(Number(r))) {
|
|
@@ -6591,7 +6601,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6591
6601
|
e[0] && e[0].id && (i = Number(e[0].id));
|
|
6592
6602
|
} else i = Number(r);
|
|
6593
6603
|
if (n.tree && Array.isArray(n.tree)) {
|
|
6594
|
-
let r =
|
|
6604
|
+
let r = Mi(n.tree, null);
|
|
6595
6605
|
if (r.length > 0) {
|
|
6596
6606
|
let e = r.map((e) => ({
|
|
6597
6607
|
sql: "UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE id = ? AND treeId = ?",
|
|
@@ -6604,16 +6614,16 @@ ki.get("/tree.json", async (e) => {
|
|
|
6604
6614
|
}));
|
|
6605
6615
|
await t.batch(e);
|
|
6606
6616
|
}
|
|
6607
|
-
return
|
|
6617
|
+
return ji(e, async () => {
|
|
6608
6618
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6609
6619
|
}), e.json({
|
|
6610
6620
|
success: !0,
|
|
6611
6621
|
reorderedCount: r.length
|
|
6612
6622
|
});
|
|
6613
6623
|
}
|
|
6614
|
-
let { action: a, title: o, nodeType: s, parentId: c, contentId: l, nodeData: u = {}, pageData: d = {} } = n, f = Object.keys(u).length > 0 ? { ...u } : { ...d }, p =
|
|
6624
|
+
let { action: a, title: o, nodeType: s, parentId: c, contentId: l, nodeData: u = {}, pageData: d = {} } = n, f = Object.keys(u).length > 0 ? { ...u } : { ...d }, p = Pi(n.isHidden === void 0 ? f.isHidden === void 0 ? f.hidden : f.isHidden : n.isHidden);
|
|
6615
6625
|
delete f._isTreeDraft, delete f._draftParentId, delete f.isNew, delete f.nodeType, delete f.contentType, delete f.title, delete f.slug, delete f.hidden, delete f.is_hidden, delete f.isHidden, delete f.status;
|
|
6616
|
-
let m =
|
|
6626
|
+
let m = Ni(c), h = e.get("user")?.id || null;
|
|
6617
6627
|
if (a === "create") {
|
|
6618
6628
|
let r = f.slug || n.slug || o, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
6619
6629
|
if (a) {
|
|
@@ -6640,7 +6650,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6640
6650
|
let e = b.map(() => "(?, ?)").join(", "), n = b.flatMap((e) => [u, e]);
|
|
6641
6651
|
await Q(t, `INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`, n);
|
|
6642
6652
|
}
|
|
6643
|
-
return
|
|
6653
|
+
return ji(e, async () => {
|
|
6644
6654
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6645
6655
|
}), e.json({
|
|
6646
6656
|
success: !0,
|
|
@@ -6670,7 +6680,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6670
6680
|
}
|
|
6671
6681
|
await Q(t, "DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?", [i, l]);
|
|
6672
6682
|
let r = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(i, l, m), a = Number(r.lastInsertRowid);
|
|
6673
|
-
return
|
|
6683
|
+
return ji(e, async () => {
|
|
6674
6684
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6675
6685
|
}), e.json({
|
|
6676
6686
|
success: !0,
|
|
@@ -6689,7 +6699,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6689
6699
|
r,
|
|
6690
6700
|
r,
|
|
6691
6701
|
i
|
|
6692
|
-
]),
|
|
6702
|
+
]), ji(e, async () => {
|
|
6693
6703
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6694
6704
|
}), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
|
|
6695
6705
|
}
|
|
@@ -6700,7 +6710,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6700
6710
|
details: t.message
|
|
6701
6711
|
}, 500);
|
|
6702
6712
|
}
|
|
6703
|
-
}),
|
|
6713
|
+
}), Ai.get("/trees.json", async (e) => {
|
|
6704
6714
|
try {
|
|
6705
6715
|
let t = e.get("db"), n = await Z(t, "SELECT * FROM trees ORDER BY LOWER(label) ASC"), r = (await Z(t, "SELECT channelId, treeId FROM channel_trees")).reduce((e, t) => {
|
|
6706
6716
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -6730,7 +6740,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6730
6740
|
} catch {
|
|
6731
6741
|
return e.json([]);
|
|
6732
6742
|
}
|
|
6733
|
-
}),
|
|
6743
|
+
}), Ai.post("/trees.json", async (e) => {
|
|
6734
6744
|
try {
|
|
6735
6745
|
let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, a = `tree-${Date.now().toString(36)}`, o = (n.key || n.slug || a).toLowerCase().replace(/[^a-z0-9_-]/g, "-"), s = n.label?.trim() || o, c = n.treeType !== void 0 && n.treeType !== null ? n.treeType : n.type ?? "site", l = n.channelId !== void 0 && n.channelId !== null && Number(n.channelId) || null, u = +(n.isHidden === !0 || n.isHidden === 1 || n.isHidden === "true"), d = e.get("user")?.id || null, f = { ...n };
|
|
6736
6746
|
if (delete f.id, delete f.key, delete f.label, delete f.treeType, delete f.type, delete f.channelId, delete f.channels, delete f.isHidden, delete f.createdById, delete f.updatedById, delete f.createdAt, delete f.updatedAt, (await Z(t, "SELECT id FROM trees WHERE key = ? AND id != ? LIMIT 1", [o, i ?? -1])).length > 0) return e.json({
|
|
@@ -6764,7 +6774,7 @@ ki.get("/tree.json", async (e) => {
|
|
|
6764
6774
|
await Q(t, `INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`, r);
|
|
6765
6775
|
}
|
|
6766
6776
|
}
|
|
6767
|
-
return
|
|
6777
|
+
return ji(e, async () => {
|
|
6768
6778
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6769
6779
|
}), e.json({
|
|
6770
6780
|
success: !0,
|
|
@@ -6780,12 +6790,12 @@ ki.get("/tree.json", async (e) => {
|
|
|
6780
6790
|
} catch (t) {
|
|
6781
6791
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
6782
6792
|
}
|
|
6783
|
-
}),
|
|
6793
|
+
}), Ai.delete("/trees.json", async (e) => {
|
|
6784
6794
|
let t = e.get("db"), n = e.req.query("id");
|
|
6785
6795
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
6786
6796
|
let r = Number(n);
|
|
6787
6797
|
try {
|
|
6788
|
-
return await Q(t, "DELETE FROM trees WHERE id = ?", [r]), await Q(t, "DELETE FROM channel_trees WHERE treeId = ?", [r]), await Q(t, "DELETE FROM tree_nodes WHERE treeId = ?", [r]),
|
|
6798
|
+
return await Q(t, "DELETE FROM trees WHERE id = ?", [r]), await Q(t, "DELETE FROM channel_trees WHERE treeId = ?", [r]), await Q(t, "DELETE FROM tree_nodes WHERE treeId = ?", [r]), ji(e, async () => {
|
|
6789
6799
|
await q(e).clear(), new J(e.env).purgeGlobalCache(e, t);
|
|
6790
6800
|
}), e.json({
|
|
6791
6801
|
success: !0,
|
|
@@ -6797,8 +6807,8 @@ ki.get("/tree.json", async (e) => {
|
|
|
6797
6807
|
});
|
|
6798
6808
|
//#endregion
|
|
6799
6809
|
//#region server/routes/admin/channels.ts
|
|
6800
|
-
var
|
|
6801
|
-
|
|
6810
|
+
var Fi = new e();
|
|
6811
|
+
Fi.get("/", async (e) => {
|
|
6802
6812
|
try {
|
|
6803
6813
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM channels ORDER BY id ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId, key, metaJson FROM channel_trees ORDER BY rowid ASC").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
|
|
6804
6814
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -6868,7 +6878,7 @@ Pi.get("/", async (e) => {
|
|
|
6868
6878
|
error: t.message
|
|
6869
6879
|
}, 500);
|
|
6870
6880
|
}
|
|
6871
|
-
}),
|
|
6881
|
+
}), Fi.post("/", async (e) => {
|
|
6872
6882
|
try {
|
|
6873
6883
|
let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, { key: a, label: o, channelType: s, domain: c, baseUrl: l, defaultLanguage: u, isHidden: d = !1, trees: f = [], createdById: p = null, updatedById: m = null, id: h, createdAt: g, updatedAt: _, ...v } = n, y = a?.trim() || "main", b = o?.trim() || "Untitled Channel", x = s ?? "website", S = c ?? "localhost", C = l ?? "http://localhost:4321", w = u ?? "en", T = JSON.stringify(v || {}), E = e.get("user")?.id || m || p, D = E === void 0 ? null : E;
|
|
6874
6884
|
if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
|
|
@@ -6908,7 +6918,7 @@ Pi.get("/", async (e) => {
|
|
|
6908
6918
|
details: t.message
|
|
6909
6919
|
}, 500);
|
|
6910
6920
|
}
|
|
6911
|
-
}),
|
|
6921
|
+
}), Fi.delete("/", async (e) => {
|
|
6912
6922
|
let t = e.get("db"), n = e.req.query("id");
|
|
6913
6923
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
6914
6924
|
let r = Number(n);
|
|
@@ -6926,7 +6936,7 @@ Pi.get("/", async (e) => {
|
|
|
6926
6936
|
});
|
|
6927
6937
|
//#endregion
|
|
6928
6938
|
//#region server/db/bundled-definitions.ts
|
|
6929
|
-
var
|
|
6939
|
+
var Ii = {
|
|
6930
6940
|
nodes: {
|
|
6931
6941
|
address: {
|
|
6932
6942
|
id: "address",
|
|
@@ -11624,11 +11634,11 @@ var Fi = {
|
|
|
11624
11634
|
treeTemplate: null,
|
|
11625
11635
|
channelTemplate: null,
|
|
11626
11636
|
userTemplate: null
|
|
11627
|
-
},
|
|
11637
|
+
}, Li = new e(), Ri = null, zi = (e) => {
|
|
11628
11638
|
try {
|
|
11629
11639
|
let t = typeof process < "u" && process.env.NODE_ENV !== "production";
|
|
11630
|
-
if (!
|
|
11631
|
-
let t = e.env?.BUNDLED_DEFINITIONS ||
|
|
11640
|
+
if (!Ri || t) {
|
|
11641
|
+
let t = e.env?.BUNDLED_DEFINITIONS || Ii || {}, n = e.get("schemas") || {}, r = e.get("schemas") || {}, i = r.channels || r.rawChannels || {}, a = r.nodes || r.rawNodes || {}, o = r.trees || r.rawTrees || {}, s = r.blocks || r.rawBlocks || {}, c = r.nodeLayouts || r.rawNodeLayouts || {}, l = r.blockLayouts || r.rawBlockLayouts || {}, u = t.rawChannels || t.channels || n.channels || {}, d = t.rawNodes || t.nodes || n.nodes || {}, f = t.rawTrees || t.trees || n.trees || {}, p = t.rawBlocks || t.blocks || n.blocks || {}, m = t.rawNodeLayouts || t.nodeLayouts || n.nodeLayouts || {}, h = t.rawBlockLayouts || t.blockLayouts || n.blockLayouts || {}, g = Object.keys(i).length > 0 ? i : u, _ = Object.keys(a).length > 0 ? a : d, v = Object.keys(o).length > 0 ? o : f, y = Object.keys(s).length > 0 ? s : p, b = Object.keys(c).length > 0 ? c : m, x = Object.keys(l).length > 0 ? l : h, S = n.userTemplate || {
|
|
11632
11642
|
id: "userTemplate",
|
|
11633
11643
|
label: "User Account",
|
|
11634
11644
|
fields: {
|
|
@@ -11664,7 +11674,7 @@ var Fi = {
|
|
|
11664
11674
|
}
|
|
11665
11675
|
}
|
|
11666
11676
|
}, C = Object.keys(g)[0];
|
|
11667
|
-
|
|
11677
|
+
Ri = {
|
|
11668
11678
|
channelTemplate: n.channelTemplate || (C ? g[C] : null),
|
|
11669
11679
|
treeTemplate: n.treeTemplate || null,
|
|
11670
11680
|
userTemplate: S,
|
|
@@ -11679,7 +11689,7 @@ var Fi = {
|
|
|
11679
11689
|
blockLayouts: x
|
|
11680
11690
|
};
|
|
11681
11691
|
}
|
|
11682
|
-
return e.json(
|
|
11692
|
+
return e.json(Ri, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
11683
11693
|
} catch (t) {
|
|
11684
11694
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
11685
11695
|
error: "Failed to load schemas",
|
|
@@ -11687,10 +11697,10 @@ var Fi = {
|
|
|
11687
11697
|
}, 500);
|
|
11688
11698
|
}
|
|
11689
11699
|
};
|
|
11690
|
-
|
|
11700
|
+
Li.get("/", zi), Li.get("/schemas.json", zi);
|
|
11691
11701
|
//#endregion
|
|
11692
11702
|
//#region server/routes/admin/validation.ts
|
|
11693
|
-
var
|
|
11703
|
+
var Bi = new e(), Vi = {
|
|
11694
11704
|
node: "content_nodes",
|
|
11695
11705
|
nodes: "content_nodes",
|
|
11696
11706
|
content_node: "content_nodes",
|
|
@@ -11702,7 +11712,7 @@ var zi = new e(), Bi = {
|
|
|
11702
11712
|
user: "users",
|
|
11703
11713
|
users: "users",
|
|
11704
11714
|
user_account: "user_accounts"
|
|
11705
|
-
},
|
|
11715
|
+
}, Hi = {
|
|
11706
11716
|
content_nodes: [
|
|
11707
11717
|
"id",
|
|
11708
11718
|
"title",
|
|
@@ -11759,11 +11769,11 @@ var zi = new e(), Bi = {
|
|
|
11759
11769
|
"createdAt"
|
|
11760
11770
|
]
|
|
11761
11771
|
};
|
|
11762
|
-
|
|
11772
|
+
Bi.post("/validate-unique", async (e) => {
|
|
11763
11773
|
try {
|
|
11764
11774
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
11765
11775
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
11766
|
-
let o =
|
|
11776
|
+
let o = Vi[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (Hi[o] || Hi.content_nodes).includes(s), l = -1;
|
|
11767
11777
|
if (a != null && String(a).trim() !== "") {
|
|
11768
11778
|
let e = Number(a);
|
|
11769
11779
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -11775,7 +11785,7 @@ zi.post("/validate-unique", async (e) => {
|
|
|
11775
11785
|
} catch (t) {
|
|
11776
11786
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
11777
11787
|
}
|
|
11778
|
-
}),
|
|
11788
|
+
}), Bi.post("/validate-unique-sibling", async (e) => {
|
|
11779
11789
|
try {
|
|
11780
11790
|
let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
|
|
11781
11791
|
if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
|
|
@@ -11803,8 +11813,8 @@ zi.post("/validate-unique", async (e) => {
|
|
|
11803
11813
|
});
|
|
11804
11814
|
//#endregion
|
|
11805
11815
|
//#region server/routes/admin/stats.ts
|
|
11806
|
-
var
|
|
11807
|
-
|
|
11816
|
+
var Ui = new e();
|
|
11817
|
+
Ui.get("/", async (e) => {
|
|
11808
11818
|
try {
|
|
11809
11819
|
let t = e.get("db"), n = await t.prepare("\n SELECT \n COUNT(*) as total,\n SUM(CASE WHEN isHidden = 0 THEN 1 ELSE 0 END) as published,\n SUM(CASE WHEN isHidden = 1 THEN 1 ELSE 0 END) as hidden\n FROM content_nodes\n ").get(), r = Number(n?.total) || 0, i = Number(n?.published) || 0, a = Number(n?.hidden) || 0, o = await t.prepare("\n SELECT \n (SELECT COUNT(*) FROM channels) as totalChannels,\n (SELECT COUNT(*) FROM trees) as totalTrees,\n (SELECT COUNT(*) FROM users) as totalUsers\n ").get(), s = await t.prepare("\n SELECT contentType as type, COUNT(*) as count \n FROM content_nodes \n GROUP BY contentType \n ORDER BY count DESC\n ").all(), c = Array.isArray(s) ? s : s?.results || [], l = await t.prepare("\n SELECT id, title, slug, contentType, isHidden, status, updatedAt \n FROM content_nodes \n ORDER BY updatedAt DESC \n LIMIT 5\n ").all(), u = (Array.isArray(l) ? l : l?.results || []).map((e) => ({
|
|
11810
11820
|
...e,
|
|
@@ -11849,7 +11859,7 @@ Hi.get("/", async (e) => {
|
|
|
11849
11859
|
});
|
|
11850
11860
|
//#endregion
|
|
11851
11861
|
//#region server/storage/provider.ts
|
|
11852
|
-
function
|
|
11862
|
+
function Wi(e) {
|
|
11853
11863
|
let t = e.split(".").pop()?.toLowerCase() || "bin";
|
|
11854
11864
|
return t = t.replace(/[^a-z0-9]/g, ""), [
|
|
11855
11865
|
"php",
|
|
@@ -11864,14 +11874,14 @@ function Ui(e) {
|
|
|
11864
11874
|
"cjs"
|
|
11865
11875
|
].includes(t) ? "bin" : t;
|
|
11866
11876
|
}
|
|
11867
|
-
var
|
|
11877
|
+
var Gi = class {
|
|
11868
11878
|
bucket;
|
|
11869
11879
|
publicDomain;
|
|
11870
11880
|
constructor(e, t) {
|
|
11871
11881
|
this.bucket = e, this.publicDomain = t;
|
|
11872
11882
|
}
|
|
11873
11883
|
async upload(e, t = "uploads") {
|
|
11874
|
-
let n =
|
|
11884
|
+
let n = Wi(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
|
|
11875
11885
|
return await this.bucket.put(r, e.stream(), { httpMetadata: { contentType: e.type } }), {
|
|
11876
11886
|
key: r,
|
|
11877
11887
|
url: `/media/${r.replace(/^\//, "")}`
|
|
@@ -11880,7 +11890,7 @@ var Wi = class {
|
|
|
11880
11890
|
async delete(e) {
|
|
11881
11891
|
await this.bucket.delete(e);
|
|
11882
11892
|
}
|
|
11883
|
-
},
|
|
11893
|
+
}, Ki = class {
|
|
11884
11894
|
customStoragePath;
|
|
11885
11895
|
constructor(e) {
|
|
11886
11896
|
this.customStoragePath = e;
|
|
@@ -11898,7 +11908,7 @@ var Wi = class {
|
|
|
11898
11908
|
), { pipeline: a } = await import(
|
|
11899
11909
|
/* @vite-ignore */
|
|
11900
11910
|
"node:stream/promises"
|
|
11901
|
-
), o =
|
|
11911
|
+
), o = Wi(e.name), s = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${o}`, c = this.customStoragePath || "./public/media", l = n.resolve(process.cwd(), c), u = n.join(l, s);
|
|
11902
11912
|
await i.mkdir(n.dirname(u), { recursive: !0 });
|
|
11903
11913
|
let d = r.createWriteStream(u);
|
|
11904
11914
|
return await a(e.stream(), d), {
|
|
@@ -11921,24 +11931,24 @@ var Wi = class {
|
|
|
11921
11931
|
}
|
|
11922
11932
|
}
|
|
11923
11933
|
};
|
|
11924
|
-
function
|
|
11934
|
+
function qi(e) {
|
|
11925
11935
|
if (e.MEDIA_BUCKET) {
|
|
11926
11936
|
let t = e.CDN_DOMAIN || "cdn.yourdomain.com";
|
|
11927
|
-
return new
|
|
11937
|
+
return new Gi(e.MEDIA_BUCKET, t);
|
|
11928
11938
|
}
|
|
11929
|
-
return new
|
|
11939
|
+
return new Ki(e.LOCAL_MEDIA_PATH);
|
|
11930
11940
|
}
|
|
11931
11941
|
//#endregion
|
|
11932
11942
|
//#region server/routes/admin/assets.ts
|
|
11933
|
-
var
|
|
11934
|
-
function
|
|
11943
|
+
var Ji = new e();
|
|
11944
|
+
function Yi(e, t) {
|
|
11935
11945
|
let n = e || (t ? `/media/${t}` : "");
|
|
11936
11946
|
try {
|
|
11937
11947
|
n.startsWith("http") && (n = new URL(n).pathname);
|
|
11938
11948
|
} catch {}
|
|
11939
11949
|
return n.startsWith("/media/") || (n = `/media/${n.replace(/^\/+/, "")}`), n;
|
|
11940
11950
|
}
|
|
11941
|
-
|
|
11951
|
+
Ji.get("/", async (e) => {
|
|
11942
11952
|
try {
|
|
11943
11953
|
let t = Xr(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: u } = e.req.query(), d = Math.max(1, parseInt(i, 10) || 1), f = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), p = (d - 1) * f, m = {
|
|
11944
11954
|
createdAt: "a.createdAt",
|
|
@@ -12008,7 +12018,7 @@ qi.get("/", async (e) => {
|
|
|
12008
12018
|
...JSON.parse(e.dataJson || "{}")
|
|
12009
12019
|
};
|
|
12010
12020
|
} catch {}
|
|
12011
|
-
let n =
|
|
12021
|
+
let n = Yi(e.cdnUrl, e.storageKeyPrivate);
|
|
12012
12022
|
return {
|
|
12013
12023
|
id: e.id,
|
|
12014
12024
|
filename: e.filename || "Untitled Asset",
|
|
@@ -12032,9 +12042,9 @@ qi.get("/", async (e) => {
|
|
|
12032
12042
|
details: t.message || String(t)
|
|
12033
12043
|
}, 500);
|
|
12034
12044
|
}
|
|
12035
|
-
}),
|
|
12045
|
+
}), Ji.post("/upload", async (e) => {
|
|
12036
12046
|
try {
|
|
12037
|
-
let t = Xr(e), n =
|
|
12047
|
+
let t = Xr(e), n = qi(e.env), r = await e.req.parseBody(), i = r.file, a = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", o = r.parentAssetId || r.parentAsset, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : null;
|
|
12038
12048
|
s && (await t.prepare("SELECT id FROM assets WHERE id = ?").all(s)).length === 0 && (s = null);
|
|
12039
12049
|
let c = r.cropCoordinates, l = null, u = null;
|
|
12040
12050
|
if (c) {
|
|
@@ -12055,7 +12065,7 @@ qi.get("/", async (e) => {
|
|
|
12055
12065
|
let w = v;
|
|
12056
12066
|
if (s) {
|
|
12057
12067
|
let n = await t.prepare("SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?").all(s);
|
|
12058
|
-
n.length > 0 && (w =
|
|
12068
|
+
n.length > 0 && (w = Yi(n[0].cdnUrl, n[0].storageKeyPrivate)), new J(e.env).purgeAsset(e, t, s);
|
|
12059
12069
|
}
|
|
12060
12070
|
return e.json({
|
|
12061
12071
|
id: f,
|
|
@@ -12074,7 +12084,7 @@ qi.get("/", async (e) => {
|
|
|
12074
12084
|
details: t.message || String(t)
|
|
12075
12085
|
}, 500);
|
|
12076
12086
|
}
|
|
12077
|
-
}),
|
|
12087
|
+
}), Ji.get("/:id/details", async (e) => {
|
|
12078
12088
|
try {
|
|
12079
12089
|
let t = Xr(e), n = e.req.param("id"), r = await t.prepare("SELECT * FROM assets WHERE id = ?").all(n);
|
|
12080
12090
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -12089,7 +12099,7 @@ qi.get("/", async (e) => {
|
|
|
12089
12099
|
...JSON.parse(i.dataJson || "{}")
|
|
12090
12100
|
};
|
|
12091
12101
|
} catch {}
|
|
12092
|
-
let l =
|
|
12102
|
+
let l = Yi(i.cdnUrl, i.storageKeyPrivate);
|
|
12093
12103
|
return e.json({
|
|
12094
12104
|
id: i.id,
|
|
12095
12105
|
filename: i.filename,
|
|
@@ -12116,7 +12126,7 @@ qi.get("/", async (e) => {
|
|
|
12116
12126
|
createdAt: e.createdAt,
|
|
12117
12127
|
parentAssetId: e.parentAssetId || i.id,
|
|
12118
12128
|
cropCoordinates: t,
|
|
12119
|
-
url:
|
|
12129
|
+
url: Yi(e.cdnUrl, e.storageKeyPrivate),
|
|
12120
12130
|
originalUrl: l
|
|
12121
12131
|
};
|
|
12122
12132
|
})
|
|
@@ -12124,7 +12134,7 @@ qi.get("/", async (e) => {
|
|
|
12124
12134
|
} catch (t) {
|
|
12125
12135
|
return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
|
|
12126
12136
|
}
|
|
12127
|
-
}),
|
|
12137
|
+
}), Ji.put("/:id", async (e) => {
|
|
12128
12138
|
try {
|
|
12129
12139
|
let t = Xr(e), n = e.req.param("id"), r = await e.req.json(), i = await t.prepare("SELECT filename, dataJson FROM assets WHERE id = ?").all(n);
|
|
12130
12140
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -12138,7 +12148,7 @@ qi.get("/", async (e) => {
|
|
|
12138
12148
|
} catch (t) {
|
|
12139
12149
|
return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
|
|
12140
12150
|
}
|
|
12141
|
-
}),
|
|
12151
|
+
}), Ji.delete("/:id", async (e) => {
|
|
12142
12152
|
try {
|
|
12143
12153
|
let t = Xr(e), n = e.req.param("id"), r = (await t.prepare("SELECT id, filename, isSystemVariant FROM assets WHERE id = ?").all(n))[0];
|
|
12144
12154
|
if (!r) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -12158,7 +12168,7 @@ qi.get("/", async (e) => {
|
|
|
12158
12168
|
details: t.message || String(t)
|
|
12159
12169
|
}, 500);
|
|
12160
12170
|
}
|
|
12161
|
-
}),
|
|
12171
|
+
}), Ji.post("/restore", async (e) => {
|
|
12162
12172
|
try {
|
|
12163
12173
|
let t = Xr(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
12164
12174
|
if (!r) return e.json({ error: "Asset ID required" }, 400);
|
|
@@ -12176,9 +12186,9 @@ qi.get("/", async (e) => {
|
|
|
12176
12186
|
details: t.message
|
|
12177
12187
|
}, 500);
|
|
12178
12188
|
}
|
|
12179
|
-
}),
|
|
12189
|
+
}), Ji.delete("/purge/:id", async (e) => {
|
|
12180
12190
|
try {
|
|
12181
|
-
let t = Xr(e), n =
|
|
12191
|
+
let t = Xr(e), n = qi(e.env), r = e.req.param("id"), i = (await t.prepare("SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?").all(r))[0];
|
|
12182
12192
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
12183
12193
|
new J(e.env).purgeAsset(e, t, r);
|
|
12184
12194
|
let a = [i];
|
|
@@ -12211,14 +12221,14 @@ qi.get("/", async (e) => {
|
|
|
12211
12221
|
});
|
|
12212
12222
|
//#endregion
|
|
12213
12223
|
//#region server/routes/public/node.ts
|
|
12214
|
-
var
|
|
12215
|
-
function
|
|
12224
|
+
var Xi = new e();
|
|
12225
|
+
function Zi(e, t) {
|
|
12216
12226
|
let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
|
|
12217
12227
|
try {
|
|
12218
12228
|
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
12219
12229
|
} catch {}
|
|
12220
12230
|
}
|
|
12221
|
-
function
|
|
12231
|
+
function Qi() {
|
|
12222
12232
|
return {
|
|
12223
12233
|
fullPath: /* @__PURE__ */ new Map(),
|
|
12224
12234
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -12226,15 +12236,15 @@ function Zi() {
|
|
|
12226
12236
|
assetUrls: /* @__PURE__ */ new Map()
|
|
12227
12237
|
};
|
|
12228
12238
|
}
|
|
12229
|
-
function
|
|
12239
|
+
function $i(...e) {
|
|
12230
12240
|
return e.map((e) => String(e ?? "")).join(":");
|
|
12231
12241
|
}
|
|
12232
|
-
function
|
|
12242
|
+
function ea(e) {
|
|
12233
12243
|
if (!e || String(e).trim() === "") return null;
|
|
12234
12244
|
let t = new Date(e.includes("T") ? e : e.replace(" ", "T") + "Z");
|
|
12235
12245
|
return isNaN(t.getTime()) ? e : t.toISOString();
|
|
12236
12246
|
}
|
|
12237
|
-
function
|
|
12247
|
+
function ta(e, t) {
|
|
12238
12248
|
let n = Date.now();
|
|
12239
12249
|
if (e && String(e).trim() !== "") {
|
|
12240
12250
|
let t = Date.parse(e);
|
|
@@ -12246,7 +12256,7 @@ function ea(e, t) {
|
|
|
12246
12256
|
}
|
|
12247
12257
|
return !0;
|
|
12248
12258
|
}
|
|
12249
|
-
async function
|
|
12259
|
+
async function na(e, t, n) {
|
|
12250
12260
|
let r = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list");
|
|
12251
12261
|
await Promise.all(r.map(async (t) => {
|
|
12252
12262
|
let r = t.data || {}, i = r.nodeType || "article", a = Number(r.limit) || 12, o = r.sortBy || "updatedAt", s = "FROM content_nodes WHERE contentType = ? AND isHidden = 0 AND (status = 'published' OR status IS NULL)", c = [i];
|
|
@@ -12260,13 +12270,13 @@ async function ta(e, t, n) {
|
|
|
12260
12270
|
if (e.dataJson) try {
|
|
12261
12271
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
12262
12272
|
} catch {}
|
|
12263
|
-
return
|
|
12273
|
+
return ta(t.startShowingAt, t.stopShowingAt) ? {
|
|
12264
12274
|
id: e.id,
|
|
12265
12275
|
title: e.title,
|
|
12266
12276
|
slug: e.slug,
|
|
12267
12277
|
language: e.language || "en",
|
|
12268
|
-
createdAt:
|
|
12269
|
-
updatedAt:
|
|
12278
|
+
createdAt: ea(e.createdAt),
|
|
12279
|
+
updatedAt: ea(e.updatedAt),
|
|
12270
12280
|
excerpt: t.excerpt || "",
|
|
12271
12281
|
image: t.image || t.coverImage || null,
|
|
12272
12282
|
author: t.author || null
|
|
@@ -12277,7 +12287,7 @@ async function ta(e, t, n) {
|
|
|
12277
12287
|
}
|
|
12278
12288
|
}));
|
|
12279
12289
|
}
|
|
12280
|
-
async function
|
|
12290
|
+
async function ra(e, t, n, r, i = !1, a) {
|
|
12281
12291
|
if (!t || t === "0" || t === 0 || t === "null") return { blocks: [] };
|
|
12282
12292
|
try {
|
|
12283
12293
|
let o = await Promise.resolve(e.prepare("\n WITH RECURSIVE ancestor_path(id, contentId, title, slug, parentId, level) AS (\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, 0 \n FROM tree_nodes t \n INNER JOIN content_nodes c ON t.contentId = c.id \n WHERE t.id = ? OR c.id = ?\n \n UNION ALL\n \n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 \n FROM tree_nodes t \n INNER JOIN content_nodes c ON t.contentId = c.id \n INNER JOIN ancestor_path ap ON t.id = ap.parentId\n WHERE ap.parentId IS NOT NULL AND ap.parentId != 0 AND ap.parentId != '0' AND ap.parentId != 'null' AND ap.level < 20\n ) SELECT * FROM ancestor_path ORDER BY level ASC\n ").all(t, t));
|
|
@@ -12317,9 +12327,9 @@ async function na(e, t, n, r, i = !1, a) {
|
|
|
12317
12327
|
try {
|
|
12318
12328
|
t = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
12319
12329
|
} catch {}
|
|
12320
|
-
let n = t.hidden === !0 || t.hidden === 1 || t.hidden === "1" || t.hidden === "true", a =
|
|
12330
|
+
let n = t.hidden === !0 || t.hidden === 1 || t.hidden === "1" || t.hidden === "true", a = ta(t.startShowingAt, t.stopShowingAt);
|
|
12321
12331
|
if (!i && (n || !a)) continue;
|
|
12322
|
-
let o = e.elementType || e.componentId || "text-block", s = r.blocks?.[o]?.fields || r.elements?.[o]?.fields || r.components?.[o]?.fields || {}, c = String(t.blockId || t._instanceId || (t.id && !String(t.id).startsWith("ast_") ? t.id : null) || e.blockId || e.id), l =
|
|
12332
|
+
let o = e.elementType || e.componentId || "text-block", s = r.blocks?.[o]?.fields || r.elements?.[o]?.fields || r.components?.[o]?.fields || {}, c = String(t.blockId || t._instanceId || (t.id && !String(t.id).startsWith("ast_") ? t.id : null) || e.blockId || e.id), l = ia(t, s);
|
|
12323
12333
|
u.push({
|
|
12324
12334
|
original: e,
|
|
12325
12335
|
data: l,
|
|
@@ -12328,7 +12338,7 @@ async function na(e, t, n, r, i = !1, a) {
|
|
|
12328
12338
|
});
|
|
12329
12339
|
}
|
|
12330
12340
|
let d = u.map((e) => e.data);
|
|
12331
|
-
d.length > 0 && (d = await ii(e, d), d =
|
|
12341
|
+
d.length > 0 && (d = await ii(e, d), d = aa(d), a && (d = await sa(e, d, a)));
|
|
12332
12342
|
let m = {};
|
|
12333
12343
|
for (let e = 0; e < u.length; e++) {
|
|
12334
12344
|
let t = u[e], r = d[e];
|
|
@@ -12353,7 +12363,7 @@ async function na(e, t, n, r, i = !1, a) {
|
|
|
12353
12363
|
}
|
|
12354
12364
|
return { blocks: [] };
|
|
12355
12365
|
}
|
|
12356
|
-
function
|
|
12366
|
+
function ia(e, t = {}) {
|
|
12357
12367
|
let n = {};
|
|
12358
12368
|
for (let [r, i] of Object.entries(e)) {
|
|
12359
12369
|
if (r === "id" && typeof i == "string" && i.startsWith("ast_")) {
|
|
@@ -12364,14 +12374,14 @@ function ra(e, t = {}) {
|
|
|
12364
12374
|
}
|
|
12365
12375
|
return n;
|
|
12366
12376
|
}
|
|
12367
|
-
function
|
|
12368
|
-
if (Array.isArray(e)) return e.map(
|
|
12377
|
+
function aa(e) {
|
|
12378
|
+
if (Array.isArray(e)) return e.map(aa);
|
|
12369
12379
|
if (!e || typeof e != "object") return e;
|
|
12370
12380
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
12371
12381
|
let t = e.metadataOverrides || {}, n = e.variants && typeof e.variants == "object" ? e.variants : {}, r = Object.entries(n).find(([, t]) => t?.id === e.id)?.[0], i = r ? {
|
|
12372
12382
|
...t,
|
|
12373
12383
|
...t.crops?.[r] || {}
|
|
12374
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
12384
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, aa({
|
|
12375
12385
|
...n,
|
|
12376
12386
|
title: n?.title ?? e.title ?? "",
|
|
12377
12387
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -12385,20 +12395,20 @@ function ia(e) {
|
|
|
12385
12395
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
12386
12396
|
};
|
|
12387
12397
|
}
|
|
12388
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
12398
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, aa(t)]));
|
|
12389
12399
|
}
|
|
12390
|
-
var
|
|
12391
|
-
async function
|
|
12400
|
+
var oa = /#node:|data-node-id|#asset:|data-asset-id/i;
|
|
12401
|
+
async function sa(e, t, n) {
|
|
12392
12402
|
if (!t) return t;
|
|
12393
12403
|
let r = JSON.stringify(t);
|
|
12394
|
-
if (!
|
|
12404
|
+
if (!oa.test(r)) return t;
|
|
12395
12405
|
let i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = (e, t) => {
|
|
12396
12406
|
let n = e.match(RegExp(`\\b${t}\\s*=\\s*(["'])(.*?)\\1`, "i"));
|
|
12397
12407
|
return n ? n[2] : void 0;
|
|
12398
12408
|
}, c = (e) => {
|
|
12399
12409
|
if (e) {
|
|
12400
12410
|
if (typeof e == "string") {
|
|
12401
|
-
if (!
|
|
12411
|
+
if (!oa.test(e)) return;
|
|
12402
12412
|
for (let t of e.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi)) i.add(t[1]);
|
|
12403
12413
|
for (let t of e.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi)) a.add(t[1]);
|
|
12404
12414
|
for (let t of e.matchAll(/<a\s+([^>]+)>/gi)) {
|
|
@@ -12436,15 +12446,15 @@ async function oa(e, t, n) {
|
|
|
12436
12446
|
}
|
|
12437
12447
|
let d = /* @__PURE__ */ new Map();
|
|
12438
12448
|
await Promise.all(Array.from(o).map(async (t) => {
|
|
12439
|
-
let [r, i] = t.split(":"), a = await
|
|
12449
|
+
let [r, i] = t.split(":"), a = await ca(e, r, i, n);
|
|
12440
12450
|
if (a?.treeNodeId) {
|
|
12441
|
-
let r = await
|
|
12451
|
+
let r = await ua(e, String(a.treeNodeId), i, n);
|
|
12442
12452
|
d.set(t, r);
|
|
12443
12453
|
}
|
|
12444
12454
|
}));
|
|
12445
12455
|
let f = (e) => {
|
|
12446
12456
|
if (!e) return e;
|
|
12447
|
-
if (typeof e == "string") return
|
|
12457
|
+
if (typeof e == "string") return oa.test(e) ? e.replace(/<a\s+([^>]+)>/gi, (e, t) => {
|
|
12448
12458
|
let n = s(t, "data-node-id"), r = s(t, "data-asset-id"), i = s(t, "href") || "";
|
|
12449
12459
|
if (i.startsWith("mailto:")) return `<a ${t.replace(/\s+target\s*=\s*["'][^"']*["']/i, "")}>`;
|
|
12450
12460
|
let a = r || i.match(/^#asset:(.+)$/i)?.[1], o = n || i.match(/^#node:(.+)$/i)?.[1];
|
|
@@ -12482,13 +12492,13 @@ async function oa(e, t, n) {
|
|
|
12482
12492
|
};
|
|
12483
12493
|
return f(t);
|
|
12484
12494
|
}
|
|
12485
|
-
async function
|
|
12486
|
-
let i =
|
|
12495
|
+
async function ca(e, t, n, r) {
|
|
12496
|
+
let i = $i(t, n);
|
|
12487
12497
|
if (r.treeEdges.has(i)) return r.treeEdges.get(i);
|
|
12488
12498
|
let a = Promise.resolve(e.prepare("SELECT id as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n));
|
|
12489
12499
|
return r.treeEdges.set(i, a), a;
|
|
12490
12500
|
}
|
|
12491
|
-
function
|
|
12501
|
+
function la(e) {
|
|
12492
12502
|
let t = e.socialImage;
|
|
12493
12503
|
if (!t || typeof t != "object") return null;
|
|
12494
12504
|
let n = (e, t) => {
|
|
@@ -12519,9 +12529,9 @@ function ca(e) {
|
|
|
12519
12529
|
])
|
|
12520
12530
|
};
|
|
12521
12531
|
}
|
|
12522
|
-
async function
|
|
12532
|
+
async function ua(e, t, n, r) {
|
|
12523
12533
|
if (!t || t === "0" || t === "null") return "/home";
|
|
12524
|
-
let i =
|
|
12534
|
+
let i = $i(t, n);
|
|
12525
12535
|
if (r && r.fullPath.has(i)) return r.fullPath.get(i);
|
|
12526
12536
|
let a = (async () => {
|
|
12527
12537
|
try {
|
|
@@ -12539,7 +12549,7 @@ async function la(e, t, n, r) {
|
|
|
12539
12549
|
})();
|
|
12540
12550
|
return r && r.fullPath.set(i, a), a;
|
|
12541
12551
|
}
|
|
12542
|
-
async function
|
|
12552
|
+
async function da(e, t, n, r, i) {
|
|
12543
12553
|
let a = {}, o = null;
|
|
12544
12554
|
if (t && t !== "0" && t !== 0 && t !== "null") try {
|
|
12545
12555
|
let n = await Promise.resolve(e.prepare("\n WITH RECURSIVE ancestor_path(id, contentId, title, slug, parentId, level) AS (\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, 0 \n FROM tree_nodes t \n INNER JOIN content_nodes c ON t.contentId = c.id \n WHERE t.id = ? OR c.id = ?\n \n UNION ALL\n \n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 \n FROM tree_nodes t \n INNER JOIN content_nodes c ON t.contentId = c.id \n INNER JOIN ancestor_path ap ON t.id = ap.parentId\n WHERE ap.parentId IS NOT NULL AND ap.parentId != 0 AND ap.parentId != '0' AND ap.parentId != 'null' AND ap.level < 20\n ) SELECT c.dataJson, c.draftDataJson FROM ancestor_path ap INNER JOIN content_nodes c ON ap.contentId = c.id ORDER BY ap.level ASC\n ").all(t, t)), i = /* @__PURE__ */ new Set([
|
|
@@ -12579,13 +12589,13 @@ async function ua(e, t, n, r, i) {
|
|
|
12579
12589
|
inheritedFields: a
|
|
12580
12590
|
};
|
|
12581
12591
|
}
|
|
12582
|
-
function
|
|
12592
|
+
function fa(e) {
|
|
12583
12593
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
12584
12594
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
12585
12595
|
}
|
|
12586
|
-
|
|
12596
|
+
Xi.get("/*", async (e) => {
|
|
12587
12597
|
try {
|
|
12588
|
-
let t = e.get("db"), n =
|
|
12598
|
+
let t = e.get("db"), n = Qi(), r = new URL(e.req.url).pathname.match(/\/node\/(.+)$/), i = (r ? r[1] : "home").replace(/^\/+|\/+$/g, ""), a = e.req.query("channelId") || e.req.query("channel") || "1", o = e.req.query("lang") || "en", s = e.req.query("preview") === "true", c = isNaN(Number(a)) ? await Promise.resolve(t.prepare("SELECT * FROM channels WHERE key = ?").get(a)) : await Promise.resolve(t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(a)));
|
|
12589
12599
|
if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
|
|
12590
12600
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
12591
12601
|
if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
|
|
@@ -12604,7 +12614,7 @@ Yi.get("/*", async (e) => {
|
|
|
12604
12614
|
if (T.length > 0) {
|
|
12605
12615
|
let e = await Promise.all(T.map(async (e) => ({
|
|
12606
12616
|
candidate: e,
|
|
12607
|
-
calculatedPath: await
|
|
12617
|
+
calculatedPath: await ua(t, String(e.treeNodeId), String(e.treeId), n)
|
|
12608
12618
|
}))), r = S.replace(/^\/+|\/+$/g, "");
|
|
12609
12619
|
for (let { candidate: t, calculatedPath: n } of e) {
|
|
12610
12620
|
let e = n.replace(/^\/+|\/+$/g, "");
|
|
@@ -12619,7 +12629,7 @@ Yi.get("/*", async (e) => {
|
|
|
12619
12629
|
let e = `SELECT id as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${y ? "AND treeId = ?" : ""} LIMIT 1`, n = y ? [_.id, y] : [_.id];
|
|
12620
12630
|
v = await Promise.resolve(t.prepare(e).get(...n));
|
|
12621
12631
|
}
|
|
12622
|
-
let E = v?.treeId || y || "main-nav", D = v?.parentId || null, O = v?.treeNodeId ? await
|
|
12632
|
+
let E = v?.treeId || y || "main-nav", D = v?.parentId || null, O = v?.treeNodeId ? await ua(t, String(v.treeNodeId), String(E), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, k = {}, ee = s && _.draftDataJson ? _.draftDataJson : _.dataJson || _.draftDataJson;
|
|
12623
12633
|
if (ee) try {
|
|
12624
12634
|
k = typeof ee == "string" ? JSON.parse(ee) : ee;
|
|
12625
12635
|
} catch {}
|
|
@@ -12637,7 +12647,7 @@ Yi.get("/*", async (e) => {
|
|
|
12637
12647
|
WHERE t.parentId = ? AND t.treeId = ?
|
|
12638
12648
|
ORDER BY t.sortOrder ASC
|
|
12639
12649
|
`, [j, se, ce] = await Promise.all([
|
|
12640
|
-
|
|
12650
|
+
da(t, D, E, s, A),
|
|
12641
12651
|
v?.treeNodeId ? Promise.resolve(t.prepare(oe).all(v.treeNodeId, E)) : Promise.resolve([]),
|
|
12642
12652
|
Promise.resolve(t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(_.id, ie))
|
|
12643
12653
|
]), { resolvedLayoutId: le, inheritedFields: ue } = j, M = {
|
|
@@ -12646,10 +12656,10 @@ Yi.get("/*", async (e) => {
|
|
|
12646
12656
|
slug: _.slug,
|
|
12647
12657
|
path: O === "" ? "/" : O,
|
|
12648
12658
|
nodeType: te,
|
|
12649
|
-
createdAt:
|
|
12650
|
-
updatedAt:
|
|
12651
|
-
publishedAt:
|
|
12652
|
-
}, de = k.disabledRegions || {}, fe = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", pe = k.startShowingAt || null, me = k.stopShowingAt || null, N =
|
|
12659
|
+
createdAt: ea(_.createdAt),
|
|
12660
|
+
updatedAt: ea(_.updatedAt),
|
|
12661
|
+
publishedAt: ea(k.publishedAt || _.createdAt)
|
|
12662
|
+
}, de = k.disabledRegions || {}, fe = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", pe = k.startShowingAt || null, me = k.stopShowingAt || null, N = ia(k, A), he = N.layoutId || null, ge = he && he !== "inherit", P = !1, F = null;
|
|
12653
12663
|
A.layoutId && (P = !0, A.layoutId.options && Array.isArray(A.layoutId.options) && (F = A.layoutId.options.map((e) => typeof e == "object" ? e.value || e.id : e)));
|
|
12654
12664
|
let _e = null;
|
|
12655
12665
|
if (P && F && F.length === 1 && F[0] !== "inherit") _e = F[0];
|
|
@@ -12659,13 +12669,13 @@ Yi.get("/*", async (e) => {
|
|
|
12659
12669
|
_e = e && e !== "inherit" && (!F || F.includes(e) || F.includes("inherit")) ? e : re.defaultLayout || null;
|
|
12660
12670
|
}
|
|
12661
12671
|
for (let [e, t] of Object.entries(ue)) A[e] && (N[e] === void 0 || N[e] === null || N[e] === "" || N[e] === "inherit") && t !== void 0 && (N[e] = t);
|
|
12662
|
-
let ve = Number(_.isHidden) === 1 || fe, ye = !
|
|
12672
|
+
let ve = Number(_.isHidden) === 1 || fe, ye = !ta(pe, me);
|
|
12663
12673
|
if (!s && (ve || ye)) return e.json({ error: "Node is hidden or outside its scheduled publishing window" }, 404);
|
|
12664
12674
|
let be = [];
|
|
12665
12675
|
if (v?.treeNodeId) {
|
|
12666
12676
|
let e = M.path === "/" ? "" : M.path;
|
|
12667
12677
|
be = (se || []).map((t) => {
|
|
12668
|
-
let n = Number(t.isHidden) === 1 || t.extHidden === 1 || t.extHidden === "1" || t.extHidden === "true" || t.extHidden === !0, r =
|
|
12678
|
+
let n = Number(t.isHidden) === 1 || t.extHidden === 1 || t.extHidden === "1" || t.extHidden === "true" || t.extHidden === !0, r = ta(t.extStart, t.extStop), i = (t.slug || "").replace(/^\/+|\/+$/g, "");
|
|
12669
12679
|
return !s && (n || !r) ? null : {
|
|
12670
12680
|
treeNodeId: t.treeNodeId,
|
|
12671
12681
|
id: t.id,
|
|
@@ -12686,9 +12696,9 @@ Yi.get("/*", async (e) => {
|
|
|
12686
12696
|
try {
|
|
12687
12697
|
n = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
12688
12698
|
} catch {}
|
|
12689
|
-
let r = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", i =
|
|
12699
|
+
let r = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", i = ta(n.startShowingAt, n.stopShowingAt);
|
|
12690
12700
|
if (!s && (r || !i)) continue;
|
|
12691
|
-
let a = e.elementType || e.componentId || "text-block", o = h.blocks?.[a]?.fields || h.elements?.[a]?.fields || h.components?.[a]?.fields || {}, c = String(n.blockId || n._instanceId || (n.id && !String(n.id).startsWith("ast_") ? n.id : null) || e.blockId || e.id), l =
|
|
12701
|
+
let a = e.elementType || e.componentId || "text-block", o = h.blocks?.[a]?.fields || h.elements?.[a]?.fields || h.components?.[a]?.fields || {}, c = String(n.blockId || n._instanceId || (n.id && !String(n.id).startsWith("ast_") ? n.id : null) || e.blockId || e.id), l = ia(n, o);
|
|
12692
12702
|
Ce.push({
|
|
12693
12703
|
original: e,
|
|
12694
12704
|
region: t,
|
|
@@ -12701,8 +12711,8 @@ Yi.get("/*", async (e) => {
|
|
|
12701
12711
|
node: N,
|
|
12702
12712
|
blocks: Ce.map((e) => e.data)
|
|
12703
12713
|
});
|
|
12704
|
-
L =
|
|
12705
|
-
let R = L.node, we =
|
|
12714
|
+
L = aa(L), L = await sa(t, L, n);
|
|
12715
|
+
let R = L.node, we = la(R);
|
|
12706
12716
|
delete R.socialImage, delete R.fbImage, delete R.xImage, delete R.whatsappImage, we && (R.socialImages = we), delete R.id, delete R.title, delete R.slug, delete R.language, delete R.contentType, delete R.nodeType, delete R.createdAt, delete R.updatedAt, delete R.publishedAt, delete R.channelId, delete R.treeId, delete R.path, R.iconName === "" && (R.iconName = null), Object.assign(M, R), re.hasCanvas && (M.layoutId = _e);
|
|
12707
12717
|
for (let e = 0; e < Ce.length; e++) {
|
|
12708
12718
|
let t = Ce[e], n = L.blocks[e];
|
|
@@ -12727,7 +12737,7 @@ Yi.get("/*", async (e) => {
|
|
|
12727
12737
|
for (let [e, r] of Object.entries(Te)) {
|
|
12728
12738
|
let i = I[e] && I[e].length > 0, a = !!de[e];
|
|
12729
12739
|
if (I[e] || (I[e] = [], Se[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && D) {
|
|
12730
|
-
let r = await
|
|
12740
|
+
let r = await ra(t, D, e, h, s, n);
|
|
12731
12741
|
if (r.blocks.length > 0 && (I[e] = r.blocks, Se[e] = {
|
|
12732
12742
|
isInherited: !0,
|
|
12733
12743
|
inheritedFromId: r.inheritedFromId,
|
|
@@ -12739,7 +12749,7 @@ Yi.get("/*", async (e) => {
|
|
|
12739
12749
|
});
|
|
12740
12750
|
}
|
|
12741
12751
|
}
|
|
12742
|
-
await Promise.all(Object.keys(I).map((e) =>
|
|
12752
|
+
await Promise.all(Object.keys(I).map((e) => na(t, I[e], u)));
|
|
12743
12753
|
let Ee = {
|
|
12744
12754
|
channelId: u || d,
|
|
12745
12755
|
treeId: E,
|
|
@@ -12748,7 +12758,7 @@ Yi.get("/*", async (e) => {
|
|
|
12748
12758
|
content: I,
|
|
12749
12759
|
regionMeta: Se
|
|
12750
12760
|
};
|
|
12751
|
-
return !s && !m ? (e.header("X-Cache", "MISS"),
|
|
12761
|
+
return !s && !m ? (e.header("X-Cache", "MISS"), Zi(e, f.set(p, Ee, fa(e)))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(Ee);
|
|
12752
12762
|
} catch (t) {
|
|
12753
12763
|
console.error("[CMS Public API] Error fetching node by path:", t);
|
|
12754
12764
|
let n = e.env?.ENVIRONMENT === "development";
|
|
@@ -12760,14 +12770,14 @@ Yi.get("/*", async (e) => {
|
|
|
12760
12770
|
});
|
|
12761
12771
|
//#endregion
|
|
12762
12772
|
//#region server/routes/public/tree.ts
|
|
12763
|
-
var
|
|
12764
|
-
function
|
|
12773
|
+
var pa = new e();
|
|
12774
|
+
function ma(e, t) {
|
|
12765
12775
|
let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
|
|
12766
12776
|
try {
|
|
12767
12777
|
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
12768
12778
|
} catch {}
|
|
12769
12779
|
}
|
|
12770
|
-
function
|
|
12780
|
+
function ha(e, t) {
|
|
12771
12781
|
let n = /* @__PURE__ */ new Date();
|
|
12772
12782
|
if (e && String(e).trim() !== "") {
|
|
12773
12783
|
let t = new Date(e);
|
|
@@ -12779,7 +12789,7 @@ function ma(e, t) {
|
|
|
12779
12789
|
}
|
|
12780
12790
|
return !0;
|
|
12781
12791
|
}
|
|
12782
|
-
|
|
12792
|
+
pa.get("/:treeParam", async (e) => {
|
|
12783
12793
|
try {
|
|
12784
12794
|
let t = e.get("db"), n = e.req.param("treeParam"), r = e.req.query("channelId") || e.req.query("channel") || "default", i = e.req.query("preview") === "true";
|
|
12785
12795
|
if (r && r !== "default" && r !== "all") {
|
|
@@ -12843,7 +12853,7 @@ fa.get("/:treeParam", async (e) => {
|
|
|
12843
12853
|
if (r.has(a)) return console.warn(`[CMS] Cycle detected for treeNodeId: ${a}. Aborting branch.`), null;
|
|
12844
12854
|
let o = new Set(r);
|
|
12845
12855
|
o.add(a);
|
|
12846
|
-
let s = !i && (e.status === "draft" || e.status === "new"), c = e.extHidden === 1 || e.extHidden === !0 || e.extHidden === "true" || e.extHidden === "1", l = Number(e.isHidden) === 1 || s || c, u =
|
|
12856
|
+
let s = !i && (e.status === "draft" || e.status === "new"), c = e.extHidden === 1 || e.extHidden === !0 || e.extHidden === "true" || e.extHidden === "1", l = Number(e.isHidden) === 1 || s || c, u = ha(e.extStart, e.extStop), d = (e.slug || "").replace(/^\/+|\/+$/g, ""), f = (!e.parentId || e.parentId === "null" || e.parentId === "") && (d === "home" || d === "homee") ? "/" : `${t}/${d}`.replace(/\/+/g, "/"), p = {
|
|
12847
12857
|
id: e.id,
|
|
12848
12858
|
treeNodeId: e.treeNodeId,
|
|
12849
12859
|
parentId: e.parentId || null,
|
|
@@ -12868,7 +12878,7 @@ fa.get("/:treeParam", async (e) => {
|
|
|
12868
12878
|
...p,
|
|
12869
12879
|
items: h(null)
|
|
12870
12880
|
};
|
|
12871
|
-
return !i && !s ? (e.header("X-Cache", "MISS"),
|
|
12881
|
+
return !i && !s ? (e.header("X-Cache", "MISS"), ma(e, a.set(o, g, 300))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(g);
|
|
12872
12882
|
} catch (t) {
|
|
12873
12883
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
12874
12884
|
error: "Failed to fetch public tree",
|
|
@@ -12878,8 +12888,8 @@ fa.get("/:treeParam", async (e) => {
|
|
|
12878
12888
|
});
|
|
12879
12889
|
//#endregion
|
|
12880
12890
|
//#region server/routes/public/assets.ts
|
|
12881
|
-
var
|
|
12882
|
-
function
|
|
12891
|
+
var ga = new e();
|
|
12892
|
+
function _a(e, t) {
|
|
12883
12893
|
if (t === "webp") return "image/webp";
|
|
12884
12894
|
if (t === "avif") return "image/avif";
|
|
12885
12895
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -12887,7 +12897,7 @@ function ga(e, t) {
|
|
|
12887
12897
|
let n = e.toLowerCase();
|
|
12888
12898
|
return n.endsWith(".jpg") || n.endsWith(".jpeg") ? "image/jpeg" : n.endsWith(".png") ? "image/png" : n.endsWith(".webp") ? "image/webp" : n.endsWith(".gif") ? "image/gif" : n.endsWith(".svg") ? "image/svg+xml" : n.endsWith(".pdf") ? "application/pdf" : n.endsWith(".mp4") ? "video/mp4" : n.endsWith(".webm") ? "video/webm" : "application/octet-stream";
|
|
12889
12899
|
}
|
|
12890
|
-
|
|
12900
|
+
ga.get("/*", async (e) => {
|
|
12891
12901
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
12892
12902
|
if (!t) return e.text("Asset key missing", 400);
|
|
12893
12903
|
let n = e.env?.MEDIA_BUCKET, { w: r, h: i, q: a, f: o } = e.req.query(), s = !!(r || i || a || o), c = e.req.header("Accept") || "", l = "";
|
|
@@ -12904,7 +12914,7 @@ ha.get("/*", async (e) => {
|
|
|
12904
12914
|
}
|
|
12905
12915
|
let p = e.req.header("Via")?.includes("image-resizing") || e.req.header("User-Agent")?.includes("Cloudflare-ImgRen"), m = new URL(e.req.url), h = e.env?.CDN_DOMAIN || m.hostname;
|
|
12906
12916
|
if (n) {
|
|
12907
|
-
let l =
|
|
12917
|
+
let l = _a(t), u = l.startsWith("image/") && !l.includes("svg");
|
|
12908
12918
|
if (s && u && h && !p) {
|
|
12909
12919
|
let e = r ? parseInt(r, 10) : void 0, n = i ? parseInt(i, 10) : void 0, s = a ? parseInt(a, 10) : 85, l = o || "auto", u = `https://${h}/media/${t}`;
|
|
12910
12920
|
try {
|
|
@@ -12947,7 +12957,7 @@ ha.get("/*", async (e) => {
|
|
|
12947
12957
|
if (!s) {
|
|
12948
12958
|
let n = _(C);
|
|
12949
12959
|
return e.body(n, 200, {
|
|
12950
|
-
"Content-Type":
|
|
12960
|
+
"Content-Type": _a(t),
|
|
12951
12961
|
"Cache-Control": "public, max-age=86400"
|
|
12952
12962
|
});
|
|
12953
12963
|
}
|
|
@@ -12955,7 +12965,7 @@ ha.get("/*", async (e) => {
|
|
|
12955
12965
|
if (g(f)) {
|
|
12956
12966
|
let n = _(f);
|
|
12957
12967
|
return e.body(n, 200, {
|
|
12958
|
-
"Content-Type":
|
|
12968
|
+
"Content-Type": _a(t, u),
|
|
12959
12969
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
12960
12970
|
"X-Local-Cache": "HIT"
|
|
12961
12971
|
});
|
|
@@ -12968,14 +12978,14 @@ ha.get("/*", async (e) => {
|
|
|
12968
12978
|
typeof n == "number" && (a.width = n), typeof o == "number" && (a.height = o), (a.width || a.height) && (a.fit = "cover", i = i.resize(a)), u === "webp" ? i = i.webp({ quality: typeof c == "number" ? c : 80 }) : u === "avif" ? i = i.avif({ quality: typeof c == "number" ? c : 70 }) : u === "jpeg" || u === "jpg" ? i = i.jpeg({ quality: typeof c == "number" ? c : 80 }) : u === "png" && (i = i.png({ quality: typeof c == "number" ? c : 80 }));
|
|
12969
12979
|
let s = await i.toBuffer();
|
|
12970
12980
|
return v(x(f), { recursive: !0 }), y(f, s), e.body(s, 200, {
|
|
12971
|
-
"Content-Type":
|
|
12981
|
+
"Content-Type": _a(t, u),
|
|
12972
12982
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
12973
12983
|
"X-Local-Cache": "MISS"
|
|
12974
12984
|
});
|
|
12975
12985
|
} catch {
|
|
12976
12986
|
let n = _(C);
|
|
12977
12987
|
return e.body(n, 200, {
|
|
12978
|
-
"Content-Type":
|
|
12988
|
+
"Content-Type": _a(t),
|
|
12979
12989
|
"Cache-Control": "public, max-age=86400"
|
|
12980
12990
|
});
|
|
12981
12991
|
}
|
|
@@ -12986,8 +12996,8 @@ ha.get("/*", async (e) => {
|
|
|
12986
12996
|
});
|
|
12987
12997
|
//#endregion
|
|
12988
12998
|
//#region server/routes/public/paths.ts
|
|
12989
|
-
var
|
|
12990
|
-
function
|
|
12999
|
+
var va = new e();
|
|
13000
|
+
function ya(e, t) {
|
|
12991
13001
|
let n = /* @__PURE__ */ new Date();
|
|
12992
13002
|
if (e && String(e).trim() !== "") {
|
|
12993
13003
|
let t = new Date(e);
|
|
@@ -12999,7 +13009,7 @@ function va(e, t) {
|
|
|
12999
13009
|
}
|
|
13000
13010
|
return !0;
|
|
13001
13011
|
}
|
|
13002
|
-
|
|
13012
|
+
va.get("/", async (e) => {
|
|
13003
13013
|
try {
|
|
13004
13014
|
let t = await e.get("db").prepare("\n SELECT\n t.id as treeNodeId,\n t.parentId,\n c.slug,\n c.contentType as nodeType,\n c.status,\n c.dataJson\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE (c.deletedAt IS NULL OR c.deletedAt = '')\n ORDER BY t.sortOrder ASC\n ").all(), n = Array.isArray(t) ? t : t?.results || [], r = [], i = /* @__PURE__ */ new Map();
|
|
13005
13015
|
for (let e of n) {
|
|
@@ -13023,7 +13033,7 @@ _a.get("/", async (e) => {
|
|
|
13023
13033
|
function o(e = null, t = "") {
|
|
13024
13034
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
|
|
13025
13035
|
for (let e of s) {
|
|
13026
|
-
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s =
|
|
13036
|
+
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = ya(n.startShowingAt, n.stopShowingAt);
|
|
13027
13037
|
if (!i || !s) continue;
|
|
13028
13038
|
let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
|
|
13029
13039
|
e.nodeType !== "external-link" && r.push(l);
|
|
@@ -13040,12 +13050,12 @@ _a.get("/", async (e) => {
|
|
|
13040
13050
|
});
|
|
13041
13051
|
//#endregion
|
|
13042
13052
|
//#region server/index.ts
|
|
13043
|
-
var
|
|
13053
|
+
var ba = Lr(), $ = new e(), xa = Kr();
|
|
13044
13054
|
$.use("*", async (e, t) => {
|
|
13045
13055
|
let n = e.env?.ENVIRONMENT === "production", r = typeof process < "u" && process.env.NODE_ENV === "production";
|
|
13046
|
-
return !n && !r ?
|
|
13056
|
+
return !n && !r ? xa(e, t) : t();
|
|
13047
13057
|
});
|
|
13048
|
-
var
|
|
13058
|
+
var Sa = !1, Ca = null;
|
|
13049
13059
|
$.use("*", zr()), $.use("/media/*", zr({
|
|
13050
13060
|
origin: "*",
|
|
13051
13061
|
allowMethods: [
|
|
@@ -13063,18 +13073,18 @@ $.use("*", zr()), $.use("/media/*", zr({
|
|
|
13063
13073
|
await t(), e.header("Cache-Control", "public, max-age=31536000, immutable"), e.header("Access-Control-Allow-Origin", "*");
|
|
13064
13074
|
}), $.use("*", async (e, t) => {
|
|
13065
13075
|
if (e.req.path.startsWith("/media/")) return t();
|
|
13066
|
-
let n =
|
|
13067
|
-
e.env?.BUNDLED_DEFINITIONS && (
|
|
13076
|
+
let n = ba;
|
|
13077
|
+
e.env?.BUNDLED_DEFINITIONS && (Ca ||= Lr(e.env.BUNDLED_DEFINITIONS), n = Ca), e.set("schemas", n);
|
|
13068
13078
|
let r = new URL(e.req.url), i = (e.req.header("host") || r.hostname).split(":")[0];
|
|
13069
13079
|
e.set("currentDomain", i);
|
|
13070
13080
|
let a = Xr(e);
|
|
13071
|
-
if (e.set("db", a), !
|
|
13072
|
-
await ei(a, n),
|
|
13081
|
+
if (e.set("db", a), !Sa) try {
|
|
13082
|
+
await ei(a, n), Sa = !0;
|
|
13073
13083
|
} catch (e) {
|
|
13074
13084
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
13075
13085
|
}
|
|
13076
13086
|
await t();
|
|
13077
|
-
}), $.route("/media",
|
|
13087
|
+
}), $.route("/media", ga), $.use("/media/*", ni()), $.route("/api/cms/nodes", Y), $.route("/api/cms/nodes.json", Y), $.route("/api/cms/formcsv", Y), $.route("/api/cms/formcsv.json", Y), $.route("/api/cms/stats", Ui), $.route("/api/cms/stats.json", Ui), $.route("/api/cms", Ai), $.route("/api/cms/channels", Fi), $.route("/api/cms/channels.json", Fi), $.route("/api/cms/schemas", Li), $.route("/api/cms/schemas.json", Li), $.route("/api/admin/schemas", Li), $.route("/api/cms", Bi), $.route("/api/admin/assets", Ji), $.route("/api/v1/node", Xi), $.route("/api/v1/page", Xi), $.route("/api/v1/tree", pa), $.route("/api/v1/all-paths", va), $.get("*", async (e) => {
|
|
13078
13088
|
if (e.env?.ASSETS) {
|
|
13079
13089
|
let t = await e.env.ASSETS.fetch(e.req.raw);
|
|
13080
13090
|
if (t.status === 404) {
|