@brightsideoy/kama 0.1.0-alpha.129 → 0.1.0-alpha.130
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/dist/assets/{index-B_6r1WsU.js → index-C1B9a4dS.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/index.js +241 -216
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6255,7 +6255,7 @@ Z.get("/", async (e) => {
|
|
|
6255
6255
|
}), Z.post("/publish", async (e) => {
|
|
6256
6256
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
6257
6257
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
6258
|
-
let i = Number(r), a = e.get("user")?.id || null, o = (await fi(t, "SELECT
|
|
6258
|
+
let i = Number(r), a = e.get("user")?.id || null, o = (await fi(t, "SELECT * FROM content_nodes WHERE id = ?", [i]))[0];
|
|
6259
6259
|
if (!o) return e.json({ error: "Node not found" }, 404);
|
|
6260
6260
|
let s = [];
|
|
6261
6261
|
return s.push({
|
|
@@ -6279,7 +6279,16 @@ Z.get("/", async (e) => {
|
|
|
6279
6279
|
}), s = JSON.stringify({
|
|
6280
6280
|
version: n,
|
|
6281
6281
|
publishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6282
|
-
node:
|
|
6282
|
+
node: {
|
|
6283
|
+
...o.draftDataJson ? JSON.parse(o.draftDataJson) : {},
|
|
6284
|
+
title: o.title,
|
|
6285
|
+
slug: o.slug,
|
|
6286
|
+
nodeType: o.contentType,
|
|
6287
|
+
contentType: o.contentType,
|
|
6288
|
+
language: o.language,
|
|
6289
|
+
isHidden: o.isHidden,
|
|
6290
|
+
status: "published"
|
|
6291
|
+
},
|
|
6283
6292
|
blocks: r
|
|
6284
6293
|
});
|
|
6285
6294
|
await pi(t, "INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)", [
|
|
@@ -6300,30 +6309,34 @@ Z.get("/", async (e) => {
|
|
|
6300
6309
|
}), Z.get("/revisions", async (e) => {
|
|
6301
6310
|
let t = e.get("db"), n = Number(e.req.query("id"));
|
|
6302
6311
|
if (!n || isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
6303
|
-
let r = await t
|
|
6312
|
+
let r = (await fi(t, "\n SELECT r.id, r.version, r.createdAt, r.createdById, u.name as createdByName, u.email as createdByEmail\n FROM node_revisions r LEFT JOIN users u ON r.createdById = u.id\n WHERE r.nodeId = ? ORDER BY r.createdAt DESC LIMIT 50\n ", [n])).map((e) => ({
|
|
6304
6313
|
...e,
|
|
6305
6314
|
createdAt: (e.createdAt || "").replace(" ", "T") + "Z"
|
|
6306
6315
|
}));
|
|
6307
|
-
return e.json({ revisions:
|
|
6316
|
+
return e.json({ revisions: r });
|
|
6308
6317
|
}), Z.get("/revisions/payload", async (e) => {
|
|
6309
6318
|
let t = e.get("db"), n = Number(e.req.query("id")), r = Number(e.req.query("revisionId"));
|
|
6310
6319
|
if (!n || isNaN(n) || !r || isNaN(r)) return e.json({ error: "Invalid IDs" }, 400);
|
|
6311
|
-
let i = await t
|
|
6312
|
-
if (!
|
|
6313
|
-
let
|
|
6320
|
+
let i = (await fi(t, "SELECT * FROM content_nodes WHERE id = ?", [n]))[0] || {}, a = (await fi(t, "SELECT snapshotJson FROM node_revisions WHERE id = ? AND nodeId = ?", [r, n]))[0];
|
|
6321
|
+
if (!a) return e.json({ error: "Revision not found" }, 404);
|
|
6322
|
+
let o = {};
|
|
6314
6323
|
try {
|
|
6315
|
-
|
|
6324
|
+
o = typeof a.snapshotJson == "string" ? JSON.parse(a.snapshotJson) : a.snapshotJson;
|
|
6316
6325
|
} catch {
|
|
6317
6326
|
return e.json({ error: "Failed to parse snapshot" }, 500);
|
|
6318
6327
|
}
|
|
6319
|
-
let
|
|
6320
|
-
|
|
6321
|
-
let
|
|
6322
|
-
...
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6328
|
+
let s = typeof o.node?.dataJson == "string" ? JSON.parse(o.node.dataJson) : o.node?.dataJson || o.node || {};
|
|
6329
|
+
s = await ui(t, _i(s));
|
|
6330
|
+
let c = {
|
|
6331
|
+
...i,
|
|
6332
|
+
nodeType: i.contentType,
|
|
6333
|
+
...o.node,
|
|
6334
|
+
...s,
|
|
6335
|
+
nodeType: o.node?.contentType || o.node?.nodeType || i.contentType,
|
|
6336
|
+
contentType: o.node?.contentType || o.node?.nodeType || i.contentType,
|
|
6337
|
+
title: o.node?.title || i.title,
|
|
6338
|
+
slug: o.node?.slug || i.slug
|
|
6339
|
+
}, l = o.blocks || [], u = await Promise.all(l.map(async (e) => {
|
|
6327
6340
|
let n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {};
|
|
6328
6341
|
n = await ui(t, n);
|
|
6329
6342
|
let r = n.blockId || n._instanceId || (n.id && !String(n.id).startsWith("ast_") ? n.id : null) || e.instanceId || String(e.id), i = { ...n };
|
|
@@ -6336,9 +6349,9 @@ Z.get("/", async (e) => {
|
|
|
6336
6349
|
};
|
|
6337
6350
|
}));
|
|
6338
6351
|
return e.json({
|
|
6339
|
-
node:
|
|
6340
|
-
blocks:
|
|
6341
|
-
version:
|
|
6352
|
+
node: c,
|
|
6353
|
+
blocks: u,
|
|
6354
|
+
version: o.version
|
|
6342
6355
|
});
|
|
6343
6356
|
}), Z.delete("/", async (e) => {
|
|
6344
6357
|
let t = e.get("db"), n = e.req.query("id");
|
|
@@ -6397,7 +6410,13 @@ Z.get("/", async (e) => {
|
|
|
6397
6410
|
//#endregion
|
|
6398
6411
|
//#region server/routes/admin/trees.ts
|
|
6399
6412
|
var yi = new n();
|
|
6400
|
-
function bi(e, t
|
|
6413
|
+
function bi(e, t) {
|
|
6414
|
+
let n = Promise.resolve(typeof t == "function" ? t() : t).catch((e) => console.error("[Background Task Error]:", e));
|
|
6415
|
+
try {
|
|
6416
|
+
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
6417
|
+
} catch {}
|
|
6418
|
+
}
|
|
6419
|
+
function xi(e, t = null) {
|
|
6401
6420
|
let n = [];
|
|
6402
6421
|
for (let r = 0; r < e.length; r++) {
|
|
6403
6422
|
let i = e[r];
|
|
@@ -6409,16 +6428,16 @@ function bi(e, t = null) {
|
|
|
6409
6428
|
id: o,
|
|
6410
6429
|
parentId: t,
|
|
6411
6430
|
sortOrder: r
|
|
6412
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
6431
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...xi(i.children, o)));
|
|
6413
6432
|
}
|
|
6414
6433
|
return n;
|
|
6415
6434
|
}
|
|
6416
|
-
function
|
|
6435
|
+
function Si(e) {
|
|
6417
6436
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6418
6437
|
let t = Number(e);
|
|
6419
6438
|
return isNaN(t) ? null : t;
|
|
6420
6439
|
}
|
|
6421
|
-
function
|
|
6440
|
+
function Ci(e) {
|
|
6422
6441
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6423
6442
|
}
|
|
6424
6443
|
yi.get("/tree.json", async (e) => {
|
|
@@ -6473,43 +6492,39 @@ yi.get("/tree.json", async (e) => {
|
|
|
6473
6492
|
}
|
|
6474
6493
|
}), yi.post("/tree.json", async (e) => {
|
|
6475
6494
|
try {
|
|
6476
|
-
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i =
|
|
6495
|
+
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = 1;
|
|
6477
6496
|
if (isNaN(Number(r))) {
|
|
6478
6497
|
let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
let e = await t.prepare("SELECT id FROM trees LIMIT 1").get();
|
|
6482
|
-
e && e.id && (o = Number(e.id));
|
|
6483
|
-
}
|
|
6484
|
-
} else o = Number(r);
|
|
6498
|
+
e && e.id && (i = Number(e.id));
|
|
6499
|
+
} else i = Number(r);
|
|
6485
6500
|
if (n.tree && Array.isArray(n.tree)) {
|
|
6486
|
-
let r =
|
|
6487
|
-
if (r.length > 0)
|
|
6488
|
-
let
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
c.push(e.id, e.sortOrder);
|
|
6499
|
-
}), c.push(...i), c.push(o), await t.prepare(s).run(...c);
|
|
6501
|
+
let r = xi(n.tree, null);
|
|
6502
|
+
if (r.length > 0) {
|
|
6503
|
+
let e = r.map((e) => ({
|
|
6504
|
+
sql: "UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE id = ? AND treeId = ?",
|
|
6505
|
+
params: [
|
|
6506
|
+
e.parentId,
|
|
6507
|
+
e.sortOrder,
|
|
6508
|
+
e.id,
|
|
6509
|
+
i
|
|
6510
|
+
]
|
|
6511
|
+
}));
|
|
6512
|
+
await t.batch(e);
|
|
6500
6513
|
}
|
|
6501
|
-
return
|
|
6514
|
+
return bi(e, async () => {
|
|
6515
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6516
|
+
}), e.json({
|
|
6502
6517
|
success: !0,
|
|
6503
6518
|
reorderedCount: r.length
|
|
6504
6519
|
});
|
|
6505
6520
|
}
|
|
6506
|
-
let { action:
|
|
6507
|
-
delete
|
|
6508
|
-
let
|
|
6509
|
-
if (
|
|
6510
|
-
let r =
|
|
6511
|
-
if (
|
|
6512
|
-
let r =
|
|
6521
|
+
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 = Ci(n.isHidden === void 0 ? f.isHidden === void 0 ? f.hidden : f.isHidden : n.isHidden);
|
|
6522
|
+
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;
|
|
6523
|
+
let m = Si(c), h = e.get("user")?.id || null;
|
|
6524
|
+
if (a === "create") {
|
|
6525
|
+
let r = f.slug || n.slug || o, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
6526
|
+
if (a) {
|
|
6527
|
+
let r = m === null ? "tn.parentId IS NULL" : "tn.parentId = ?", o = n.contentId || n.id ? Number(n.contentId || n.id) : null, s = `
|
|
6513
6528
|
SELECT 1
|
|
6514
6529
|
FROM tree_nodes tn
|
|
6515
6530
|
INNER JOIN content_nodes cn ON tn.contentId = cn.id
|
|
@@ -6517,49 +6532,51 @@ yi.get("/tree.json", async (e) => {
|
|
|
6517
6532
|
AND ${r}
|
|
6518
6533
|
AND cn.slug = ?
|
|
6519
6534
|
AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
6520
|
-
`, c =
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6535
|
+
`, c = m === null ? [i, a] : [
|
|
6536
|
+
i,
|
|
6537
|
+
m,
|
|
6538
|
+
a
|
|
6524
6539
|
];
|
|
6525
|
-
if (
|
|
6526
|
-
error: `The slug '${
|
|
6540
|
+
if (o && !isNaN(o) && (s += " AND cn.id != ?", c.push(o)), s += " LIMIT 1", await t.prepare(s).get(...c)) return e.json({
|
|
6541
|
+
error: `The slug '${a}' is already in use by another page in this section.`,
|
|
6527
6542
|
field: "slug"
|
|
6528
6543
|
}, 409);
|
|
6529
6544
|
}
|
|
6530
|
-
let
|
|
6531
|
-
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(
|
|
6532
|
-
let
|
|
6545
|
+
let c = JSON.stringify(f), l = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, ?, ?)\n ").run(s || "page", o || "Untitled", a, f.language || n.language || "en", p, c, h, h), u = Number(l.lastInsertRowid);
|
|
6546
|
+
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(i, u);
|
|
6547
|
+
let d = m === null ? "parentId IS NULL" : "parentId = ?", g = m === null ? [i] : [i, m], _ = (await t.prepare(`
|
|
6533
6548
|
SELECT COALESCE(MAX(sortOrder), -1) + 1 as nextSort
|
|
6534
6549
|
FROM tree_nodes
|
|
6535
|
-
WHERE treeId = ? AND ${
|
|
6536
|
-
`).get(...
|
|
6537
|
-
n.channels && Array.isArray(n.channels) ?
|
|
6538
|
-
let
|
|
6539
|
-
if (
|
|
6540
|
-
let e =
|
|
6550
|
+
WHERE treeId = ? AND ${d}
|
|
6551
|
+
`).get(...g))?.nextSort ?? 0, v = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(i, u, m, _), y = Number(v.lastInsertRowid), b = [];
|
|
6552
|
+
n.channels && Array.isArray(n.channels) ? b = n.channels : n.channelId && n.channelId !== "all" && (b = [n.channelId]);
|
|
6553
|
+
let x = [...new Set(b)].filter((e) => e && e !== "all").map((e) => Number(e));
|
|
6554
|
+
if (x.length > 0) {
|
|
6555
|
+
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [u, e]);
|
|
6541
6556
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
6542
6557
|
}
|
|
6543
|
-
return
|
|
6558
|
+
return bi(e, async () => {
|
|
6559
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6560
|
+
}), e.json({
|
|
6544
6561
|
success: !0,
|
|
6545
|
-
id:
|
|
6546
|
-
treeNodeId:
|
|
6562
|
+
id: u,
|
|
6563
|
+
treeNodeId: y,
|
|
6547
6564
|
status: "draft"
|
|
6548
6565
|
}, 201);
|
|
6549
6566
|
}
|
|
6550
|
-
if (
|
|
6551
|
-
if (!
|
|
6552
|
-
let n = await t.prepare("SELECT slug FROM content_nodes WHERE id = ?").get(
|
|
6567
|
+
if (a === "attach") {
|
|
6568
|
+
if (!l) return e.json({ error: "contentId is required for attach" }, 400);
|
|
6569
|
+
let n = await t.prepare("SELECT slug FROM content_nodes WHERE id = ?").get(l);
|
|
6553
6570
|
if (n && n.slug) {
|
|
6554
|
-
let r =
|
|
6555
|
-
|
|
6571
|
+
let r = m === null ? "tn.parentId IS NULL" : "tn.parentId = ?", a = m === null ? [
|
|
6572
|
+
i,
|
|
6556
6573
|
n.slug,
|
|
6557
|
-
|
|
6574
|
+
l
|
|
6558
6575
|
] : [
|
|
6559
|
-
|
|
6560
|
-
|
|
6576
|
+
i,
|
|
6577
|
+
m,
|
|
6561
6578
|
n.slug,
|
|
6562
|
-
|
|
6579
|
+
l
|
|
6563
6580
|
];
|
|
6564
6581
|
if (await t.prepare(`
|
|
6565
6582
|
SELECT 1
|
|
@@ -6571,21 +6588,25 @@ yi.get("/tree.json", async (e) => {
|
|
|
6571
6588
|
AND cn.id != ?
|
|
6572
6589
|
AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
6573
6590
|
LIMIT 1
|
|
6574
|
-
`).get(...
|
|
6591
|
+
`).get(...a)) return e.json({
|
|
6575
6592
|
error: `Cannot attach. The slug '${n.slug}' is already in use by another page in this section.`,
|
|
6576
6593
|
field: "slug"
|
|
6577
6594
|
}, 409);
|
|
6578
6595
|
}
|
|
6579
|
-
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(
|
|
6580
|
-
let r = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(
|
|
6581
|
-
return
|
|
6596
|
+
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(i, l);
|
|
6597
|
+
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);
|
|
6598
|
+
return bi(e, async () => {
|
|
6599
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6600
|
+
}), e.json({
|
|
6582
6601
|
success: !0,
|
|
6583
|
-
treeNodeId:
|
|
6602
|
+
treeNodeId: a
|
|
6584
6603
|
});
|
|
6585
6604
|
}
|
|
6586
|
-
if (
|
|
6605
|
+
if (a === "detach") {
|
|
6587
6606
|
let r = n.treeNodeId || n.contentId;
|
|
6588
|
-
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, r,
|
|
6607
|
+
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, r, i, r, i), await t.prepare("DELETE FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?").run(r, r, i), bi(e, async () => {
|
|
6608
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6609
|
+
}), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
|
|
6589
6610
|
}
|
|
6590
6611
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
6591
6612
|
} catch (t) {
|
|
@@ -6649,7 +6670,9 @@ yi.get("/tree.json", async (e) => {
|
|
|
6649
6670
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
6650
6671
|
}
|
|
6651
6672
|
}
|
|
6652
|
-
return
|
|
6673
|
+
return bi(e, async () => {
|
|
6674
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6675
|
+
}), e.json({
|
|
6653
6676
|
success: !0,
|
|
6654
6677
|
id: p,
|
|
6655
6678
|
key: o,
|
|
@@ -6668,7 +6691,9 @@ yi.get("/tree.json", async (e) => {
|
|
|
6668
6691
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
6669
6692
|
let r = Number(n);
|
|
6670
6693
|
try {
|
|
6671
|
-
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r),
|
|
6694
|
+
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), bi(e, async () => {
|
|
6695
|
+
await Y(e).clear(), new X(e.env).purgeGlobalCache(e, t);
|
|
6696
|
+
}), e.json({
|
|
6672
6697
|
success: !0,
|
|
6673
6698
|
deletedTreeId: r
|
|
6674
6699
|
});
|
|
@@ -6678,8 +6703,8 @@ yi.get("/tree.json", async (e) => {
|
|
|
6678
6703
|
});
|
|
6679
6704
|
//#endregion
|
|
6680
6705
|
//#region server/routes/admin/channels.ts
|
|
6681
|
-
var
|
|
6682
|
-
|
|
6706
|
+
var wi = new n();
|
|
6707
|
+
wi.get("/", async (e) => {
|
|
6683
6708
|
try {
|
|
6684
6709
|
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) => {
|
|
6685
6710
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -6747,7 +6772,7 @@ Ci.get("/", async (e) => {
|
|
|
6747
6772
|
error: t.message
|
|
6748
6773
|
}, 500);
|
|
6749
6774
|
}
|
|
6750
|
-
}),
|
|
6775
|
+
}), wi.post("/", async (e) => {
|
|
6751
6776
|
try {
|
|
6752
6777
|
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;
|
|
6753
6778
|
if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
|
|
@@ -6787,7 +6812,7 @@ Ci.get("/", async (e) => {
|
|
|
6787
6812
|
details: t.message
|
|
6788
6813
|
}, 500);
|
|
6789
6814
|
}
|
|
6790
|
-
}),
|
|
6815
|
+
}), wi.delete("/", async (e) => {
|
|
6791
6816
|
let t = e.get("db"), n = e.req.query("id");
|
|
6792
6817
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
6793
6818
|
let r = Number(n);
|
|
@@ -6805,7 +6830,7 @@ Ci.get("/", async (e) => {
|
|
|
6805
6830
|
});
|
|
6806
6831
|
//#endregion
|
|
6807
6832
|
//#region server/db/bundled-definitions.ts
|
|
6808
|
-
var
|
|
6833
|
+
var Ti = {
|
|
6809
6834
|
nodes: {
|
|
6810
6835
|
address: {
|
|
6811
6836
|
id: "address",
|
|
@@ -11512,11 +11537,11 @@ var wi = {
|
|
|
11512
11537
|
treeTemplate: null,
|
|
11513
11538
|
channelTemplate: null,
|
|
11514
11539
|
userTemplate: null
|
|
11515
|
-
},
|
|
11540
|
+
}, Ei = new n(), Di = null, Oi = (e) => {
|
|
11516
11541
|
try {
|
|
11517
11542
|
let t = process.env.NODE_ENV !== "production";
|
|
11518
|
-
if (!
|
|
11519
|
-
let t = e.env?.BUNDLED_DEFINITIONS ||
|
|
11543
|
+
if (!Di || t) {
|
|
11544
|
+
let t = e.env?.BUNDLED_DEFINITIONS || Ti || {}, n = Mr(t) || {}, r = e.get("schemas") || {}, i = r.rawChannels || {}, a = r.rawNodes || {}, o = r.rawTrees || {}, s = r.rawBlocks || {}, c = r.rawNodeLayouts || {}, l = 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 || {
|
|
11520
11545
|
id: "userTemplate",
|
|
11521
11546
|
label: "User Account",
|
|
11522
11547
|
fields: {
|
|
@@ -11552,7 +11577,7 @@ var wi = {
|
|
|
11552
11577
|
}
|
|
11553
11578
|
}
|
|
11554
11579
|
}, C = Object.keys(g)[0];
|
|
11555
|
-
|
|
11580
|
+
Di = {
|
|
11556
11581
|
channelTemplate: n.channelTemplate || (C ? g[C] : null),
|
|
11557
11582
|
treeTemplate: n.treeTemplate || null,
|
|
11558
11583
|
userTemplate: S,
|
|
@@ -11567,7 +11592,7 @@ var wi = {
|
|
|
11567
11592
|
blockLayouts: x
|
|
11568
11593
|
};
|
|
11569
11594
|
}
|
|
11570
|
-
return e.json(
|
|
11595
|
+
return e.json(Di, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
11571
11596
|
} catch (t) {
|
|
11572
11597
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
11573
11598
|
error: "Failed to load schemas",
|
|
@@ -11575,10 +11600,10 @@ var wi = {
|
|
|
11575
11600
|
}, 500);
|
|
11576
11601
|
}
|
|
11577
11602
|
};
|
|
11578
|
-
|
|
11603
|
+
Ei.get("/", Oi), Ei.get("/schemas.json", Oi);
|
|
11579
11604
|
//#endregion
|
|
11580
11605
|
//#region server/routes/admin/validation.ts
|
|
11581
|
-
var
|
|
11606
|
+
var ki = new n(), Ai = {
|
|
11582
11607
|
node: "content_nodes",
|
|
11583
11608
|
nodes: "content_nodes",
|
|
11584
11609
|
content_node: "content_nodes",
|
|
@@ -11590,7 +11615,7 @@ var Oi = new n(), ki = {
|
|
|
11590
11615
|
user: "users",
|
|
11591
11616
|
users: "users",
|
|
11592
11617
|
user_account: "user_accounts"
|
|
11593
|
-
},
|
|
11618
|
+
}, ji = {
|
|
11594
11619
|
content_nodes: [
|
|
11595
11620
|
"id",
|
|
11596
11621
|
"title",
|
|
@@ -11647,11 +11672,11 @@ var Oi = new n(), ki = {
|
|
|
11647
11672
|
"createdAt"
|
|
11648
11673
|
]
|
|
11649
11674
|
};
|
|
11650
|
-
|
|
11675
|
+
ki.post("/validate-unique", async (e) => {
|
|
11651
11676
|
try {
|
|
11652
11677
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
11653
11678
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
11654
|
-
let o =
|
|
11679
|
+
let o = Ai[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (ji[o] || ji.content_nodes).includes(s), l = -1;
|
|
11655
11680
|
if (a != null && String(a).trim() !== "") {
|
|
11656
11681
|
let e = Number(a);
|
|
11657
11682
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -11663,7 +11688,7 @@ Oi.post("/validate-unique", async (e) => {
|
|
|
11663
11688
|
} catch (t) {
|
|
11664
11689
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
11665
11690
|
}
|
|
11666
|
-
}),
|
|
11691
|
+
}), ki.post("/validate-unique-sibling", async (e) => {
|
|
11667
11692
|
try {
|
|
11668
11693
|
let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
|
|
11669
11694
|
if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
|
|
@@ -11691,8 +11716,8 @@ Oi.post("/validate-unique", async (e) => {
|
|
|
11691
11716
|
});
|
|
11692
11717
|
//#endregion
|
|
11693
11718
|
//#region server/routes/admin/stats.ts
|
|
11694
|
-
var
|
|
11695
|
-
|
|
11719
|
+
var Mi = new n();
|
|
11720
|
+
Mi.get("/", async (e) => {
|
|
11696
11721
|
try {
|
|
11697
11722
|
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) => ({
|
|
11698
11723
|
...e,
|
|
@@ -11735,7 +11760,7 @@ ji.get("/", async (e) => {
|
|
|
11735
11760
|
});
|
|
11736
11761
|
//#endregion
|
|
11737
11762
|
//#region server/storage/provider.ts
|
|
11738
|
-
function
|
|
11763
|
+
function Ni(e) {
|
|
11739
11764
|
let t = e.split(".").pop()?.toLowerCase() || "bin";
|
|
11740
11765
|
return t = t.replace(/[^a-z0-9]/g, ""), [
|
|
11741
11766
|
"php",
|
|
@@ -11750,14 +11775,14 @@ function Mi(e) {
|
|
|
11750
11775
|
"cjs"
|
|
11751
11776
|
].includes(t) ? "bin" : t;
|
|
11752
11777
|
}
|
|
11753
|
-
var
|
|
11778
|
+
var Pi = class {
|
|
11754
11779
|
bucket;
|
|
11755
11780
|
publicDomain;
|
|
11756
11781
|
constructor(e, t) {
|
|
11757
11782
|
this.bucket = e, this.publicDomain = t;
|
|
11758
11783
|
}
|
|
11759
11784
|
async upload(e, t = "uploads") {
|
|
11760
|
-
let n =
|
|
11785
|
+
let n = Ni(e.name), r = `${t}/${crypto.randomUUID().replace(/-/g, "")}.${n}`;
|
|
11761
11786
|
return await this.bucket.put(r, e.stream(), { httpMetadata: { contentType: e.type } }), {
|
|
11762
11787
|
key: r,
|
|
11763
11788
|
url: `/media/${r.replace(/^\//, "")}`
|
|
@@ -11766,7 +11791,7 @@ var Ni = class {
|
|
|
11766
11791
|
async delete(e) {
|
|
11767
11792
|
await this.bucket.delete(e);
|
|
11768
11793
|
}
|
|
11769
|
-
},
|
|
11794
|
+
}, Fi = class {
|
|
11770
11795
|
customStoragePath;
|
|
11771
11796
|
constructor(e) {
|
|
11772
11797
|
this.customStoragePath = e;
|
|
@@ -11784,7 +11809,7 @@ var Ni = class {
|
|
|
11784
11809
|
), { pipeline: a } = await import(
|
|
11785
11810
|
/* @vite-ignore */
|
|
11786
11811
|
"node:stream/promises"
|
|
11787
|
-
), o =
|
|
11812
|
+
), o = Ni(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);
|
|
11788
11813
|
await i.mkdir(n.dirname(u), { recursive: !0 });
|
|
11789
11814
|
let d = r.createWriteStream(u);
|
|
11790
11815
|
return await a(e.stream(), d), {
|
|
@@ -11807,16 +11832,16 @@ var Ni = class {
|
|
|
11807
11832
|
}
|
|
11808
11833
|
}
|
|
11809
11834
|
};
|
|
11810
|
-
function
|
|
11835
|
+
function Ii(e) {
|
|
11811
11836
|
if (e.MEDIA_BUCKET) {
|
|
11812
11837
|
let t = e.CDN_DOMAIN || "cdn.yourdomain.com";
|
|
11813
|
-
return new
|
|
11838
|
+
return new Pi(e.MEDIA_BUCKET, t);
|
|
11814
11839
|
}
|
|
11815
|
-
return new
|
|
11840
|
+
return new Fi(e.LOCAL_MEDIA_PATH);
|
|
11816
11841
|
}
|
|
11817
11842
|
//#endregion
|
|
11818
11843
|
//#region server/routes/admin/assets.ts
|
|
11819
|
-
var
|
|
11844
|
+
var Li = new n();
|
|
11820
11845
|
async function Q(e, t, n = []) {
|
|
11821
11846
|
let r = e.prepare(t);
|
|
11822
11847
|
if (typeof r.bind == "function") {
|
|
@@ -11829,19 +11854,19 @@ async function Q(e, t, n = []) {
|
|
|
11829
11854
|
}
|
|
11830
11855
|
return [];
|
|
11831
11856
|
}
|
|
11832
|
-
async function
|
|
11857
|
+
async function Ri(e, t, n = []) {
|
|
11833
11858
|
let r = e.prepare(t);
|
|
11834
11859
|
if (typeof r.bind == "function") return await r.bind(...n).run();
|
|
11835
11860
|
if (typeof r.run == "function") return await r.run(...n);
|
|
11836
11861
|
}
|
|
11837
|
-
function
|
|
11862
|
+
function zi(e, t) {
|
|
11838
11863
|
let n = e || (t ? `/media/${t}` : "");
|
|
11839
11864
|
try {
|
|
11840
11865
|
n.startsWith("http") && (n = new URL(n).pathname);
|
|
11841
11866
|
} catch {}
|
|
11842
11867
|
return n.startsWith("/media/") || (n = `/media/${n.replace(/^\/+/, "")}`), n;
|
|
11843
11868
|
}
|
|
11844
|
-
|
|
11869
|
+
Li.get("/", async (e) => {
|
|
11845
11870
|
try {
|
|
11846
11871
|
let t = zr(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 = {
|
|
11847
11872
|
createdAt: "a.createdAt",
|
|
@@ -11908,7 +11933,7 @@ Ii.get("/", async (e) => {
|
|
|
11908
11933
|
...JSON.parse(e.dataJson || "{}")
|
|
11909
11934
|
};
|
|
11910
11935
|
} catch {}
|
|
11911
|
-
let n =
|
|
11936
|
+
let n = zi(e.cdnUrl, e.storageKeyPrivate);
|
|
11912
11937
|
return {
|
|
11913
11938
|
id: e.id,
|
|
11914
11939
|
filename: e.filename || "Untitled Asset",
|
|
@@ -11932,9 +11957,9 @@ Ii.get("/", async (e) => {
|
|
|
11932
11957
|
details: t.message || String(t)
|
|
11933
11958
|
}, 500);
|
|
11934
11959
|
}
|
|
11935
|
-
}),
|
|
11960
|
+
}), Li.post("/upload", async (e) => {
|
|
11936
11961
|
try {
|
|
11937
|
-
let t = zr(e), n =
|
|
11962
|
+
let t = zr(e), n = Ii(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;
|
|
11938
11963
|
s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
|
|
11939
11964
|
let c = r.cropCoordinates, l = null, u = null;
|
|
11940
11965
|
if (c) {
|
|
@@ -11951,7 +11976,7 @@ Ii.get("/", async (e) => {
|
|
|
11951
11976
|
let v = `/media/${_.replace(/^\//, "")}`, y = i.type || "application/octet-stream", b = i.size || 0, x = e.get("userId"), S = typeof x == "string" && x.trim().length > 0 ? x : null;
|
|
11952
11977
|
S && (await Q(t, "SELECT id FROM users WHERE id = ?", [S])).length === 0 && (S = null);
|
|
11953
11978
|
let C = +!!m;
|
|
11954
|
-
await
|
|
11979
|
+
await Ri(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
|
|
11955
11980
|
f,
|
|
11956
11981
|
i.name,
|
|
11957
11982
|
y,
|
|
@@ -11966,7 +11991,7 @@ Ii.get("/", async (e) => {
|
|
|
11966
11991
|
let w = v;
|
|
11967
11992
|
if (s) {
|
|
11968
11993
|
let n = await Q(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [s]);
|
|
11969
|
-
n.length > 0 && (w =
|
|
11994
|
+
n.length > 0 && (w = zi(n[0].cdnUrl, n[0].storageKeyPrivate)), new X(e.env).purgeAsset(e, t, s);
|
|
11970
11995
|
}
|
|
11971
11996
|
return e.json({
|
|
11972
11997
|
id: f,
|
|
@@ -11985,7 +12010,7 @@ Ii.get("/", async (e) => {
|
|
|
11985
12010
|
details: t.message || String(t)
|
|
11986
12011
|
}, 500);
|
|
11987
12012
|
}
|
|
11988
|
-
}),
|
|
12013
|
+
}), Li.get("/:id/details", async (e) => {
|
|
11989
12014
|
try {
|
|
11990
12015
|
let t = zr(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
11991
12016
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -12008,7 +12033,7 @@ Ii.get("/", async (e) => {
|
|
|
12008
12033
|
...JSON.parse(i.dataJson || "{}")
|
|
12009
12034
|
};
|
|
12010
12035
|
} catch {}
|
|
12011
|
-
let l =
|
|
12036
|
+
let l = zi(i.cdnUrl, i.storageKeyPrivate);
|
|
12012
12037
|
return e.json({
|
|
12013
12038
|
id: i.id,
|
|
12014
12039
|
filename: i.filename,
|
|
@@ -12035,7 +12060,7 @@ Ii.get("/", async (e) => {
|
|
|
12035
12060
|
createdAt: e.createdAt,
|
|
12036
12061
|
parentAssetId: e.parentAssetId || i.id,
|
|
12037
12062
|
cropCoordinates: t,
|
|
12038
|
-
url:
|
|
12063
|
+
url: zi(e.cdnUrl, e.storageKeyPrivate),
|
|
12039
12064
|
originalUrl: l
|
|
12040
12065
|
};
|
|
12041
12066
|
})
|
|
@@ -12043,7 +12068,7 @@ Ii.get("/", async (e) => {
|
|
|
12043
12068
|
} catch (t) {
|
|
12044
12069
|
return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
|
|
12045
12070
|
}
|
|
12046
|
-
}),
|
|
12071
|
+
}), Li.put("/:id", async (e) => {
|
|
12047
12072
|
try {
|
|
12048
12073
|
let t = zr(e), n = e.req.param("id"), r = await e.req.json(), i = await Q(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
|
|
12049
12074
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -12051,7 +12076,7 @@ Ii.get("/", async (e) => {
|
|
|
12051
12076
|
try {
|
|
12052
12077
|
o = JSON.parse(a.dataJson || "{}");
|
|
12053
12078
|
} catch {}
|
|
12054
|
-
return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await
|
|
12079
|
+
return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await Ri(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
12055
12080
|
r.filename === void 0 ? a.filename : r.filename,
|
|
12056
12081
|
JSON.stringify(o),
|
|
12057
12082
|
n
|
|
@@ -12059,10 +12084,10 @@ Ii.get("/", async (e) => {
|
|
|
12059
12084
|
} catch (t) {
|
|
12060
12085
|
return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
|
|
12061
12086
|
}
|
|
12062
|
-
}),
|
|
12087
|
+
}), Li.delete("/:id", async (e) => {
|
|
12063
12088
|
try {
|
|
12064
12089
|
let t = zr(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
12065
|
-
return r ? (new X(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await
|
|
12090
|
+
return r ? (new X(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await Ri(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Ri(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
12066
12091
|
n,
|
|
12067
12092
|
n,
|
|
12068
12093
|
`crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
@@ -12078,12 +12103,12 @@ Ii.get("/", async (e) => {
|
|
|
12078
12103
|
details: t.message || String(t)
|
|
12079
12104
|
}, 500);
|
|
12080
12105
|
}
|
|
12081
|
-
}),
|
|
12106
|
+
}), Li.post("/restore", async (e) => {
|
|
12082
12107
|
try {
|
|
12083
12108
|
let t = zr(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
12084
12109
|
if (!r) return e.json({ error: "Asset ID required" }, 400);
|
|
12085
12110
|
let i = (await Q(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
|
|
12086
|
-
return i ? (await
|
|
12111
|
+
return i ? (await Ri(t, "UPDATE assets \n SET deletedAt = NULL \n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
12087
12112
|
r,
|
|
12088
12113
|
r,
|
|
12089
12114
|
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
@@ -12099,9 +12124,9 @@ Ii.get("/", async (e) => {
|
|
|
12099
12124
|
details: t.message
|
|
12100
12125
|
}, 500);
|
|
12101
12126
|
}
|
|
12102
|
-
}),
|
|
12127
|
+
}), Li.delete("/purge/:id", async (e) => {
|
|
12103
12128
|
try {
|
|
12104
|
-
let t = zr(e), n =
|
|
12129
|
+
let t = zr(e), n = Ii(e.env), r = e.req.param("id"), i = (await Q(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
12105
12130
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
12106
12131
|
new X(e.env).purgeAsset(e, t, r);
|
|
12107
12132
|
let a = [i];
|
|
@@ -12119,7 +12144,7 @@ Ii.get("/", async (e) => {
|
|
|
12119
12144
|
}
|
|
12120
12145
|
}
|
|
12121
12146
|
let s = o.map(() => "?").join(",");
|
|
12122
|
-
return await
|
|
12147
|
+
return await Ri(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await Ri(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
|
|
12123
12148
|
success: !0,
|
|
12124
12149
|
id: r,
|
|
12125
12150
|
purged: !0,
|
|
@@ -12135,14 +12160,14 @@ Ii.get("/", async (e) => {
|
|
|
12135
12160
|
});
|
|
12136
12161
|
//#endregion
|
|
12137
12162
|
//#region server/routes/public/node.ts
|
|
12138
|
-
var
|
|
12139
|
-
function
|
|
12163
|
+
var Bi = new n();
|
|
12164
|
+
function Vi(e, t) {
|
|
12140
12165
|
let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
|
|
12141
12166
|
try {
|
|
12142
12167
|
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
12143
12168
|
} catch {}
|
|
12144
12169
|
}
|
|
12145
|
-
function
|
|
12170
|
+
function Hi() {
|
|
12146
12171
|
return {
|
|
12147
12172
|
fullPath: /* @__PURE__ */ new Map(),
|
|
12148
12173
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -12150,15 +12175,15 @@ function Vi() {
|
|
|
12150
12175
|
assetUrls: /* @__PURE__ */ new Map()
|
|
12151
12176
|
};
|
|
12152
12177
|
}
|
|
12153
|
-
function
|
|
12178
|
+
function Ui(...e) {
|
|
12154
12179
|
return e.map((e) => String(e ?? "")).join(":");
|
|
12155
12180
|
}
|
|
12156
|
-
function
|
|
12181
|
+
function Wi(e) {
|
|
12157
12182
|
if (!e || String(e).trim() === "") return null;
|
|
12158
12183
|
let t = new Date(e.includes("T") ? e : e.replace(" ", "T") + "Z");
|
|
12159
12184
|
return isNaN(t.getTime()) ? e : t.toISOString();
|
|
12160
12185
|
}
|
|
12161
|
-
function
|
|
12186
|
+
function Gi(e, t) {
|
|
12162
12187
|
let n = Date.now();
|
|
12163
12188
|
if (e && String(e).trim() !== "") {
|
|
12164
12189
|
let t = Date.parse(e);
|
|
@@ -12170,7 +12195,7 @@ function Wi(e, t) {
|
|
|
12170
12195
|
}
|
|
12171
12196
|
return !0;
|
|
12172
12197
|
}
|
|
12173
|
-
async function
|
|
12198
|
+
async function Ki(e, t, n) {
|
|
12174
12199
|
let r = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list");
|
|
12175
12200
|
await Promise.all(r.map(async (t) => {
|
|
12176
12201
|
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];
|
|
@@ -12184,13 +12209,13 @@ async function Gi(e, t, n) {
|
|
|
12184
12209
|
if (e.dataJson) try {
|
|
12185
12210
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
12186
12211
|
} catch {}
|
|
12187
|
-
return
|
|
12212
|
+
return Gi(t.startShowingAt, t.stopShowingAt) ? {
|
|
12188
12213
|
id: e.id,
|
|
12189
12214
|
title: e.title,
|
|
12190
12215
|
slug: e.slug,
|
|
12191
12216
|
language: e.language || "en",
|
|
12192
|
-
createdAt:
|
|
12193
|
-
updatedAt:
|
|
12217
|
+
createdAt: Wi(e.createdAt),
|
|
12218
|
+
updatedAt: Wi(e.updatedAt),
|
|
12194
12219
|
excerpt: t.excerpt || "",
|
|
12195
12220
|
image: t.image || t.coverImage || null,
|
|
12196
12221
|
author: t.author || null
|
|
@@ -12201,7 +12226,7 @@ async function Gi(e, t, n) {
|
|
|
12201
12226
|
}
|
|
12202
12227
|
}));
|
|
12203
12228
|
}
|
|
12204
|
-
async function
|
|
12229
|
+
async function qi(e, t, n, r, i = !1, a) {
|
|
12205
12230
|
if (!t) return { blocks: [] };
|
|
12206
12231
|
let o = await 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 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? OR c.id = ?\n UNION ALL\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId\n ) SELECT * FROM ancestor_path ORDER BY level ASC\n ").all(t, t), s = Array.isArray(o) ? o : o?.results || [];
|
|
12207
12232
|
if (!s || s.length === 0) return { blocks: [] };
|
|
@@ -12242,10 +12267,10 @@ async function Ki(e, t, n, r, i = !1, a) {
|
|
|
12242
12267
|
try {
|
|
12243
12268
|
a = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
|
|
12244
12269
|
} catch {}
|
|
12245
|
-
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s =
|
|
12270
|
+
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Gi(a.startShowingAt, a.stopShowingAt);
|
|
12246
12271
|
if (!i && (o || !s)) return null;
|
|
12247
|
-
let c = t.elementType || t.componentId || "text-block", l = r.blocks?.[c]?.fields || r.elements?.[c]?.fields || r.components?.[c]?.fields || {}, u = String(a.blockId || a._instanceId || (a.id && !String(a.id).startsWith("ast_") ? a.id : null) || t.blockId || t.id), d =
|
|
12248
|
-
return d = await ui(e, d), d =
|
|
12272
|
+
let c = t.elementType || t.componentId || "text-block", l = r.blocks?.[c]?.fields || r.elements?.[c]?.fields || r.components?.[c]?.fields || {}, u = String(a.blockId || a._instanceId || (a.id && !String(a.id).startsWith("ast_") ? a.id : null) || t.blockId || t.id), d = Ji(a, l);
|
|
12273
|
+
return d = await ui(e, d), d = Yi(d), d.blockId = u, {
|
|
12249
12274
|
region: t.region || n,
|
|
12250
12275
|
block: {
|
|
12251
12276
|
instanceId: t.id,
|
|
@@ -12265,7 +12290,7 @@ async function Ki(e, t, n, r, i = !1, a) {
|
|
|
12265
12290
|
}
|
|
12266
12291
|
return { blocks: [] };
|
|
12267
12292
|
}
|
|
12268
|
-
function
|
|
12293
|
+
function Ji(e, t = {}) {
|
|
12269
12294
|
let n = {};
|
|
12270
12295
|
for (let [r, i] of Object.entries(e)) {
|
|
12271
12296
|
if (r === "id" && typeof i == "string" && i.startsWith("ast_")) {
|
|
@@ -12276,14 +12301,14 @@ function qi(e, t = {}) {
|
|
|
12276
12301
|
}
|
|
12277
12302
|
return n;
|
|
12278
12303
|
}
|
|
12279
|
-
function
|
|
12280
|
-
if (Array.isArray(e)) return e.map(
|
|
12304
|
+
function Yi(e) {
|
|
12305
|
+
if (Array.isArray(e)) return e.map(Yi);
|
|
12281
12306
|
if (!e || typeof e != "object") return e;
|
|
12282
12307
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
12283
12308
|
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 ? {
|
|
12284
12309
|
...t,
|
|
12285
12310
|
...t.crops?.[r] || {}
|
|
12286
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
12311
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Yi({
|
|
12287
12312
|
...n,
|
|
12288
12313
|
title: n?.title ?? e.title ?? "",
|
|
12289
12314
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -12297,9 +12322,9 @@ function Ji(e) {
|
|
|
12297
12322
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
12298
12323
|
};
|
|
12299
12324
|
}
|
|
12300
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
12325
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Yi(t)]));
|
|
12301
12326
|
}
|
|
12302
|
-
async function
|
|
12327
|
+
async function Xi(e, t, n) {
|
|
12303
12328
|
if (!t) return t;
|
|
12304
12329
|
if (typeof t == "string") {
|
|
12305
12330
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
@@ -12318,9 +12343,9 @@ async function Yi(e, t, n) {
|
|
|
12318
12343
|
return await Promise.all(Array.from(t.matchAll(d)).map(async (t) => {
|
|
12319
12344
|
let i = t[1], a = r(i, "data-node-id"), o = r(i, "data-tree-id");
|
|
12320
12345
|
if (!a || !o) return;
|
|
12321
|
-
let s = await
|
|
12346
|
+
let s = await Qi(e, a, o, n);
|
|
12322
12347
|
if (s?.treeNodeId) {
|
|
12323
|
-
let t = await
|
|
12348
|
+
let t = await na(e, String(s.treeNodeId), o, n);
|
|
12324
12349
|
u.set(`${a}:${o}`, t);
|
|
12325
12350
|
}
|
|
12326
12351
|
})), t.replace(d, (e, t) => {
|
|
@@ -12340,41 +12365,41 @@ async function Yi(e, t, n) {
|
|
|
12340
12365
|
return /href\s*=/.test(h) || (h += ` href="${m || "/"}"`), `<a ${h}>`;
|
|
12341
12366
|
});
|
|
12342
12367
|
}
|
|
12343
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
12368
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => Xi(e, t, n)));
|
|
12344
12369
|
if (typeof t == "object") {
|
|
12345
12370
|
let r = JSON.stringify(t);
|
|
12346
12371
|
if (!r.includes("#node:") && !r.includes("data-node-id") && !r.includes("#asset:") && !r.includes("data-asset-id")) return t;
|
|
12347
12372
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
|
|
12348
12373
|
...t,
|
|
12349
|
-
href: await
|
|
12374
|
+
href: await Zi(e, t, n)
|
|
12350
12375
|
};
|
|
12351
|
-
let i = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await
|
|
12376
|
+
let i = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await Xi(e, r, n)]));
|
|
12352
12377
|
return Object.fromEntries(i);
|
|
12353
12378
|
}
|
|
12354
12379
|
return t;
|
|
12355
12380
|
}
|
|
12356
|
-
async function
|
|
12381
|
+
async function Zi(e, t, n) {
|
|
12357
12382
|
let r = t.href.match(/^#node:(.+)$/), i = t.href.match(/^#asset:(.+)$/);
|
|
12358
|
-
if (i) return
|
|
12383
|
+
if (i) return ea(e, i[1], n);
|
|
12359
12384
|
if (!r) return t.href;
|
|
12360
12385
|
let a = r[1];
|
|
12361
12386
|
if (t.treeId) {
|
|
12362
|
-
let r = await
|
|
12387
|
+
let r = await Qi(e, a, String(t.treeId), n);
|
|
12363
12388
|
if (r?.treeNodeId) {
|
|
12364
|
-
let i = await
|
|
12389
|
+
let i = await na(e, String(r.treeNodeId), String(t.treeId), n);
|
|
12365
12390
|
if (i) return i;
|
|
12366
12391
|
}
|
|
12367
12392
|
}
|
|
12368
|
-
let o = await
|
|
12393
|
+
let o = await $i(e, a, n);
|
|
12369
12394
|
return o === void 0 ? "#" : `/${o}`;
|
|
12370
12395
|
}
|
|
12371
|
-
async function
|
|
12372
|
-
let i =
|
|
12396
|
+
async function Qi(e, t, n, r) {
|
|
12397
|
+
let i = Ui(t, n);
|
|
12373
12398
|
if (r.treeEdges.has(i)) return r.treeEdges.get(i);
|
|
12374
12399
|
let a = e.prepare("SELECT id as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
|
|
12375
12400
|
return r.treeEdges.set(i, Promise.resolve(a)), a;
|
|
12376
12401
|
}
|
|
12377
|
-
async function
|
|
12402
|
+
async function $i(e, t, n) {
|
|
12378
12403
|
let r = String(t);
|
|
12379
12404
|
if (n.nodeSlugs.has(r)) return n.nodeSlugs.get(r);
|
|
12380
12405
|
let i = (async () => {
|
|
@@ -12383,7 +12408,7 @@ async function Qi(e, t, n) {
|
|
|
12383
12408
|
})();
|
|
12384
12409
|
return n.nodeSlugs.set(r, i), i;
|
|
12385
12410
|
}
|
|
12386
|
-
async function
|
|
12411
|
+
async function ea(e, t, n) {
|
|
12387
12412
|
let r = String(t);
|
|
12388
12413
|
if (n.assetUrls.has(r)) return n.assetUrls.get(r);
|
|
12389
12414
|
let i = (async () => {
|
|
@@ -12392,7 +12417,7 @@ async function $i(e, t, n) {
|
|
|
12392
12417
|
})();
|
|
12393
12418
|
return n.assetUrls.set(r, i), i;
|
|
12394
12419
|
}
|
|
12395
|
-
function
|
|
12420
|
+
function ta(e) {
|
|
12396
12421
|
let t = e.socialImage;
|
|
12397
12422
|
if (!t || typeof t != "object") return null;
|
|
12398
12423
|
let n = (e, t) => {
|
|
@@ -12423,9 +12448,9 @@ function ea(e) {
|
|
|
12423
12448
|
])
|
|
12424
12449
|
};
|
|
12425
12450
|
}
|
|
12426
|
-
async function
|
|
12451
|
+
async function na(e, t, n, r) {
|
|
12427
12452
|
if (!t) return "";
|
|
12428
|
-
let i =
|
|
12453
|
+
let i = Ui(t, n);
|
|
12429
12454
|
if (r && r.fullPath.has(i)) return r.fullPath.get(i);
|
|
12430
12455
|
let a = (async () => {
|
|
12431
12456
|
let r = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, slug, level) AS (\n SELECT t.id, t.parentId, c.slug, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? AND t.treeId = ?\n UNION ALL\n SELECT t.id, t.parentId, c.slug, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId WHERE t.treeId = ?\n ) SELECT slug FROM ancestor_path ORDER BY level DESC\n ").all(t, n, n), i = Array.isArray(r) ? r : r?.results || [], a = [];
|
|
@@ -12437,7 +12462,7 @@ async function ta(e, t, n, r) {
|
|
|
12437
12462
|
})();
|
|
12438
12463
|
return r && r.fullPath.set(i, a), a;
|
|
12439
12464
|
}
|
|
12440
|
-
async function
|
|
12465
|
+
async function ra(e, t, n, r, i) {
|
|
12441
12466
|
let a = {}, o = null;
|
|
12442
12467
|
if (t) {
|
|
12443
12468
|
let n = await 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 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.id = ? OR c.id = ?\n UNION ALL\n SELECT t.id, t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.id = ap.parentId\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 = Array.isArray(n) ? n : n?.results || [], s = /* @__PURE__ */ new Set([
|
|
@@ -12475,13 +12500,13 @@ async function na(e, t, n, r, i) {
|
|
|
12475
12500
|
inheritedFields: a
|
|
12476
12501
|
};
|
|
12477
12502
|
}
|
|
12478
|
-
function
|
|
12503
|
+
function ia(e) {
|
|
12479
12504
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
12480
12505
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
12481
12506
|
}
|
|
12482
|
-
|
|
12507
|
+
Bi.get("/*", async (e) => {
|
|
12483
12508
|
try {
|
|
12484
|
-
let t = e.get("db"), n =
|
|
12509
|
+
let t = e.get("db"), n = Hi(), 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 t.prepare("SELECT * FROM channels WHERE key = ?").get(a) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(a));
|
|
12485
12510
|
if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
|
|
12486
12511
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
12487
12512
|
if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
|
|
@@ -12500,7 +12525,7 @@ zi.get("/*", async (e) => {
|
|
|
12500
12525
|
if (E.length > 0) {
|
|
12501
12526
|
let e = await Promise.all(E.map(async (e) => ({
|
|
12502
12527
|
candidate: e,
|
|
12503
|
-
calculatedPath: await
|
|
12528
|
+
calculatedPath: await na(t, String(e.treeNodeId), String(e.treeId), n)
|
|
12504
12529
|
}))), r = S.replace(/^\/+|\/+$/g, "");
|
|
12505
12530
|
for (let { candidate: t, calculatedPath: n } of e) {
|
|
12506
12531
|
let e = n.replace(/^\/+|\/+$/g, "");
|
|
@@ -12515,7 +12540,7 @@ zi.get("/*", async (e) => {
|
|
|
12515
12540
|
let e = y ? [_.id, y] : [_.id];
|
|
12516
12541
|
v = await t.prepare(`SELECT id as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${y ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
|
|
12517
12542
|
}
|
|
12518
|
-
let D = v?.treeId || y || "main-nav", O = v?.parentId || null, ee = v?.treeNodeId ? await
|
|
12543
|
+
let D = v?.treeId || y || "main-nav", O = v?.parentId || null, ee = v?.treeNodeId ? await na(t, String(v.treeNodeId), String(D), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, k = {}, te = s && _.draftDataJson ? _.draftDataJson : _.dataJson || _.draftDataJson;
|
|
12519
12544
|
if (te) try {
|
|
12520
12545
|
k = typeof te == "string" ? JSON.parse(te) : te;
|
|
12521
12546
|
} catch {}
|
|
@@ -12524,7 +12549,7 @@ zi.get("/*", async (e) => {
|
|
|
12524
12549
|
Object.assign(j, e.fields || {});
|
|
12525
12550
|
});
|
|
12526
12551
|
let ie = +!!s, [ae, oe, M] = await Promise.all([
|
|
12527
|
-
|
|
12552
|
+
ra(t, O, D, s, j),
|
|
12528
12553
|
v?.treeNodeId ? t.prepare("SELECT t.id as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.dataJson, c.draftDataJson FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? ORDER BY t.sortOrder ASC").all(v.treeNodeId, D) : Promise.resolve([]),
|
|
12529
12554
|
t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(_.id, ie)
|
|
12530
12555
|
]), { resolvedLayoutId: N, inheritedFields: se } = ae, P = {
|
|
@@ -12533,10 +12558,10 @@ zi.get("/*", async (e) => {
|
|
|
12533
12558
|
slug: _.slug,
|
|
12534
12559
|
path: ee === "" ? "/" : ee,
|
|
12535
12560
|
nodeType: ne,
|
|
12536
|
-
createdAt:
|
|
12537
|
-
updatedAt:
|
|
12538
|
-
publishedAt:
|
|
12539
|
-
}, ce = k.disabledRegions || {}, le = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", F = k.startShowingAt || null, ue = k.stopShowingAt || null, de =
|
|
12561
|
+
createdAt: Wi(_.createdAt),
|
|
12562
|
+
updatedAt: Wi(_.updatedAt),
|
|
12563
|
+
publishedAt: Wi(k.publishedAt || _.createdAt)
|
|
12564
|
+
}, ce = k.disabledRegions || {}, le = k.hidden === !0 || k.hidden === 1 || k.hidden === "1" || k.hidden === "true", F = k.startShowingAt || null, ue = k.stopShowingAt || null, de = Ji(k, j), fe = de.layoutId || null, pe = fe && fe !== "inherit", me = !1, I = null;
|
|
12540
12565
|
j.layoutId && (me = !0, j.layoutId.options && Array.isArray(j.layoutId.options) && (I = j.layoutId.options.map((e) => typeof e == "object" ? e.value || e.id : e)));
|
|
12541
12566
|
let he = null;
|
|
12542
12567
|
if (me && I && I.length === 1 && I[0] !== "inherit") he = I[0];
|
|
@@ -12547,10 +12572,10 @@ zi.get("/*", async (e) => {
|
|
|
12547
12572
|
}
|
|
12548
12573
|
for (let [e, t] of Object.entries(se)) j[e] && (de[e] === void 0 || de[e] === null || de[e] === "" || de[e] === "inherit") && t !== void 0 && (de[e] = t);
|
|
12549
12574
|
let L = await ui(t, de);
|
|
12550
|
-
L =
|
|
12551
|
-
let R =
|
|
12575
|
+
L = Yi(L), L = await Xi(t, L, n);
|
|
12576
|
+
let R = ta(L);
|
|
12552
12577
|
delete L.socialImage, delete L.fbImage, delete L.xImage, delete L.whatsappImage, R && (L.socialImages = R), delete L.id, delete L.title, delete L.slug, delete L.language, delete L.contentType, delete L.nodeType, delete L.createdAt, delete L.updatedAt, delete L.publishedAt, delete L.channelId, delete L.treeId, delete L.path, L.iconName === "" && (L.iconName = null), Object.assign(P, L), A.hasCanvas && (P.layoutId = he);
|
|
12553
|
-
let ge = Number(_.isHidden) === 1 || le, _e = !
|
|
12578
|
+
let ge = Number(_.isHidden) === 1 || le, _e = !Gi(F, ue);
|
|
12554
12579
|
if (!s && (ge || _e)) return e.json({ error: "Node is hidden or outside its scheduled publishing window" }, 404);
|
|
12555
12580
|
let ve = [];
|
|
12556
12581
|
if (v?.treeNodeId) {
|
|
@@ -12560,7 +12585,7 @@ zi.get("/*", async (e) => {
|
|
|
12560
12585
|
try {
|
|
12561
12586
|
n = (typeof r == "string" ? JSON.parse(r) : r) || {};
|
|
12562
12587
|
} catch {}
|
|
12563
|
-
let i = Number(e.isHidden) === 1 || n.hidden === !0 || n.hidden === 1 || n.hidden === "1", a =
|
|
12588
|
+
let i = Number(e.isHidden) === 1 || n.hidden === !0 || n.hidden === 1 || n.hidden === "1", a = Gi(n.startShowingAt, n.stopShowingAt), o = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
12564
12589
|
return !s && (i || !a) ? null : {
|
|
12565
12590
|
treeNodeId: e.treeNodeId,
|
|
12566
12591
|
id: e.id,
|
|
@@ -12583,10 +12608,10 @@ zi.get("/*", async (e) => {
|
|
|
12583
12608
|
try {
|
|
12584
12609
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
12585
12610
|
} catch {}
|
|
12586
|
-
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o =
|
|
12611
|
+
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Gi(i.startShowingAt, i.stopShowingAt);
|
|
12587
12612
|
if (!s && (a || !o)) return null;
|
|
12588
|
-
let c = e.elementType || e.componentId || "text-block", l = h.blocks?.[c]?.fields || h.elements?.[c]?.fields || h.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || (i.id && !String(i.id).startsWith("ast_") ? i.id : null) || e.blockId || e.id), d =
|
|
12589
|
-
return d = await ui(t, d), d =
|
|
12613
|
+
let c = e.elementType || e.componentId || "text-block", l = h.blocks?.[c]?.fields || h.elements?.[c]?.fields || h.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || (i.id && !String(i.id).startsWith("ast_") ? i.id : null) || e.blockId || e.id), d = Ji(i, l);
|
|
12614
|
+
return d = await ui(t, d), d = Yi(d), d = await Xi(t, d, n), d.blockId = u, {
|
|
12590
12615
|
region: r,
|
|
12591
12616
|
block: {
|
|
12592
12617
|
instanceId: e.id,
|
|
@@ -12611,7 +12636,7 @@ zi.get("/*", async (e) => {
|
|
|
12611
12636
|
for (let [e, r] of Object.entries(xe)) {
|
|
12612
12637
|
let i = z[e] && z[e].length > 0, a = !!ce[e];
|
|
12613
12638
|
if (z[e] || (z[e] = [], B[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && O) {
|
|
12614
|
-
let r = await
|
|
12639
|
+
let r = await qi(t, O, e, h, s, n);
|
|
12615
12640
|
if (r.blocks.length > 0 && (z[e] = r.blocks, B[e] = {
|
|
12616
12641
|
isInherited: !0,
|
|
12617
12642
|
inheritedFromId: r.inheritedFromId,
|
|
@@ -12623,7 +12648,7 @@ zi.get("/*", async (e) => {
|
|
|
12623
12648
|
});
|
|
12624
12649
|
}
|
|
12625
12650
|
}
|
|
12626
|
-
await Promise.all(Object.keys(z).map((e) =>
|
|
12651
|
+
await Promise.all(Object.keys(z).map((e) => Ki(t, z[e], u)));
|
|
12627
12652
|
let Se = {
|
|
12628
12653
|
channelId: u || d,
|
|
12629
12654
|
treeId: D,
|
|
@@ -12632,7 +12657,7 @@ zi.get("/*", async (e) => {
|
|
|
12632
12657
|
content: z,
|
|
12633
12658
|
regionMeta: B
|
|
12634
12659
|
};
|
|
12635
|
-
return !s && !m ? (e.header("X-Cache", "MISS"),
|
|
12660
|
+
return !s && !m ? (e.header("X-Cache", "MISS"), Vi(e, f.set(p, Se, ia(e)))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(Se);
|
|
12636
12661
|
} catch (t) {
|
|
12637
12662
|
console.error("[CMS Public API] Error fetching node by path:", t);
|
|
12638
12663
|
let n = e.env?.ENVIRONMENT === "development";
|
|
@@ -12644,14 +12669,14 @@ zi.get("/*", async (e) => {
|
|
|
12644
12669
|
});
|
|
12645
12670
|
//#endregion
|
|
12646
12671
|
//#region server/routes/public/tree.ts
|
|
12647
|
-
var
|
|
12648
|
-
function
|
|
12672
|
+
var aa = new n();
|
|
12673
|
+
function oa(e, t) {
|
|
12649
12674
|
let n = Promise.resolve(t).catch((e) => console.error("[Background Task Error]:", e));
|
|
12650
12675
|
try {
|
|
12651
12676
|
e.executionCtx && typeof e.executionCtx.waitUntil == "function" && e.executionCtx.waitUntil(n);
|
|
12652
12677
|
} catch {}
|
|
12653
12678
|
}
|
|
12654
|
-
function
|
|
12679
|
+
function sa(e, t) {
|
|
12655
12680
|
let n = /* @__PURE__ */ new Date();
|
|
12656
12681
|
if (e && String(e).trim() !== "") {
|
|
12657
12682
|
let t = new Date(e);
|
|
@@ -12663,7 +12688,7 @@ function oa(e, t) {
|
|
|
12663
12688
|
}
|
|
12664
12689
|
return !0;
|
|
12665
12690
|
}
|
|
12666
|
-
|
|
12691
|
+
aa.get("/:treeParam", async (e) => {
|
|
12667
12692
|
try {
|
|
12668
12693
|
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";
|
|
12669
12694
|
if (r && r !== "default" && r !== "all") {
|
|
@@ -12741,7 +12766,7 @@ ia.get("/:treeParam", async (e) => {
|
|
|
12741
12766
|
"isHidden",
|
|
12742
12767
|
"status"
|
|
12743
12768
|
].includes(e) || (r[e] = t);
|
|
12744
|
-
let a = !i && (e.status === "draft" || e.status === "new"), o = Number(e.isHidden) === 1 || a || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s =
|
|
12769
|
+
let a = !i && (e.status === "draft" || e.status === "new"), o = Number(e.isHidden) === 1 || a || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = sa(n.startShowingAt, n.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = (!e.parentId || e.parentId === "null" || e.parentId === "") && (c === "home" || c === "homee") ? "/" : `${t}/${c}`.replace(/\/+/g, "/"), u = {
|
|
12745
12770
|
id: e.id,
|
|
12746
12771
|
treeNodeId: e.treeNodeId,
|
|
12747
12772
|
parentId: e.parentId || null,
|
|
@@ -12766,7 +12791,7 @@ ia.get("/:treeParam", async (e) => {
|
|
|
12766
12791
|
...m,
|
|
12767
12792
|
items: _(null)
|
|
12768
12793
|
};
|
|
12769
|
-
return !i && !s ? (e.header("X-Cache", "MISS"),
|
|
12794
|
+
return !i && !s ? (e.header("X-Cache", "MISS"), oa(e, a.set(o, v, 300))) : e.header("Cache-Control", "no-store, no-cache, must-revalidate"), e.json(v);
|
|
12770
12795
|
} catch (t) {
|
|
12771
12796
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
12772
12797
|
error: "Failed to fetch public tree",
|
|
@@ -12776,8 +12801,8 @@ ia.get("/:treeParam", async (e) => {
|
|
|
12776
12801
|
});
|
|
12777
12802
|
//#endregion
|
|
12778
12803
|
//#region server/routes/public/assets.ts
|
|
12779
|
-
var
|
|
12780
|
-
function
|
|
12804
|
+
var ca = new n();
|
|
12805
|
+
function la(e, t) {
|
|
12781
12806
|
if (t === "webp") return "image/webp";
|
|
12782
12807
|
if (t === "avif") return "image/avif";
|
|
12783
12808
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -12785,7 +12810,7 @@ function ca(e, t) {
|
|
|
12785
12810
|
let n = e.toLowerCase();
|
|
12786
12811
|
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";
|
|
12787
12812
|
}
|
|
12788
|
-
|
|
12813
|
+
ca.get("/*", async (e) => {
|
|
12789
12814
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
12790
12815
|
if (!t) return e.text("Asset key missing", 400);
|
|
12791
12816
|
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 = "";
|
|
@@ -12802,7 +12827,7 @@ sa.get("/*", async (e) => {
|
|
|
12802
12827
|
}
|
|
12803
12828
|
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;
|
|
12804
12829
|
if (n) {
|
|
12805
|
-
let l =
|
|
12830
|
+
let l = la(t), u = l.startsWith("image/") && !l.includes("svg");
|
|
12806
12831
|
if (s && u && h && !p) {
|
|
12807
12832
|
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}`;
|
|
12808
12833
|
try {
|
|
@@ -12845,7 +12870,7 @@ sa.get("/*", async (e) => {
|
|
|
12845
12870
|
if (!s) {
|
|
12846
12871
|
let n = _(C);
|
|
12847
12872
|
return e.body(n, 200, {
|
|
12848
|
-
"Content-Type":
|
|
12873
|
+
"Content-Type": la(t),
|
|
12849
12874
|
"Cache-Control": "public, max-age=86400"
|
|
12850
12875
|
});
|
|
12851
12876
|
}
|
|
@@ -12853,7 +12878,7 @@ sa.get("/*", async (e) => {
|
|
|
12853
12878
|
if (g(f)) {
|
|
12854
12879
|
let n = _(f);
|
|
12855
12880
|
return e.body(n, 200, {
|
|
12856
|
-
"Content-Type":
|
|
12881
|
+
"Content-Type": la(t, u),
|
|
12857
12882
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
12858
12883
|
"X-Local-Cache": "HIT"
|
|
12859
12884
|
});
|
|
@@ -12866,14 +12891,14 @@ sa.get("/*", async (e) => {
|
|
|
12866
12891
|
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 }));
|
|
12867
12892
|
let s = await i.toBuffer();
|
|
12868
12893
|
return v(x(f), { recursive: !0 }), y(f, s), e.body(s, 200, {
|
|
12869
|
-
"Content-Type":
|
|
12894
|
+
"Content-Type": la(t, u),
|
|
12870
12895
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
12871
12896
|
"X-Local-Cache": "MISS"
|
|
12872
12897
|
});
|
|
12873
12898
|
} catch {
|
|
12874
12899
|
let n = _(C);
|
|
12875
12900
|
return e.body(n, 200, {
|
|
12876
|
-
"Content-Type":
|
|
12901
|
+
"Content-Type": la(t),
|
|
12877
12902
|
"Cache-Control": "public, max-age=86400"
|
|
12878
12903
|
});
|
|
12879
12904
|
}
|
|
@@ -12884,8 +12909,8 @@ sa.get("/*", async (e) => {
|
|
|
12884
12909
|
});
|
|
12885
12910
|
//#endregion
|
|
12886
12911
|
//#region server/routes/public/paths.ts
|
|
12887
|
-
var
|
|
12888
|
-
function
|
|
12912
|
+
var ua = new n();
|
|
12913
|
+
function da(e, t) {
|
|
12889
12914
|
let n = /* @__PURE__ */ new Date();
|
|
12890
12915
|
if (e && String(e).trim() !== "") {
|
|
12891
12916
|
let t = new Date(e);
|
|
@@ -12897,7 +12922,7 @@ function ua(e, t) {
|
|
|
12897
12922
|
}
|
|
12898
12923
|
return !0;
|
|
12899
12924
|
}
|
|
12900
|
-
|
|
12925
|
+
ua.get("/", async (e) => {
|
|
12901
12926
|
try {
|
|
12902
12927
|
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();
|
|
12903
12928
|
for (let e of n) {
|
|
@@ -12921,7 +12946,7 @@ la.get("/", async (e) => {
|
|
|
12921
12946
|
function o(e = null, t = "") {
|
|
12922
12947
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
|
|
12923
12948
|
for (let e of s) {
|
|
12924
|
-
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s =
|
|
12949
|
+
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = da(n.startShowingAt, n.stopShowingAt);
|
|
12925
12950
|
if (!i || !s) continue;
|
|
12926
12951
|
let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
|
|
12927
12952
|
e.nodeType !== "external-link" && r.push(l);
|
|
@@ -12938,7 +12963,7 @@ la.get("/", async (e) => {
|
|
|
12938
12963
|
});
|
|
12939
12964
|
//#endregion
|
|
12940
12965
|
//#region server/index.ts
|
|
12941
|
-
var
|
|
12966
|
+
var fa = Nr(), $ = new n(), pa = !1;
|
|
12942
12967
|
$.use("*", Fr()), $.use("/media/*", Fr({
|
|
12943
12968
|
origin: "*",
|
|
12944
12969
|
allowMethods: [
|
|
@@ -12956,18 +12981,18 @@ $.use("*", Fr()), $.use("/media/*", Fr({
|
|
|
12956
12981
|
await t(), e.header("Cache-Control", "public, max-age=31536000, immutable"), e.header("Access-Control-Allow-Origin", "*");
|
|
12957
12982
|
}), $.use("*", async (e, t) => {
|
|
12958
12983
|
if (e.req.path.startsWith("/media/")) return t();
|
|
12959
|
-
let n =
|
|
12984
|
+
let n = fa;
|
|
12960
12985
|
e.env?.BUNDLED_DEFINITIONS && (e.env.BUNDLED_DEFINITIONS._isCompiled || (e.env.BUNDLED_DEFINITIONS = Nr(e.env.BUNDLED_DEFINITIONS), e.env.BUNDLED_DEFINITIONS._isCompiled = !0), n = e.env.BUNDLED_DEFINITIONS), e.set("schemas", n);
|
|
12961
12986
|
let r = new URL(e.req.url), i = (e.req.header("host") || r.hostname).split(":")[0];
|
|
12962
12987
|
e.set("currentDomain", i);
|
|
12963
12988
|
let a = zr(e);
|
|
12964
|
-
if (e.set("db", a), !
|
|
12965
|
-
await Ur(a, n),
|
|
12989
|
+
if (e.set("db", a), !pa) try {
|
|
12990
|
+
await Ur(a, n), pa = !0;
|
|
12966
12991
|
} catch (e) {
|
|
12967
12992
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
12968
12993
|
}
|
|
12969
12994
|
await t();
|
|
12970
|
-
}), $.route("/media",
|
|
12995
|
+
}), $.route("/media", ca), $.use("/media/*", Gr()), $.route("/api/cms/nodes", Z), $.route("/api/cms/nodes.json", Z), $.route("/api/cms/formcsv", Z), $.route("/api/cms/formcsv.json", Z), $.route("/api/cms/stats", Mi), $.route("/api/cms/stats.json", Mi), $.route("/api/cms", yi), $.route("/api/cms/channels", wi), $.route("/api/cms/channels.json", wi), $.route("/api/cms/schemas", Ei), $.route("/api/cms/schemas.json", Ei), $.route("/api/admin/schemas", Ei), $.route("/api/cms", ki), $.route("/api/admin/assets", Li), $.route("/api/v1/node", Bi), $.route("/api/v1/page", Bi), $.route("/api/v1/tree", aa), $.route("/api/v1/all-paths", ua), $.get("*", async (e) => {
|
|
12971
12996
|
if (e.env?.ASSETS) {
|
|
12972
12997
|
let t = await e.env.ASSETS.fetch(e.req.raw);
|
|
12973
12998
|
if (t.status === 404) {
|