@brightsideoy/kama 0.1.0-alpha.86 → 0.1.0-alpha.87
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-BvcEh0__.css → index-Dgg7MfYy.css} +1 -1
- package/dist/assets/index-m96oHQ-x.js +1388 -0
- package/dist/index.html +2 -2
- package/dist/index.js +149 -136
- package/package.json +1 -1
- package/dist/assets/index-BTi6oBGA.js +0 -1388
package/dist/index.js
CHANGED
|
@@ -7406,7 +7406,13 @@ var X = class {
|
|
|
7406
7406
|
this.env = e, this.zoneId = e.CLOUDFLARE_ZONE_ID, this.apiToken = e.CLOUDFLARE_API_TOKEN, this.frontendUrl = (e.PUBLIC_FRONTEND_URL || "https://kama.t3cloud.eu").replace(/\/+$/, "");
|
|
7407
7407
|
}
|
|
7408
7408
|
dispatch(e, t) {
|
|
7409
|
-
|
|
7409
|
+
try {
|
|
7410
|
+
if (e.executionCtx && typeof e.executionCtx.waitUntil == "function") {
|
|
7411
|
+
e.executionCtx.waitUntil(t);
|
|
7412
|
+
return;
|
|
7413
|
+
}
|
|
7414
|
+
} catch {}
|
|
7415
|
+
t.catch((e) => console.warn("[CacheManager Warn]:", e));
|
|
7410
7416
|
}
|
|
7411
7417
|
async callAstroPurge(e, t) {
|
|
7412
7418
|
let n = `${this.frontendUrl}/api/purge`, r = {
|
|
@@ -7849,17 +7855,18 @@ Z.get("/", async (e) => {
|
|
|
7849
7855
|
}
|
|
7850
7856
|
}
|
|
7851
7857
|
if (g !== void 0 && Array.isArray(g) && w) {
|
|
7858
|
+
let e = await t.prepare("SELECT treeId, parentId, sortOrder FROM tree_nodes WHERE contentId = ?").all(w), n = Array.isArray(e) ? e : e?.results || [];
|
|
7852
7859
|
await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(w);
|
|
7853
|
-
let
|
|
7854
|
-
for (let
|
|
7855
|
-
let
|
|
7856
|
-
if (!
|
|
7857
|
-
|
|
7858
|
-
let
|
|
7859
|
-
|
|
7860
|
+
let r = /* @__PURE__ */ new Set(), i = [], a = [];
|
|
7861
|
+
for (let e of g) if (e && e.treeId) {
|
|
7862
|
+
let t = Number(e.treeId) || e.treeId;
|
|
7863
|
+
if (!r.has(t)) {
|
|
7864
|
+
r.add(t);
|
|
7865
|
+
let o = hi(e.parentId ?? e._draftParentId ?? null), s = n.find((e) => e.treeId === t), c = 0;
|
|
7866
|
+
typeof e.sortOrder == "number" ? c = e.sortOrder : s && typeof s.sortOrder == "number" && (c = s.sortOrder), i.push("(?, ?, ?, ?)"), a.push(t, w, o, c);
|
|
7860
7867
|
}
|
|
7861
7868
|
}
|
|
7862
|
-
|
|
7869
|
+
i.length > 0 && await t.prepare(`INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES ${i.join(", ")}`).run(...a);
|
|
7863
7870
|
}
|
|
7864
7871
|
let E = [];
|
|
7865
7872
|
if (m !== void 0 && Array.isArray(m) && w) {
|
|
@@ -7945,7 +7952,7 @@ Z.get("/", async (e) => {
|
|
|
7945
7952
|
let a = new X(e.env);
|
|
7946
7953
|
if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
|
|
7947
7954
|
let n = await fi(t, r);
|
|
7948
|
-
a.purgeSmart(e, t, r, i.slug, n, !0);
|
|
7955
|
+
i.slug && a.purgeAndWarmSlug(e, i.slug, n), a.purgeSmart(e, t, r, i.slug, n, !0);
|
|
7949
7956
|
}
|
|
7950
7957
|
return e.json({
|
|
7951
7958
|
success: !0,
|
|
@@ -7955,11 +7962,12 @@ Z.get("/", async (e) => {
|
|
|
7955
7962
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
7956
7963
|
if (!r) return e.json({ error: "Node ID required" }, 400);
|
|
7957
7964
|
let i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r);
|
|
7965
|
+
if (!i) return e.json({ error: "Node not found" }, 404);
|
|
7958
7966
|
await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await J(e).clear();
|
|
7959
7967
|
let a = new X(e.env);
|
|
7960
7968
|
if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
|
|
7961
7969
|
let n = await fi(t, r);
|
|
7962
|
-
a.purgeSmart(e, t, r, i.slug, n, !0);
|
|
7970
|
+
i.slug && a.purgeAndWarmSlug(e, i.slug, n), a.purgeSmart(e, t, r, i.slug, n, !0);
|
|
7963
7971
|
}
|
|
7964
7972
|
return e.json({
|
|
7965
7973
|
success: !0,
|
|
@@ -7969,7 +7977,7 @@ Z.get("/", async (e) => {
|
|
|
7969
7977
|
let t = e.get("db"), n = e.req.query("id");
|
|
7970
7978
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
7971
7979
|
let r = Number(n), i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r), a = await fi(t, r), o = new X(e.env);
|
|
7972
|
-
return i && await o.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await J(e).clear(), i && i.status === "published" && o.purgeSmart(e, t, r, i.slug, a, !0), e.json({
|
|
7980
|
+
return i && await o.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await J(e).clear(), i && i.status === "published" && (i.slug && o.purgeAndWarmSlug(e, i.slug, a), o.purgeSmart(e, t, r, i.slug, a, !0)), e.json({
|
|
7973
7981
|
success: !0,
|
|
7974
7982
|
purgedNodeId: r
|
|
7975
7983
|
});
|
|
@@ -8001,6 +8009,15 @@ function Si(e) {
|
|
|
8001
8009
|
function Ci(e) {
|
|
8002
8010
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
8003
8011
|
}
|
|
8012
|
+
function wi(e, t) {
|
|
8013
|
+
try {
|
|
8014
|
+
if (e.executionCtx && typeof e.executionCtx.waitUntil == "function") {
|
|
8015
|
+
e.executionCtx.waitUntil(t);
|
|
8016
|
+
return;
|
|
8017
|
+
}
|
|
8018
|
+
} catch {}
|
|
8019
|
+
t.catch((e) => console.error("[Tree bgTask Error]:", e));
|
|
8020
|
+
}
|
|
8004
8021
|
bi.get("/tree.json", async (e) => {
|
|
8005
8022
|
try {
|
|
8006
8023
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
@@ -8078,7 +8095,7 @@ bi.get("/tree.json", async (e) => {
|
|
|
8078
8095
|
c.push(e.id, e.sortOrder);
|
|
8079
8096
|
}), c.push(...i), c.push(o), await t.prepare(s).run(...c);
|
|
8080
8097
|
}
|
|
8081
|
-
return await i.clear(),
|
|
8098
|
+
return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
|
|
8082
8099
|
success: !0,
|
|
8083
8100
|
reorderedCount: r.length
|
|
8084
8101
|
});
|
|
@@ -8117,7 +8134,7 @@ bi.get("/tree.json", async (e) => {
|
|
|
8117
8134
|
let e = b.map(() => "(?, ?)").join(", "), n = b.flatMap((e) => [f, e]);
|
|
8118
8135
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
8119
8136
|
}
|
|
8120
|
-
return await i.clear(),
|
|
8137
|
+
return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
|
|
8121
8138
|
success: !0,
|
|
8122
8139
|
id: f,
|
|
8123
8140
|
treeNodeId: v,
|
|
@@ -8155,14 +8172,14 @@ bi.get("/tree.json", async (e) => {
|
|
|
8155
8172
|
}
|
|
8156
8173
|
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d);
|
|
8157
8174
|
let r = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), s = Number(r.lastInsertRowid);
|
|
8158
|
-
return await i.clear(),
|
|
8175
|
+
return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
|
|
8159
8176
|
success: !0,
|
|
8160
8177
|
treeNodeId: s
|
|
8161
8178
|
});
|
|
8162
8179
|
}
|
|
8163
8180
|
if (s === "detach") {
|
|
8164
8181
|
let r = n.treeNodeId || n.contentId;
|
|
8165
|
-
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, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?").run(r, r, o), await i.clear(),
|
|
8182
|
+
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, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE (id = ? OR contentId = ?) AND treeId = ?").run(r, r, o), await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
|
|
8166
8183
|
}
|
|
8167
8184
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
8168
8185
|
} catch (t) {
|
|
@@ -8226,9 +8243,7 @@ bi.get("/tree.json", async (e) => {
|
|
|
8226
8243
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
8227
8244
|
}
|
|
8228
8245
|
}
|
|
8229
|
-
await J(e).clear()
|
|
8230
|
-
let m = new X(e.env);
|
|
8231
|
-
return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(m.purgeGlobalCacheDirect(e, t)) : await m.purgeGlobalCacheDirect(e, t), e.json({
|
|
8246
|
+
return await J(e).clear(), wi(e, new X(e.env).purgeGlobalCacheDirect(e, t)), e.json({
|
|
8232
8247
|
success: !0,
|
|
8233
8248
|
id: p,
|
|
8234
8249
|
key: o,
|
|
@@ -8247,9 +8262,7 @@ bi.get("/tree.json", async (e) => {
|
|
|
8247
8262
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
8248
8263
|
let r = Number(n);
|
|
8249
8264
|
try {
|
|
8250
|
-
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), await J(e).clear()
|
|
8251
|
-
let n = new X(e.env);
|
|
8252
|
-
return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
|
|
8265
|
+
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), await J(e).clear(), wi(e, new X(e.env).purgeGlobalCacheDirect(e, t)), e.json({
|
|
8253
8266
|
success: !0,
|
|
8254
8267
|
deletedTreeId: r
|
|
8255
8268
|
});
|
|
@@ -8259,8 +8272,8 @@ bi.get("/tree.json", async (e) => {
|
|
|
8259
8272
|
});
|
|
8260
8273
|
//#endregion
|
|
8261
8274
|
//#region server/routes/admin/channels.ts
|
|
8262
|
-
var
|
|
8263
|
-
|
|
8275
|
+
var Ti = new e();
|
|
8276
|
+
Ti.get("/", async (e) => {
|
|
8264
8277
|
try {
|
|
8265
8278
|
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").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
|
|
8266
8279
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -8326,7 +8339,7 @@ wi.get("/", async (e) => {
|
|
|
8326
8339
|
error: t.message
|
|
8327
8340
|
}, 500);
|
|
8328
8341
|
}
|
|
8329
|
-
}),
|
|
8342
|
+
}), Ti.post("/", async (e) => {
|
|
8330
8343
|
try {
|
|
8331
8344
|
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 = "website", domain: c = "localhost", baseUrl: l = "http://localhost:4321", defaultLanguage: u = "en", 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 = Array.isArray(f) ? f : [], S = JSON.stringify(v || {}), C = e.get("user")?.id || m || p || null;
|
|
8332
8345
|
if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
|
|
@@ -8365,7 +8378,7 @@ wi.get("/", async (e) => {
|
|
|
8365
8378
|
details: t.message
|
|
8366
8379
|
}, 500);
|
|
8367
8380
|
}
|
|
8368
|
-
}),
|
|
8381
|
+
}), Ti.delete("/", async (e) => {
|
|
8369
8382
|
let t = e.get("db"), n = e.req.query("id");
|
|
8370
8383
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
8371
8384
|
let r = Number(n);
|
|
@@ -8385,9 +8398,9 @@ wi.get("/", async (e) => {
|
|
|
8385
8398
|
});
|
|
8386
8399
|
//#endregion
|
|
8387
8400
|
//#region server/routes/admin/schemas.ts
|
|
8388
|
-
var
|
|
8401
|
+
var Ei = new e(), Di = null, Oi = (e) => {
|
|
8389
8402
|
try {
|
|
8390
|
-
if (!
|
|
8403
|
+
if (!Di) {
|
|
8391
8404
|
let t = ci(e.env?.BUNDLED_DEFINITIONS || Or), n = t.userTemplate || {
|
|
8392
8405
|
id: "userTemplate",
|
|
8393
8406
|
label: "User Account",
|
|
@@ -8424,7 +8437,7 @@ var Ti = new e(), Ei = null, Di = (e) => {
|
|
|
8424
8437
|
}
|
|
8425
8438
|
}
|
|
8426
8439
|
};
|
|
8427
|
-
|
|
8440
|
+
Di = {
|
|
8428
8441
|
channelTemplate: t.channelTemplate || null,
|
|
8429
8442
|
treeTemplate: t.treeTemplate || null,
|
|
8430
8443
|
userTemplate: n,
|
|
@@ -8436,7 +8449,7 @@ var Ti = new e(), Ei = null, Di = (e) => {
|
|
|
8436
8449
|
blockLayouts: t.blockLayouts || {}
|
|
8437
8450
|
};
|
|
8438
8451
|
}
|
|
8439
|
-
return e.json(
|
|
8452
|
+
return e.json(Di, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
|
|
8440
8453
|
} catch (t) {
|
|
8441
8454
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
8442
8455
|
error: "Failed to load schemas",
|
|
@@ -8444,10 +8457,10 @@ var Ti = new e(), Ei = null, Di = (e) => {
|
|
|
8444
8457
|
}, 500);
|
|
8445
8458
|
}
|
|
8446
8459
|
};
|
|
8447
|
-
|
|
8460
|
+
Ei.get("/", Oi), Ei.get("/schemas.json", Oi);
|
|
8448
8461
|
//#endregion
|
|
8449
8462
|
//#region server/routes/admin/validation.ts
|
|
8450
|
-
var
|
|
8463
|
+
var ki = new e(), Ai = {
|
|
8451
8464
|
node: "content_nodes",
|
|
8452
8465
|
nodes: "content_nodes",
|
|
8453
8466
|
content_node: "content_nodes",
|
|
@@ -8459,7 +8472,7 @@ var Oi = new e(), ki = {
|
|
|
8459
8472
|
user: "users",
|
|
8460
8473
|
users: "users",
|
|
8461
8474
|
user_account: "user_accounts"
|
|
8462
|
-
},
|
|
8475
|
+
}, ji = {
|
|
8463
8476
|
content_nodes: [
|
|
8464
8477
|
"id",
|
|
8465
8478
|
"title",
|
|
@@ -8516,11 +8529,11 @@ var Oi = new e(), ki = {
|
|
|
8516
8529
|
"createdAt"
|
|
8517
8530
|
]
|
|
8518
8531
|
};
|
|
8519
|
-
|
|
8532
|
+
ki.post("/validate-unique", async (e) => {
|
|
8520
8533
|
try {
|
|
8521
8534
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
8522
8535
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
8523
|
-
let o =
|
|
8536
|
+
let o = Ai[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (ji[o] || ji.content_nodes).includes(s), l = -1;
|
|
8524
8537
|
if (a != null && String(a).trim() !== "") {
|
|
8525
8538
|
let e = Number(a);
|
|
8526
8539
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -8532,7 +8545,7 @@ Oi.post("/validate-unique", async (e) => {
|
|
|
8532
8545
|
} catch (t) {
|
|
8533
8546
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
8534
8547
|
}
|
|
8535
|
-
}),
|
|
8548
|
+
}), ki.post("/validate-unique-sibling", async (e) => {
|
|
8536
8549
|
try {
|
|
8537
8550
|
let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
|
|
8538
8551
|
if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
|
|
@@ -8559,8 +8572,8 @@ Oi.post("/validate-unique", async (e) => {
|
|
|
8559
8572
|
});
|
|
8560
8573
|
//#endregion
|
|
8561
8574
|
//#region server/routes/admin/stats.ts
|
|
8562
|
-
var
|
|
8563
|
-
|
|
8575
|
+
var Mi = new e();
|
|
8576
|
+
Mi.get("/", async (e) => {
|
|
8564
8577
|
try {
|
|
8565
8578
|
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) => ({
|
|
8566
8579
|
...e,
|
|
@@ -8603,7 +8616,7 @@ ji.get("/", async (e) => {
|
|
|
8603
8616
|
});
|
|
8604
8617
|
//#endregion
|
|
8605
8618
|
//#region server/routes/admin/assets.ts
|
|
8606
|
-
var
|
|
8619
|
+
var Ni = new e();
|
|
8607
8620
|
async function Q(e, t, n = []) {
|
|
8608
8621
|
let r = e.prepare(t);
|
|
8609
8622
|
if (typeof r.bind == "function") {
|
|
@@ -8616,20 +8629,20 @@ async function Q(e, t, n = []) {
|
|
|
8616
8629
|
}
|
|
8617
8630
|
return [];
|
|
8618
8631
|
}
|
|
8619
|
-
async function
|
|
8632
|
+
async function Pi(e, t, n = []) {
|
|
8620
8633
|
let r = e.prepare(t);
|
|
8621
8634
|
if (typeof r.bind == "function") return await r.bind(...n).run();
|
|
8622
8635
|
if (typeof r.run == "function") return await r.run(...n);
|
|
8623
8636
|
}
|
|
8624
|
-
function
|
|
8637
|
+
function Fi(e, t, n) {
|
|
8625
8638
|
let r = e || (t ? `/media/${t}` : "");
|
|
8626
8639
|
return r && n && r.startsWith(`https://${n}/`) && !r.includes("/media/") && (r = r.replace(`https://${n}/`, `https://${n}/media/`)), r;
|
|
8627
8640
|
}
|
|
8628
|
-
async function
|
|
8641
|
+
async function Ii(e, t, n) {
|
|
8629
8642
|
try {
|
|
8630
8643
|
let r = new X(e.env), i = await Q(t, "\n SELECT cdnUrl, storageKeyPrivate\n FROM assets\n WHERE id = ? OR parentAssetId = ?\n ", [n, n]), a = [];
|
|
8631
8644
|
for (let t of i) {
|
|
8632
|
-
let n =
|
|
8645
|
+
let n = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
8633
8646
|
n && a.push(n);
|
|
8634
8647
|
}
|
|
8635
8648
|
let o = await Q(t, "\n SELECT DISTINCT cn.id, cn.slug, cn.status\n FROM node_assets na\n INNER JOIN content_nodes cn ON na.nodeId = cn.id\n LEFT JOIN assets crop ON na.assetId = crop.id\n WHERE cn.status = 'published' AND (\n na.assetId = ?\n OR crop.parentAssetId = ?\n OR crop.id = (SELECT parentAssetId FROM assets WHERE id = ?)\n )\n ", [
|
|
@@ -8643,7 +8656,7 @@ async function Fi(e, t, n) {
|
|
|
8643
8656
|
console.warn("[Assets Router] Failed to purge edge cache for asset nodes:", e);
|
|
8644
8657
|
}
|
|
8645
8658
|
}
|
|
8646
|
-
|
|
8659
|
+
Ni.get("/", async (e) => {
|
|
8647
8660
|
try {
|
|
8648
8661
|
let t = u(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: d } = e.req.query(), f = Math.max(1, parseInt(i, 10) || 1), p = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), m = (f - 1) * p, h = {
|
|
8649
8662
|
createdAt: "a.createdAt",
|
|
@@ -8710,7 +8723,7 @@ Mi.get("/", async (e) => {
|
|
|
8710
8723
|
...JSON.parse(t.dataJson || "{}")
|
|
8711
8724
|
};
|
|
8712
8725
|
} catch {}
|
|
8713
|
-
let r =
|
|
8726
|
+
let r = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
8714
8727
|
return {
|
|
8715
8728
|
id: t.id,
|
|
8716
8729
|
filename: t.filename || "Untitled Asset",
|
|
@@ -8734,7 +8747,7 @@ Mi.get("/", async (e) => {
|
|
|
8734
8747
|
details: t.message || String(t)
|
|
8735
8748
|
}, 500);
|
|
8736
8749
|
}
|
|
8737
|
-
}),
|
|
8750
|
+
}), Ni.post("/upload", async (e) => {
|
|
8738
8751
|
try {
|
|
8739
8752
|
let t = u(e), n = ni(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;
|
|
8740
8753
|
s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
|
|
@@ -8753,7 +8766,7 @@ Mi.get("/", async (e) => {
|
|
|
8753
8766
|
let y = e.env.CDN_DOMAIN, b = v.replace(/^\//, ""), x = y ? `https://${y}/media/${b}` : `/media/${b}`, S = i.type || "application/octet-stream", C = i.size || 0, w = e.get("userId"), T = typeof w == "string" && w.trim().length > 0 ? w : null;
|
|
8754
8767
|
T && (await Q(t, "SELECT id FROM users WHERE id = ?", [T])).length === 0 && (T = null);
|
|
8755
8768
|
let E = +!!h;
|
|
8756
|
-
await
|
|
8769
|
+
await Pi(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
|
|
8757
8770
|
p,
|
|
8758
8771
|
i.name,
|
|
8759
8772
|
S,
|
|
@@ -8768,7 +8781,7 @@ Mi.get("/", async (e) => {
|
|
|
8768
8781
|
let D = x;
|
|
8769
8782
|
if (s) {
|
|
8770
8783
|
let n = await Q(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [s]);
|
|
8771
|
-
n.length > 0 && (D =
|
|
8784
|
+
n.length > 0 && (D = Fi(n[0].cdnUrl, n[0].storageKeyPrivate, y)), await Ii(e, t, s);
|
|
8772
8785
|
}
|
|
8773
8786
|
return e.json({
|
|
8774
8787
|
id: p,
|
|
@@ -8787,7 +8800,7 @@ Mi.get("/", async (e) => {
|
|
|
8787
8800
|
details: t.message || String(t)
|
|
8788
8801
|
}, 500);
|
|
8789
8802
|
}
|
|
8790
|
-
}),
|
|
8803
|
+
}), Ni.get("/:id/details", async (e) => {
|
|
8791
8804
|
try {
|
|
8792
8805
|
let t = u(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
8793
8806
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -8810,7 +8823,7 @@ Mi.get("/", async (e) => {
|
|
|
8810
8823
|
...JSON.parse(i.dataJson || "{}")
|
|
8811
8824
|
};
|
|
8812
8825
|
} catch {}
|
|
8813
|
-
let l =
|
|
8826
|
+
let l = Fi(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
8814
8827
|
return e.json({
|
|
8815
8828
|
id: i.id,
|
|
8816
8829
|
filename: i.filename,
|
|
@@ -8837,7 +8850,7 @@ Mi.get("/", async (e) => {
|
|
|
8837
8850
|
createdAt: t.createdAt,
|
|
8838
8851
|
parentAssetId: t.parentAssetId || i.id,
|
|
8839
8852
|
cropCoordinates: n,
|
|
8840
|
-
url:
|
|
8853
|
+
url: Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN),
|
|
8841
8854
|
originalUrl: l
|
|
8842
8855
|
};
|
|
8843
8856
|
})
|
|
@@ -8845,7 +8858,7 @@ Mi.get("/", async (e) => {
|
|
|
8845
8858
|
} catch (t) {
|
|
8846
8859
|
return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
|
|
8847
8860
|
}
|
|
8848
|
-
}),
|
|
8861
|
+
}), Ni.put("/:id", async (e) => {
|
|
8849
8862
|
try {
|
|
8850
8863
|
let t = u(e), n = e.req.param("id"), r = await e.req.json(), i = await Q(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
|
|
8851
8864
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
@@ -8853,18 +8866,18 @@ Mi.get("/", async (e) => {
|
|
|
8853
8866
|
try {
|
|
8854
8867
|
o = JSON.parse(a.dataJson || "{}");
|
|
8855
8868
|
} catch {}
|
|
8856
|
-
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
|
|
8869
|
+
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 Pi(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
8857
8870
|
r.filename === void 0 ? a.filename : r.filename,
|
|
8858
8871
|
JSON.stringify(o),
|
|
8859
8872
|
n
|
|
8860
|
-
]), await
|
|
8873
|
+
]), await Ii(e, t, n), e.json({ success: !0 });
|
|
8861
8874
|
} catch (t) {
|
|
8862
8875
|
return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
|
|
8863
8876
|
}
|
|
8864
|
-
}),
|
|
8877
|
+
}), Ni.delete("/:id", async (e) => {
|
|
8865
8878
|
try {
|
|
8866
8879
|
let t = u(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
8867
|
-
return r ? (await
|
|
8880
|
+
return r ? (await Ii(e, t, n), r.isSystemVariant ? await Pi(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Pi(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
8868
8881
|
n,
|
|
8869
8882
|
n,
|
|
8870
8883
|
`crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
@@ -8880,17 +8893,17 @@ Mi.get("/", async (e) => {
|
|
|
8880
8893
|
details: t.message || String(t)
|
|
8881
8894
|
}, 500);
|
|
8882
8895
|
}
|
|
8883
|
-
}),
|
|
8896
|
+
}), Ni.post("/restore", async (e) => {
|
|
8884
8897
|
try {
|
|
8885
8898
|
let t = u(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
8886
8899
|
if (!r) return e.json({ error: "Asset ID required" }, 400);
|
|
8887
8900
|
let i = (await Q(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
|
|
8888
|
-
return i ? (await
|
|
8901
|
+
return i ? (await Pi(t, "UPDATE assets \n SET deletedAt = NULL \n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
8889
8902
|
r,
|
|
8890
8903
|
r,
|
|
8891
8904
|
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
8892
8905
|
`%${r}%`
|
|
8893
|
-
]), await
|
|
8906
|
+
]), await Ii(e, t, r), e.json({
|
|
8894
8907
|
success: !0,
|
|
8895
8908
|
id: r,
|
|
8896
8909
|
restored: !0
|
|
@@ -8901,11 +8914,11 @@ Mi.get("/", async (e) => {
|
|
|
8901
8914
|
details: t.message
|
|
8902
8915
|
}, 500);
|
|
8903
8916
|
}
|
|
8904
|
-
}),
|
|
8917
|
+
}), Ni.delete("/purge/:id", async (e) => {
|
|
8905
8918
|
try {
|
|
8906
8919
|
let t = u(e), n = ni(e.env), r = e.req.param("id"), i = (await Q(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
8907
8920
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
8908
|
-
await
|
|
8921
|
+
await Ii(e, t, r);
|
|
8909
8922
|
let a = [i];
|
|
8910
8923
|
i.isSystemVariant || (a = [i, ...await Q(t, "SELECT id, storageKeyPrivate FROM assets \n WHERE parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
8911
8924
|
r,
|
|
@@ -8921,7 +8934,7 @@ Mi.get("/", async (e) => {
|
|
|
8921
8934
|
}
|
|
8922
8935
|
}
|
|
8923
8936
|
let s = o.map(() => "?").join(",");
|
|
8924
|
-
return await
|
|
8937
|
+
return await Pi(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await Pi(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
|
|
8925
8938
|
success: !0,
|
|
8926
8939
|
id: r,
|
|
8927
8940
|
purged: !0,
|
|
@@ -8937,8 +8950,8 @@ Mi.get("/", async (e) => {
|
|
|
8937
8950
|
});
|
|
8938
8951
|
//#endregion
|
|
8939
8952
|
//#region server/routes/public/node.ts
|
|
8940
|
-
var
|
|
8941
|
-
function
|
|
8953
|
+
var Li = new e();
|
|
8954
|
+
function Ri() {
|
|
8942
8955
|
return {
|
|
8943
8956
|
fullPath: /* @__PURE__ */ new Map(),
|
|
8944
8957
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -8946,10 +8959,10 @@ function Li() {
|
|
|
8946
8959
|
assetUrls: /* @__PURE__ */ new Map()
|
|
8947
8960
|
};
|
|
8948
8961
|
}
|
|
8949
|
-
function
|
|
8962
|
+
function zi(...e) {
|
|
8950
8963
|
return e.map((e) => String(e ?? "")).join(":");
|
|
8951
8964
|
}
|
|
8952
|
-
function
|
|
8965
|
+
function Bi(e, t) {
|
|
8953
8966
|
let n = Date.now();
|
|
8954
8967
|
if (e && String(e).trim() !== "") {
|
|
8955
8968
|
let t = Date.parse(e);
|
|
@@ -8961,7 +8974,7 @@ function zi(e, t) {
|
|
|
8961
8974
|
}
|
|
8962
8975
|
return !0;
|
|
8963
8976
|
}
|
|
8964
|
-
async function
|
|
8977
|
+
async function Vi(e, t, n) {
|
|
8965
8978
|
let r = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list");
|
|
8966
8979
|
await Promise.all(r.map(async (t) => {
|
|
8967
8980
|
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];
|
|
@@ -8982,7 +8995,7 @@ async function Bi(e, t, n) {
|
|
|
8982
8995
|
if (e.dataJson) try {
|
|
8983
8996
|
t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
8984
8997
|
} catch {}
|
|
8985
|
-
return
|
|
8998
|
+
return Bi(t.startShowingAt, t.stopShowingAt) ? {
|
|
8986
8999
|
id: e.id,
|
|
8987
9000
|
title: e.title,
|
|
8988
9001
|
slug: e.slug,
|
|
@@ -8999,7 +9012,7 @@ async function Bi(e, t, n) {
|
|
|
8999
9012
|
}
|
|
9000
9013
|
}));
|
|
9001
9014
|
}
|
|
9002
|
-
async function
|
|
9015
|
+
async function Hi(e, t, n, r, i = !1, a) {
|
|
9003
9016
|
if (!t) return { blocks: [] };
|
|
9004
9017
|
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\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 )\n SELECT *\n FROM ancestor_path\n ORDER BY level ASC\n ").all(t, t), s = Array.isArray(o) ? o : o?.results || [];
|
|
9005
9018
|
if (!s || s.length === 0) return { blocks: [] };
|
|
@@ -9055,10 +9068,10 @@ async function Vi(e, t, n, r, i = !1, a) {
|
|
|
9055
9068
|
try {
|
|
9056
9069
|
a = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
|
|
9057
9070
|
} catch {}
|
|
9058
|
-
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s =
|
|
9071
|
+
let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Bi(a.startShowingAt, a.stopShowingAt);
|
|
9059
9072
|
if (!i && (o || !s)) return null;
|
|
9060
|
-
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 || t.blockId || t.id), d =
|
|
9061
|
-
return d = await oi(e, d), d =
|
|
9073
|
+
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 || t.blockId || t.id), d = Ui(a, l);
|
|
9074
|
+
return d = await oi(e, d), d = Wi(d), d.blockId = u, {
|
|
9062
9075
|
region: t.region || n,
|
|
9063
9076
|
block: {
|
|
9064
9077
|
instanceId: t.id,
|
|
@@ -9078,7 +9091,7 @@ async function Vi(e, t, n, r, i = !1, a) {
|
|
|
9078
9091
|
}
|
|
9079
9092
|
return { blocks: [] };
|
|
9080
9093
|
}
|
|
9081
|
-
function
|
|
9094
|
+
function Ui(e, t = {}) {
|
|
9082
9095
|
let n = {};
|
|
9083
9096
|
for (let [r, i] of Object.entries(e)) {
|
|
9084
9097
|
if (r.endsWith("_meta") || r === "disabledRegions" || r === "hidden" || r === "is_hidden" || r === "isHidden" || r === "status" || r === "startShowingAt" || r === "stopShowingAt" || r === "slug" || r === "title" || r === "id" || r.startsWith("_")) continue;
|
|
@@ -9087,14 +9100,14 @@ function Hi(e, t = {}) {
|
|
|
9087
9100
|
}
|
|
9088
9101
|
return n;
|
|
9089
9102
|
}
|
|
9090
|
-
function
|
|
9091
|
-
if (Array.isArray(e)) return e.map(
|
|
9103
|
+
function Wi(e) {
|
|
9104
|
+
if (Array.isArray(e)) return e.map(Wi);
|
|
9092
9105
|
if (!e || typeof e != "object") return e;
|
|
9093
9106
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
9094
9107
|
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 ? {
|
|
9095
9108
|
...t,
|
|
9096
9109
|
...t.crops?.[r] || {}
|
|
9097
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
9110
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Wi({
|
|
9098
9111
|
...n,
|
|
9099
9112
|
title: n?.title ?? e.title ?? "",
|
|
9100
9113
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -9108,9 +9121,9 @@ function Ui(e) {
|
|
|
9108
9121
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
9109
9122
|
};
|
|
9110
9123
|
}
|
|
9111
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
9124
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Wi(t)]));
|
|
9112
9125
|
}
|
|
9113
|
-
async function
|
|
9126
|
+
async function Gi(e, t, n) {
|
|
9114
9127
|
if (typeof t == "string") {
|
|
9115
9128
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
9116
9129
|
let r = (e, t) => {
|
|
@@ -9136,9 +9149,9 @@ async function Wi(e, t, n) {
|
|
|
9136
9149
|
return await Promise.all(Array.from(t.matchAll(h)).map(async (t) => {
|
|
9137
9150
|
let i = t[1], a = r(i, "data-node-id"), o = r(i, "data-tree-id");
|
|
9138
9151
|
if (!a || !o) return;
|
|
9139
|
-
let s = await
|
|
9152
|
+
let s = await qi(e, a, o, n);
|
|
9140
9153
|
if (s?.treeNodeId) {
|
|
9141
|
-
let t = await
|
|
9154
|
+
let t = await Zi(e, String(s.treeNodeId), o, n);
|
|
9142
9155
|
m.set(`${a}:${o}`, t);
|
|
9143
9156
|
}
|
|
9144
9157
|
})), t.replace(h, (e, t) => {
|
|
@@ -9158,39 +9171,39 @@ async function Wi(e, t, n) {
|
|
|
9158
9171
|
return /href\s*=\s*["'][^"']*["']/i.test(_) ? _ = _.replace(/href\s*=\s*["'][^"']*["']/i, `href="${g || "/"}"`) : _ += ` href="${g || "/"}"`, `<a ${_}>`;
|
|
9159
9172
|
});
|
|
9160
9173
|
}
|
|
9161
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
9174
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => Gi(e, t, n)));
|
|
9162
9175
|
if (t && typeof t == "object") {
|
|
9163
9176
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
|
|
9164
9177
|
...t,
|
|
9165
|
-
href: await
|
|
9178
|
+
href: await Ki(e, t, n)
|
|
9166
9179
|
};
|
|
9167
|
-
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await
|
|
9180
|
+
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await Gi(e, r, n)]));
|
|
9168
9181
|
return Object.fromEntries(r);
|
|
9169
9182
|
}
|
|
9170
9183
|
return t;
|
|
9171
9184
|
}
|
|
9172
|
-
async function
|
|
9185
|
+
async function Ki(e, t, n) {
|
|
9173
9186
|
let r = t.href.match(/^#node:(.+)$/), i = t.href.match(/^#asset:(.+)$/);
|
|
9174
|
-
if (i) return
|
|
9187
|
+
if (i) return Yi(e, i[1], n);
|
|
9175
9188
|
if (!r) return t.href;
|
|
9176
9189
|
let a = r[1];
|
|
9177
9190
|
if (t.treeId) {
|
|
9178
|
-
let r = await
|
|
9191
|
+
let r = await qi(e, a, String(t.treeId), n);
|
|
9179
9192
|
if (r?.treeNodeId) {
|
|
9180
|
-
let i = await
|
|
9193
|
+
let i = await Zi(e, String(r.treeNodeId), String(t.treeId), n);
|
|
9181
9194
|
if (i) return i;
|
|
9182
9195
|
}
|
|
9183
9196
|
}
|
|
9184
|
-
let o = await
|
|
9197
|
+
let o = await Ji(e, a, n);
|
|
9185
9198
|
return o === void 0 ? "#" : `/${o}`;
|
|
9186
9199
|
}
|
|
9187
|
-
async function
|
|
9188
|
-
let i =
|
|
9200
|
+
async function qi(e, t, n, r) {
|
|
9201
|
+
let i = zi(t, n), a = r.treeEdges.get(i);
|
|
9189
9202
|
if (a) return a;
|
|
9190
9203
|
let o = e.prepare("\n SELECT id as treeNodeId\n FROM tree_nodes\n WHERE contentId = ?\n AND treeId = ?\n LIMIT 1\n ").get(t, n);
|
|
9191
9204
|
return r.treeEdges.set(i, Promise.resolve(o)), o;
|
|
9192
9205
|
}
|
|
9193
|
-
async function
|
|
9206
|
+
async function Ji(e, t, n) {
|
|
9194
9207
|
let r = String(t), i = n.nodeSlugs.get(r);
|
|
9195
9208
|
if (i) return i;
|
|
9196
9209
|
let a = (async () => {
|
|
@@ -9199,7 +9212,7 @@ async function qi(e, t, n) {
|
|
|
9199
9212
|
})();
|
|
9200
9213
|
return n.nodeSlugs.set(r, a), a;
|
|
9201
9214
|
}
|
|
9202
|
-
async function
|
|
9215
|
+
async function Yi(e, t, n) {
|
|
9203
9216
|
let r = String(t), i = n.assetUrls.get(r);
|
|
9204
9217
|
if (i) return i;
|
|
9205
9218
|
let a = (async () => {
|
|
@@ -9208,7 +9221,7 @@ async function Ji(e, t, n) {
|
|
|
9208
9221
|
})();
|
|
9209
9222
|
return n.assetUrls.set(r, a), a;
|
|
9210
9223
|
}
|
|
9211
|
-
function
|
|
9224
|
+
function Xi(e) {
|
|
9212
9225
|
let t = e.socialImage;
|
|
9213
9226
|
if (!t || typeof t != "object") return null;
|
|
9214
9227
|
let n = (e, t) => {
|
|
@@ -9239,9 +9252,9 @@ function Yi(e) {
|
|
|
9239
9252
|
])
|
|
9240
9253
|
};
|
|
9241
9254
|
}
|
|
9242
|
-
async function
|
|
9255
|
+
async function Zi(e, t, n, r) {
|
|
9243
9256
|
if (!t) return "";
|
|
9244
|
-
let i =
|
|
9257
|
+
let i = zi(t, n);
|
|
9245
9258
|
if (r) {
|
|
9246
9259
|
let e = r.fullPath.get(i);
|
|
9247
9260
|
if (e) return e;
|
|
@@ -9256,7 +9269,7 @@ async function Xi(e, t, n, r) {
|
|
|
9256
9269
|
})();
|
|
9257
9270
|
return r && r.fullPath.set(i, a), a;
|
|
9258
9271
|
}
|
|
9259
|
-
async function
|
|
9272
|
+
async function Qi(e, t, n, r, i) {
|
|
9260
9273
|
let a = {}, o = null;
|
|
9261
9274
|
if (t) {
|
|
9262
9275
|
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\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 )\n SELECT c.dataJson, c.draftDataJson\n FROM ancestor_path ap\n INNER JOIN content_nodes c ON ap.contentId = c.id\n ORDER BY ap.level ASC\n ").all(t, t), i = Array.isArray(n) ? n : n?.results || [], s = /* @__PURE__ */ new Set([
|
|
@@ -9294,20 +9307,20 @@ async function Zi(e, t, n, r, i) {
|
|
|
9294
9307
|
inheritedFields: a
|
|
9295
9308
|
};
|
|
9296
9309
|
}
|
|
9297
|
-
function
|
|
9310
|
+
function $i(e) {
|
|
9298
9311
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
9299
9312
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
9300
9313
|
}
|
|
9301
|
-
async function
|
|
9314
|
+
async function ea(e, t, n, r) {
|
|
9302
9315
|
try {
|
|
9303
9316
|
await e.set(t, n, r);
|
|
9304
9317
|
} catch (e) {
|
|
9305
9318
|
console.warn("[CMS Cache] Failed to write node response to cache:", e);
|
|
9306
9319
|
}
|
|
9307
9320
|
}
|
|
9308
|
-
|
|
9321
|
+
Li.get("/*", async (e) => {
|
|
9309
9322
|
try {
|
|
9310
|
-
let t = e.get("db"), n =
|
|
9323
|
+
let t = e.get("db"), n = Ri(), 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));
|
|
9311
9324
|
if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
|
|
9312
9325
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
9313
9326
|
if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
|
|
@@ -9332,7 +9345,7 @@ Ii.get("/*", async (e) => {
|
|
|
9332
9345
|
if (E.length > 0) {
|
|
9333
9346
|
let e = await Promise.all(E.map(async (e) => ({
|
|
9334
9347
|
candidate: e,
|
|
9335
|
-
calculatedPath: await
|
|
9348
|
+
calculatedPath: await Zi(t, String(e.treeNodeId), String(e.treeId), n)
|
|
9336
9349
|
}))), r = S.replace(/^\/+|\/+$/g, "");
|
|
9337
9350
|
for (let { candidate: t, calculatedPath: n } of e) {
|
|
9338
9351
|
let e = n.replace(/^\/+|\/+$/g, "");
|
|
@@ -9356,7 +9369,7 @@ Ii.get("/*", async (e) => {
|
|
|
9356
9369
|
LIMIT 1
|
|
9357
9370
|
`).get(...e);
|
|
9358
9371
|
}
|
|
9359
|
-
let D = v?.treeId || y || "main-nav", O = v?.parentId || null, k = v?.treeNodeId ? await
|
|
9372
|
+
let D = v?.treeId || y || "main-nav", O = v?.parentId || null, k = v?.treeNodeId ? await Zi(t, String(v.treeNodeId), String(D), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, A = {
|
|
9360
9373
|
id: _.id,
|
|
9361
9374
|
title: _.title,
|
|
9362
9375
|
slug: _.slug,
|
|
@@ -9374,13 +9387,13 @@ Ii.get("/*", async (e) => {
|
|
|
9374
9387
|
M = typeof N == "string" ? JSON.parse(N) : N;
|
|
9375
9388
|
} catch {}
|
|
9376
9389
|
M.disabledRegions && (ne = M.disabledRegions), ae = M.hidden === !0 || M.hidden === 1 || M.hidden === "1" || M.hidden === "true", re = M.startShowingAt || null, ie = M.stopShowingAt || null;
|
|
9377
|
-
let oe = M.layoutId, se = oe && oe !== "inherit", { resolvedLayoutId: ce, inheritedFields: le } = await
|
|
9390
|
+
let oe = M.layoutId, se = oe && oe !== "inherit", { resolvedLayoutId: ce, inheritedFields: le } = await Qi(t, O, D, s, j), P = se ? oe : ce || te.defaultLayout || null;
|
|
9378
9391
|
for (let [e, t] of Object.entries(le)) (M[e] === void 0 || M[e] === null || M[e] === "" || M[e] === "inherit") && t !== void 0 && (M[e] = t);
|
|
9379
|
-
let F = await oi(t,
|
|
9380
|
-
F =
|
|
9381
|
-
let ue =
|
|
9392
|
+
let F = await oi(t, Ui(M, j));
|
|
9393
|
+
F = Wi(F), F = await Gi(t, F, n);
|
|
9394
|
+
let ue = Xi(F);
|
|
9382
9395
|
delete F.socialImage, delete F.fbImage, delete F.xImage, delete F.whatsappImage, ue && (F.socialImages = ue), A.slug = _.slug, A.title = _.title, Object.assign(A, F), A.layoutId = P;
|
|
9383
|
-
let de = Number(_.isHidden) === 1 || ae, fe = !
|
|
9396
|
+
let de = Number(_.isHidden) === 1 || ae, fe = !Bi(re, ie);
|
|
9384
9397
|
if (!s && (de || fe)) return e.json({ error: "Node is hidden or outside its scheduled publishing window" }, 404);
|
|
9385
9398
|
let pe = [];
|
|
9386
9399
|
if (v?.treeNodeId) {
|
|
@@ -9390,7 +9403,7 @@ Ii.get("/*", async (e) => {
|
|
|
9390
9403
|
try {
|
|
9391
9404
|
t = (typeof n == "string" ? JSON.parse(n) : n) || {};
|
|
9392
9405
|
} catch {}
|
|
9393
|
-
let i = Number(e.isHidden) === 1 || t.hidden === !0 || t.hidden === 1 || t.hidden === "1", a =
|
|
9406
|
+
let i = Number(e.isHidden) === 1 || t.hidden === !0 || t.hidden === 1 || t.hidden === "1", a = Bi(t.startShowingAt, t.stopShowingAt), o = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
9394
9407
|
return !s && (i || !a) ? null : {
|
|
9395
9408
|
treeNodeId: e.treeNodeId,
|
|
9396
9409
|
id: e.id,
|
|
@@ -9410,10 +9423,10 @@ Ii.get("/*", async (e) => {
|
|
|
9410
9423
|
try {
|
|
9411
9424
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
9412
9425
|
} catch {}
|
|
9413
|
-
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o =
|
|
9426
|
+
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Bi(i.startShowingAt, i.stopShowingAt);
|
|
9414
9427
|
if (!s && (a || !o)) return null;
|
|
9415
|
-
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 || e.blockId || e.id), d =
|
|
9416
|
-
return d = await oi(t, d), d =
|
|
9428
|
+
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 || e.blockId || e.id), d = Ui(i, l);
|
|
9429
|
+
return d = await oi(t, d), d = Wi(d), d = await Gi(t, d, n), d.blockId = u, {
|
|
9417
9430
|
region: r,
|
|
9418
9431
|
block: {
|
|
9419
9432
|
instanceId: e.id,
|
|
@@ -9438,7 +9451,7 @@ Ii.get("/*", async (e) => {
|
|
|
9438
9451
|
for (let [e, r] of Object.entries(ge)) {
|
|
9439
9452
|
let i = R[e] && R[e].length > 0, a = !!ne[e];
|
|
9440
9453
|
if (R[e] || (R[e] = [], z[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && O) {
|
|
9441
|
-
let r = await
|
|
9454
|
+
let r = await Hi(t, O, e, h, s, n);
|
|
9442
9455
|
if (r.blocks.length > 0 && (R[e] = r.blocks, z[e] = {
|
|
9443
9456
|
isInherited: !0,
|
|
9444
9457
|
inheritedFromId: r.inheritedFromId,
|
|
@@ -9450,7 +9463,7 @@ Ii.get("/*", async (e) => {
|
|
|
9450
9463
|
});
|
|
9451
9464
|
}
|
|
9452
9465
|
}
|
|
9453
|
-
await Promise.all(Object.keys(R).map((e) =>
|
|
9466
|
+
await Promise.all(Object.keys(R).map((e) => Vi(t, R[e], u)));
|
|
9454
9467
|
let _e = {
|
|
9455
9468
|
channelId: u || d,
|
|
9456
9469
|
treeId: D,
|
|
@@ -9459,7 +9472,7 @@ Ii.get("/*", async (e) => {
|
|
|
9459
9472
|
content: R,
|
|
9460
9473
|
regionMeta: z
|
|
9461
9474
|
};
|
|
9462
|
-
return !s && !m && (e.header("X-Cache", "MISS"), await
|
|
9475
|
+
return !s && !m && (e.header("X-Cache", "MISS"), await ea(f, p, _e, $i(e))), e.json(_e);
|
|
9463
9476
|
} catch (t) {
|
|
9464
9477
|
console.error("[CMS Public API] Error fetching node by path:", t);
|
|
9465
9478
|
let n = e.env?.ENVIRONMENT === "development";
|
|
@@ -9471,8 +9484,8 @@ Ii.get("/*", async (e) => {
|
|
|
9471
9484
|
});
|
|
9472
9485
|
//#endregion
|
|
9473
9486
|
//#region server/routes/public/tree.ts
|
|
9474
|
-
var
|
|
9475
|
-
function
|
|
9487
|
+
var ta = new e();
|
|
9488
|
+
function na(e, t) {
|
|
9476
9489
|
let n = /* @__PURE__ */ new Date();
|
|
9477
9490
|
if (e && String(e).trim() !== "") {
|
|
9478
9491
|
let t = new Date(e);
|
|
@@ -9484,14 +9497,14 @@ function ta(e, t) {
|
|
|
9484
9497
|
}
|
|
9485
9498
|
return !0;
|
|
9486
9499
|
}
|
|
9487
|
-
async function
|
|
9500
|
+
async function ra(e, t, n, r) {
|
|
9488
9501
|
try {
|
|
9489
9502
|
await e.set(t, n, r);
|
|
9490
9503
|
} catch (e) {
|
|
9491
9504
|
console.warn("[CMS Cache] Failed to write tree response to cache:", e);
|
|
9492
9505
|
}
|
|
9493
9506
|
}
|
|
9494
|
-
|
|
9507
|
+
ta.get("/:treeParam", async (e) => {
|
|
9495
9508
|
try {
|
|
9496
9509
|
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";
|
|
9497
9510
|
if (r && r !== "default" && r !== "all") {
|
|
@@ -9545,7 +9558,7 @@ ea.get("/:treeParam", async (e) => {
|
|
|
9545
9558
|
return (p.get(n) || []).map((e) => {
|
|
9546
9559
|
let n = m.get(String(e.treeNodeId)) || {}, r = {};
|
|
9547
9560
|
for (let [e, t] of Object.entries(n)) e !== "_isTreeDraft" && e !== "_draftParentId" && e !== "isNew" && e !== "hidden" && e !== "is_hidden" && e !== "isHidden" && e !== "status" && (r[e] = t);
|
|
9548
|
-
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 =
|
|
9561
|
+
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 = na(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 = {
|
|
9549
9562
|
id: e.id,
|
|
9550
9563
|
treeNodeId: e.treeNodeId,
|
|
9551
9564
|
parentId: e.parentId || null,
|
|
@@ -9570,7 +9583,7 @@ ea.get("/:treeParam", async (e) => {
|
|
|
9570
9583
|
...d,
|
|
9571
9584
|
items: h(null)
|
|
9572
9585
|
};
|
|
9573
|
-
return !i && !s && (e.header("X-Cache", "MISS"), await
|
|
9586
|
+
return !i && !s && (e.header("X-Cache", "MISS"), await ra(a, o, g, 300)), e.json(g);
|
|
9574
9587
|
} catch (t) {
|
|
9575
9588
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
9576
9589
|
error: "Failed to fetch public tree",
|
|
@@ -9580,8 +9593,8 @@ ea.get("/:treeParam", async (e) => {
|
|
|
9580
9593
|
});
|
|
9581
9594
|
//#endregion
|
|
9582
9595
|
//#region server/routes/public/assets.ts
|
|
9583
|
-
var
|
|
9584
|
-
function
|
|
9596
|
+
var ia = new e();
|
|
9597
|
+
function aa(e, t) {
|
|
9585
9598
|
if (t === "webp") return "image/webp";
|
|
9586
9599
|
if (t === "avif") return "image/avif";
|
|
9587
9600
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -9589,7 +9602,7 @@ function ia(e, t) {
|
|
|
9589
9602
|
let n = e.toLowerCase();
|
|
9590
9603
|
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";
|
|
9591
9604
|
}
|
|
9592
|
-
|
|
9605
|
+
ia.get("/*", async (e) => {
|
|
9593
9606
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
9594
9607
|
if (!t) return e.text("Asset key missing", 400);
|
|
9595
9608
|
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 = "";
|
|
@@ -9612,7 +9625,7 @@ ra.get("/*", async (e) => {
|
|
|
9612
9625
|
c = await n.get(e);
|
|
9613
9626
|
}
|
|
9614
9627
|
if (!c) return e.text(`Asset not found: ${t}`, 404);
|
|
9615
|
-
let d = c.httpMetadata?.contentType ||
|
|
9628
|
+
let d = c.httpMetadata?.contentType || aa(t), m = d.startsWith("image/") && !d.includes("svg"), g = !1;
|
|
9616
9629
|
if (s && m && e.env?.IMAGES) {
|
|
9617
9630
|
g = !0;
|
|
9618
9631
|
try {
|
|
@@ -9675,7 +9688,7 @@ ra.get("/*", async (e) => {
|
|
|
9675
9688
|
if (!s) {
|
|
9676
9689
|
let n = _(C);
|
|
9677
9690
|
return e.body(n, 200, {
|
|
9678
|
-
"Content-Type":
|
|
9691
|
+
"Content-Type": aa(t),
|
|
9679
9692
|
"Cache-Control": "public, max-age=86400"
|
|
9680
9693
|
});
|
|
9681
9694
|
}
|
|
@@ -9683,7 +9696,7 @@ ra.get("/*", async (e) => {
|
|
|
9683
9696
|
if (g(f)) {
|
|
9684
9697
|
let n = _(f);
|
|
9685
9698
|
return e.body(n, 200, {
|
|
9686
|
-
"Content-Type":
|
|
9699
|
+
"Content-Type": aa(t, u),
|
|
9687
9700
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
9688
9701
|
"X-Local-Cache": "HIT"
|
|
9689
9702
|
});
|
|
@@ -9696,14 +9709,14 @@ ra.get("/*", async (e) => {
|
|
|
9696
9709
|
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 }));
|
|
9697
9710
|
let s = await i.toBuffer();
|
|
9698
9711
|
return v(x(f), { recursive: !0 }), y(f, s), e.body(s, 200, {
|
|
9699
|
-
"Content-Type":
|
|
9712
|
+
"Content-Type": aa(t, u),
|
|
9700
9713
|
"Cache-Control": "public, max-age=31536000, immutable",
|
|
9701
9714
|
"X-Local-Cache": "MISS"
|
|
9702
9715
|
});
|
|
9703
9716
|
} catch {
|
|
9704
9717
|
let n = _(C);
|
|
9705
9718
|
return e.body(n, 200, {
|
|
9706
|
-
"Content-Type":
|
|
9719
|
+
"Content-Type": aa(t),
|
|
9707
9720
|
"Cache-Control": "public, max-age=86400"
|
|
9708
9721
|
});
|
|
9709
9722
|
}
|
|
@@ -9714,8 +9727,8 @@ ra.get("/*", async (e) => {
|
|
|
9714
9727
|
});
|
|
9715
9728
|
//#endregion
|
|
9716
9729
|
//#region server/routes/public/paths.ts
|
|
9717
|
-
var
|
|
9718
|
-
function
|
|
9730
|
+
var oa = new e();
|
|
9731
|
+
function sa(e, t) {
|
|
9719
9732
|
let n = /* @__PURE__ */ new Date();
|
|
9720
9733
|
if (e && String(e).trim() !== "") {
|
|
9721
9734
|
let t = new Date(e);
|
|
@@ -9727,7 +9740,7 @@ function oa(e, t) {
|
|
|
9727
9740
|
}
|
|
9728
9741
|
return !0;
|
|
9729
9742
|
}
|
|
9730
|
-
|
|
9743
|
+
oa.get("/", async (e) => {
|
|
9731
9744
|
try {
|
|
9732
9745
|
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();
|
|
9733
9746
|
for (let e of n) {
|
|
@@ -9751,7 +9764,7 @@ aa.get("/", async (e) => {
|
|
|
9751
9764
|
function o(e = null, t = "") {
|
|
9752
9765
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
|
|
9753
9766
|
for (let e of s) {
|
|
9754
|
-
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s =
|
|
9767
|
+
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = sa(n.startShowingAt, n.stopShowingAt);
|
|
9755
9768
|
if (!i || !s) continue;
|
|
9756
9769
|
let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
|
|
9757
9770
|
e.nodeType !== "external-link" && r.push(l);
|
|
@@ -9768,7 +9781,7 @@ aa.get("/", async (e) => {
|
|
|
9768
9781
|
});
|
|
9769
9782
|
//#endregion
|
|
9770
9783
|
//#region server/index.ts
|
|
9771
|
-
var $ = new e(),
|
|
9784
|
+
var $ = new e(), ca = !1;
|
|
9772
9785
|
$.use("*", o()), $.use("/media/*", o({
|
|
9773
9786
|
origin: "*",
|
|
9774
9787
|
allowMethods: [
|
|
@@ -9789,13 +9802,13 @@ $.use("*", o()), $.use("/media/*", o({
|
|
|
9789
9802
|
let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
|
|
9790
9803
|
e.set("currentDomain", r);
|
|
9791
9804
|
let i = u(e);
|
|
9792
|
-
if (e.set("db", i), !
|
|
9793
|
-
await Mr(i),
|
|
9805
|
+
if (e.set("db", i), !ca) try {
|
|
9806
|
+
await Mr(i), ca = !0;
|
|
9794
9807
|
} catch (e) {
|
|
9795
9808
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
9796
9809
|
}
|
|
9797
9810
|
await t();
|
|
9798
|
-
}), $.route("/media",
|
|
9811
|
+
}), $.route("/media", ia), $.use("/media/*", Fr()), $.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", bi), $.route("/api/cms/channels", Ti), $.route("/api/cms/channels.json", Ti), $.route("/api/cms/schemas", Ei), $.route("/api/cms/schemas.json", Ei), $.route("/api/cms", ki), $.route("/api/admin/assets", Ni), $.route("/api/v1/node", Li), $.route("/api/v1/page", Li), $.route("/api/v1/tree", ta), $.route("/api/v1/all-paths", oa), $.get("*", async (e) => {
|
|
9799
9812
|
if (e.env?.ASSETS) {
|
|
9800
9813
|
let t = await e.env.ASSETS.fetch(e.req.raw);
|
|
9801
9814
|
if (t.status === 404) {
|