@brightsideoy/kama 0.1.0-alpha.88 → 0.1.0-alpha.90

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/index.js CHANGED
@@ -7403,29 +7403,31 @@ var X = class {
7403
7403
  frontendUrl;
7404
7404
  env;
7405
7405
  constructor(e) {
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(/\/+$/, "");
7406
+ this.env = e || {}, this.zoneId = this.env.CLOUDFLARE_ZONE_ID, this.apiToken = this.env.CLOUDFLARE_API_TOKEN, this.frontendUrl = (this.env.PUBLIC_FRONTEND_URL || "https://kama.t3cloud.eu").replace(/\/+$/, "");
7407
7407
  }
7408
7408
  dispatch(e, t) {
7409
+ if (!t || typeof t != "object" || typeof t.catch != "function") return;
7410
+ let n = t.catch((e) => {
7411
+ console.warn("[CacheManager Warn]:", e?.message || e);
7412
+ });
7409
7413
  try {
7410
7414
  if (e.executionCtx && typeof e.executionCtx.waitUntil == "function") {
7411
- e.executionCtx.waitUntil(t);
7415
+ e.executionCtx.waitUntil(n);
7412
7416
  return;
7413
7417
  }
7414
7418
  } catch {}
7415
- t.catch((e) => console.warn("[CacheManager Warn]:", e));
7416
7419
  }
7417
7420
  async callAstroPurge(e, t) {
7418
- let n = `${this.frontendUrl}/api/purge`, r = {
7419
- Authorization: `Bearer ${this.apiToken}`,
7420
- "Content-Type": "application/json"
7421
- }, i = e.env?.FRONTEND_WORKER || this.env.FRONTEND_WORKER;
7422
- return i && typeof i.fetch == "function" ? i.fetch(n, {
7421
+ let n = `${this.frontendUrl}/api/purge`, r = this.apiToken || e.env?.CLOUDFLARE_API_TOKEN || "", i = { "Content-Type": "application/json" };
7422
+ r && (i.Authorization = `Bearer ${r}`);
7423
+ let a = e.env?.FRONTEND_WORKER || this.env.FRONTEND_WORKER;
7424
+ return a && typeof a.fetch == "function" ? a.fetch(n, {
7423
7425
  method: "POST",
7424
- headers: r,
7426
+ headers: i,
7425
7427
  body: JSON.stringify(t)
7426
7428
  }) : fetch(n, {
7427
7429
  method: "POST",
7428
- headers: r,
7430
+ headers: i,
7429
7431
  body: JSON.stringify(t)
7430
7432
  });
7431
7433
  }
@@ -7454,15 +7456,11 @@ var X = class {
7454
7456
  }
7455
7457
  }
7456
7458
  purgeAndWarmSlug(e, t, n = []) {
7457
- let r = (async () => {
7458
- await this.purgeAndWarmSlugDirect(e, t, n);
7459
- })();
7459
+ let r = this.purgeAndWarmSlugDirect(e, t, n);
7460
7460
  this.dispatch(e, r);
7461
7461
  }
7462
7462
  purgeGlobalCache(e, t) {
7463
- let n = (async () => {
7464
- await this.purgeGlobalCacheDirect(e, t);
7465
- })();
7463
+ let n = this.purgeGlobalCacheDirect(e, t);
7466
7464
  this.dispatch(e, n);
7467
7465
  }
7468
7466
  purgeSmart(e, t, n, r, i = [], a = !1) {
@@ -7854,10 +7852,8 @@ Z.get("/", async (e) => {
7854
7852
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...r);
7855
7853
  }
7856
7854
  }
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 || [];
7859
- await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(w);
7860
- let r = /* @__PURE__ */ new Set(), i = [], a = [];
7855
+ if (g !== void 0 && Array.isArray(g) && g.length > 0 && w) {
7856
+ let e = await t.prepare("SELECT treeId, parentId, sortOrder FROM tree_nodes WHERE contentId = ?").all(w), n = Array.isArray(e) ? e : e?.results || [], r = /* @__PURE__ */ new Set(), i = [], a = [];
7861
7857
  for (let e of g) if (e && e.treeId) {
7862
7858
  let t = Number(e.treeId) || e.treeId;
7863
7859
  if (!r.has(t)) {
@@ -7868,7 +7864,7 @@ Z.get("/", async (e) => {
7868
7864
  typeof e.sortOrder == "number" ? c = e.sortOrder : o && typeof o.sortOrder == "number" && (c = o.sortOrder), i.push("(?, ?, ?, ?)"), a.push(t, w, s, c);
7869
7865
  }
7870
7866
  }
7871
- i.length > 0 && await t.prepare(`INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES ${i.join(", ")}`).run(...a);
7867
+ i.length > 0 && (await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(w), await t.prepare(`INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES ${i.join(", ")}`).run(...a));
7872
7868
  }
7873
7869
  let E = [];
7874
7870
  if (m !== void 0 && Array.isArray(m) && w) {
@@ -7936,10 +7932,8 @@ Z.get("/", async (e) => {
7936
7932
  blocks: g
7937
7933
  };
7938
7934
  await t.prepare("\n INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById)\n VALUES (?, ?, ?, ?)\n ").run(i, _, v.publishedAt, a), await J(e).clear();
7939
- let y = new X(e.env);
7940
- await y.purgeInternalWorkerCache(e, t, i, o.slug, o.language || "en");
7941
- let b = await fi(t, i);
7942
- return y.purgeSmart(e, t, i, o.slug, b, p), e.json({
7935
+ let y = await fi(t, i), b = new X(e.env);
7936
+ return b.purgeInternalWorkerCache(e, t, i, o.slug, o.language || "en"), b.purgeSmart(e, t, i, o.slug, y, p), e.json({
7943
7937
  success: !0,
7944
7938
  id: i,
7945
7939
  status: "published",
@@ -7952,7 +7946,7 @@ Z.get("/", async (e) => {
7952
7946
  let r = Number(n), i = await t.prepare("SELECT slug, language, status FROM content_nodes WHERE id = ?").get(r);
7953
7947
  await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await J(e).clear();
7954
7948
  let a = new X(e.env);
7955
- if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7949
+ if (i && a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7956
7950
  let n = await fi(t, r);
7957
7951
  i.slug && a.purgeAndWarmSlug(e, i.slug, n), a.purgeSmart(e, t, r, i.slug, n, !0);
7958
7952
  }
@@ -7967,7 +7961,7 @@ Z.get("/", async (e) => {
7967
7961
  if (!i) return e.json({ error: "Node not found" }, 404);
7968
7962
  await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await J(e).clear();
7969
7963
  let a = new X(e.env);
7970
- if (i && await a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7964
+ if (i && a.purgeInternalWorkerCache(e, t, r, i.slug, i.language || "en"), i && i.status === "published") {
7971
7965
  let n = await fi(t, r);
7972
7966
  i.slug && a.purgeAndWarmSlug(e, i.slug, n), a.purgeSmart(e, t, r, i.slug, n, !0);
7973
7967
  }
@@ -7979,7 +7973,7 @@ Z.get("/", async (e) => {
7979
7973
  let t = e.get("db"), n = e.req.query("id");
7980
7974
  if (!n) return e.json({ error: "Node ID required" }, 400);
7981
7975
  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);
7982
- 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({
7976
+ return i && 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({
7983
7977
  success: !0,
7984
7978
  purgedNodeId: r
7985
7979
  });
@@ -8011,15 +8005,6 @@ function Si(e) {
8011
8005
  function Ci(e) {
8012
8006
  return +(e === !0 || e === 1 || e === "1" || e === "true");
8013
8007
  }
8014
- function wi(e, t) {
8015
- try {
8016
- if (e.executionCtx && typeof e.executionCtx.waitUntil == "function") {
8017
- e.executionCtx.waitUntil(t);
8018
- return;
8019
- }
8020
- } catch {}
8021
- t.catch((e) => console.error("[Tree bgTask Error]:", e));
8022
- }
8023
8008
  bi.get("/tree.json", async (e) => {
8024
8009
  try {
8025
8010
  let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
@@ -8097,7 +8082,7 @@ bi.get("/tree.json", async (e) => {
8097
8082
  c.push(e.id, e.sortOrder);
8098
8083
  }), c.push(...i), c.push(o), await t.prepare(s).run(...c);
8099
8084
  }
8100
- return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
8085
+ return await i.clear(), a.purgeGlobalCache(e, t), e.json({
8101
8086
  success: !0,
8102
8087
  reorderedCount: r.length
8103
8088
  });
@@ -8129,17 +8114,21 @@ bi.get("/tree.json", async (e) => {
8129
8114
  }
8130
8115
  let u = JSON.stringify(m), d = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, ?, ?)\n ").run(l || "page", c || "Untitled", s, m.language || n.language || "en", h, u, _, _), f = Number(d.lastInsertRowid);
8131
8116
  await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, f);
8132
- let p = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, f, g), v = Number(p.lastInsertRowid), y = [];
8133
- n.channels && Array.isArray(n.channels) ? y = n.channels : n.channelId && n.channelId !== "all" && (y = [n.channelId]);
8134
- let b = [...new Set(y)].filter((e) => e && e !== "all").map((e) => Number(e));
8135
- if (b.length > 0) {
8136
- let e = b.map(() => "(?, ?)").join(", "), n = b.flatMap((e) => [f, e]);
8117
+ let p = g === null ? "parentId IS NULL" : "parentId = ?", v = g === null ? [o] : [o, g], y = (await t.prepare(`
8118
+ SELECT COALESCE(MAX(sortOrder), -1) + 1 as nextSort
8119
+ FROM tree_nodes
8120
+ WHERE treeId = ? AND ${p}
8121
+ `).get(...v))?.nextSort ?? 0, b = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(o, f, g, y), x = Number(b.lastInsertRowid), S = [];
8122
+ n.channels && Array.isArray(n.channels) ? S = n.channels : n.channelId && n.channelId !== "all" && (S = [n.channelId]);
8123
+ let C = [...new Set(S)].filter((e) => e && e !== "all").map((e) => Number(e));
8124
+ if (C.length > 0) {
8125
+ let e = C.map(() => "(?, ?)").join(", "), n = C.flatMap((e) => [f, e]);
8137
8126
  await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
8138
8127
  }
8139
- return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
8128
+ return await i.clear(), a.purgeGlobalCache(e, t), e.json({
8140
8129
  success: !0,
8141
8130
  id: f,
8142
- treeNodeId: v,
8131
+ treeNodeId: x,
8143
8132
  status: "draft"
8144
8133
  }, 201);
8145
8134
  }
@@ -8174,14 +8163,14 @@ bi.get("/tree.json", async (e) => {
8174
8163
  }
8175
8164
  await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d);
8176
8165
  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);
8177
- return await i.clear(), wi(e, a.purgeGlobalCacheDirect(e, t)), e.json({
8166
+ return await i.clear(), a.purgeGlobalCache(e, t), e.json({
8178
8167
  success: !0,
8179
8168
  treeNodeId: s
8180
8169
  });
8181
8170
  }
8182
8171
  if (s === "detach") {
8183
8172
  let r = n.treeNodeId || n.contentId;
8184
- 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);
8173
+ 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(), a.purgeGlobalCache(e, t), e.json({ success: !0 })) : e.json({ error: "treeNodeId or contentId required for detach" }, 400);
8185
8174
  }
8186
8175
  return e.json({ error: "Invalid payload or action" }, 400);
8187
8176
  } catch (t) {
@@ -8245,7 +8234,7 @@ bi.get("/tree.json", async (e) => {
8245
8234
  await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
8246
8235
  }
8247
8236
  }
8248
- return await J(e).clear(), wi(e, new X(e.env).purgeGlobalCacheDirect(e, t)), e.json({
8237
+ return await J(e).clear(), new X(e.env).purgeGlobalCache(e, t), e.json({
8249
8238
  success: !0,
8250
8239
  id: p,
8251
8240
  key: o,
@@ -8264,7 +8253,7 @@ bi.get("/tree.json", async (e) => {
8264
8253
  if (!n) return e.json({ error: "Tree ID required" }, 400);
8265
8254
  let r = Number(n);
8266
8255
  try {
8267
- 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({
8256
+ 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(), new X(e.env).purgeGlobalCache(e, t), e.json({
8268
8257
  success: !0,
8269
8258
  deletedTreeId: r
8270
8259
  });
@@ -8274,8 +8263,8 @@ bi.get("/tree.json", async (e) => {
8274
8263
  });
8275
8264
  //#endregion
8276
8265
  //#region server/routes/admin/channels.ts
8277
- var Ti = new e();
8278
- Ti.get("/", async (e) => {
8266
+ var wi = new e();
8267
+ wi.get("/", async (e) => {
8279
8268
  try {
8280
8269
  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) => {
8281
8270
  e[t.channelId] || (e[t.channelId] = []);
@@ -8341,7 +8330,7 @@ Ti.get("/", async (e) => {
8341
8330
  error: t.message
8342
8331
  }, 500);
8343
8332
  }
8344
- }), Ti.post("/", async (e) => {
8333
+ }), wi.post("/", async (e) => {
8345
8334
  try {
8346
8335
  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;
8347
8336
  if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(y, i ?? -1)) return e.json({
@@ -8368,9 +8357,7 @@ Ti.get("/", async (e) => {
8368
8357
  VALUES ${e}
8369
8358
  `).run(...n);
8370
8359
  }
8371
- await J(e).clear();
8372
- let E = new X(e.env);
8373
- return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(E.purgeGlobalCacheDirect(e, t)) : await E.purgeGlobalCacheDirect(e, t), e.json({
8360
+ return await J(e).clear(), new X(e.env).purgeGlobalCache(e, t), e.json({
8374
8361
  success: !0,
8375
8362
  id: w
8376
8363
  });
@@ -8380,14 +8367,12 @@ Ti.get("/", async (e) => {
8380
8367
  details: t.message
8381
8368
  }, 500);
8382
8369
  }
8383
- }), Ti.delete("/", async (e) => {
8370
+ }), wi.delete("/", async (e) => {
8384
8371
  let t = e.get("db"), n = e.req.query("id");
8385
8372
  if (!n) return e.json({ error: "Channel ID required" }, 400);
8386
8373
  let r = Number(n);
8387
8374
  try {
8388
- await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(r), await t.prepare("DELETE FROM node_channels WHERE channelId = ?").run(r), await t.prepare("DELETE FROM channels WHERE id = ?").run(r), await J(e).clear();
8389
- let n = new X(e.env);
8390
- return e.executionCtx && typeof e.executionCtx.waitUntil == "function" ? e.executionCtx.waitUntil(n.purgeGlobalCacheDirect(e, t)) : await n.purgeGlobalCacheDirect(e, t), e.json({
8375
+ return await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(r), await t.prepare("DELETE FROM node_channels WHERE channelId = ?").run(r), await t.prepare("DELETE FROM channels WHERE id = ?").run(r), await J(e).clear(), new X(e.env).purgeGlobalCache(e, t), e.json({
8391
8376
  success: !0,
8392
8377
  deletedSiteId: r
8393
8378
  });
@@ -8400,9 +8385,9 @@ Ti.get("/", async (e) => {
8400
8385
  });
8401
8386
  //#endregion
8402
8387
  //#region server/routes/admin/schemas.ts
8403
- var Ei = new e(), Di = null, Oi = (e) => {
8388
+ var Ti = new e(), Ei = null, Di = (e) => {
8404
8389
  try {
8405
- if (!Di) {
8390
+ if (!Ei) {
8406
8391
  let t = ci(e.env?.BUNDLED_DEFINITIONS || Or), n = t.userTemplate || {
8407
8392
  id: "userTemplate",
8408
8393
  label: "User Account",
@@ -8439,7 +8424,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8439
8424
  }
8440
8425
  }
8441
8426
  };
8442
- Di = {
8427
+ Ei = {
8443
8428
  channelTemplate: t.channelTemplate || null,
8444
8429
  treeTemplate: t.treeTemplate || null,
8445
8430
  userTemplate: n,
@@ -8451,7 +8436,7 @@ var Ei = new e(), Di = null, Oi = (e) => {
8451
8436
  blockLayouts: t.blockLayouts || {}
8452
8437
  };
8453
8438
  }
8454
- return e.json(Di, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8439
+ return e.json(Ei, 200, { "Cache-Control": "public, max-age=300, stale-while-revalidate=86400" });
8455
8440
  } catch (t) {
8456
8441
  return console.error("[CMS API] Error loading schemas:", t), e.json({
8457
8442
  error: "Failed to load schemas",
@@ -8459,10 +8444,10 @@ var Ei = new e(), Di = null, Oi = (e) => {
8459
8444
  }, 500);
8460
8445
  }
8461
8446
  };
8462
- Ei.get("/", Oi), Ei.get("/schemas.json", Oi);
8447
+ Ti.get("/", Di), Ti.get("/schemas.json", Di);
8463
8448
  //#endregion
8464
8449
  //#region server/routes/admin/validation.ts
8465
- var ki = new e(), Ai = {
8450
+ var Oi = new e(), ki = {
8466
8451
  node: "content_nodes",
8467
8452
  nodes: "content_nodes",
8468
8453
  content_node: "content_nodes",
@@ -8474,7 +8459,7 @@ var ki = new e(), Ai = {
8474
8459
  user: "users",
8475
8460
  users: "users",
8476
8461
  user_account: "user_accounts"
8477
- }, ji = {
8462
+ }, Ai = {
8478
8463
  content_nodes: [
8479
8464
  "id",
8480
8465
  "title",
@@ -8531,11 +8516,11 @@ var ki = new e(), Ai = {
8531
8516
  "createdAt"
8532
8517
  ]
8533
8518
  };
8534
- ki.post("/validate-unique", async (e) => {
8519
+ Oi.post("/validate-unique", async (e) => {
8535
8520
  try {
8536
8521
  let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
8537
8522
  if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
8538
- let o = Ai[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (ji[o] || ji.content_nodes).includes(s), l = -1;
8523
+ let o = ki[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (Ai[o] || Ai.content_nodes).includes(s), l = -1;
8539
8524
  if (a != null && String(a).trim() !== "") {
8540
8525
  let e = Number(a);
8541
8526
  l = isNaN(e) ? String(a) : e;
@@ -8547,7 +8532,7 @@ ki.post("/validate-unique", async (e) => {
8547
8532
  } catch (t) {
8548
8533
  return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
8549
8534
  }
8550
- }), ki.post("/validate-unique-sibling", async (e) => {
8535
+ }), Oi.post("/validate-unique-sibling", async (e) => {
8551
8536
  try {
8552
8537
  let t = e.get("db"), { slug: n, treeId: r, parentId: i, excludeTreeNodeId: a } = await e.req.json();
8553
8538
  if (!n || !String(n).trim() || !r) return e.json({ isUnique: !0 });
@@ -8574,8 +8559,8 @@ ki.post("/validate-unique", async (e) => {
8574
8559
  });
8575
8560
  //#endregion
8576
8561
  //#region server/routes/admin/stats.ts
8577
- var Mi = new e();
8578
- Mi.get("/", async (e) => {
8562
+ var ji = new e();
8563
+ ji.get("/", async (e) => {
8579
8564
  try {
8580
8565
  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) => ({
8581
8566
  ...e,
@@ -8618,7 +8603,7 @@ Mi.get("/", async (e) => {
8618
8603
  });
8619
8604
  //#endregion
8620
8605
  //#region server/routes/admin/assets.ts
8621
- var Ni = new e();
8606
+ var Mi = new e();
8622
8607
  async function Q(e, t, n = []) {
8623
8608
  let r = e.prepare(t);
8624
8609
  if (typeof r.bind == "function") {
@@ -8631,20 +8616,20 @@ async function Q(e, t, n = []) {
8631
8616
  }
8632
8617
  return [];
8633
8618
  }
8634
- async function Pi(e, t, n = []) {
8619
+ async function Ni(e, t, n = []) {
8635
8620
  let r = e.prepare(t);
8636
8621
  if (typeof r.bind == "function") return await r.bind(...n).run();
8637
8622
  if (typeof r.run == "function") return await r.run(...n);
8638
8623
  }
8639
- function Fi(e, t, n) {
8624
+ function Pi(e, t, n) {
8640
8625
  let r = e || (t ? `/media/${t}` : "");
8641
8626
  return r && n && r.startsWith(`https://${n}/`) && !r.includes("/media/") && (r = r.replace(`https://${n}/`, `https://${n}/media/`)), r;
8642
8627
  }
8643
- async function Ii(e, t, n) {
8628
+ async function Fi(e, t, n) {
8644
8629
  try {
8645
8630
  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 = [];
8646
8631
  for (let t of i) {
8647
- let n = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8632
+ let n = Pi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8648
8633
  n && a.push(n);
8649
8634
  }
8650
8635
  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 ", [
@@ -8658,7 +8643,7 @@ async function Ii(e, t, n) {
8658
8643
  console.warn("[Assets Router] Failed to purge edge cache for asset nodes:", e);
8659
8644
  }
8660
8645
  }
8661
- Ni.get("/", async (e) => {
8646
+ Mi.get("/", async (e) => {
8662
8647
  try {
8663
8648
  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 = {
8664
8649
  createdAt: "a.createdAt",
@@ -8725,7 +8710,7 @@ Ni.get("/", async (e) => {
8725
8710
  ...JSON.parse(t.dataJson || "{}")
8726
8711
  };
8727
8712
  } catch {}
8728
- let r = Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8713
+ let r = Pi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
8729
8714
  return {
8730
8715
  id: t.id,
8731
8716
  filename: t.filename || "Untitled Asset",
@@ -8749,7 +8734,7 @@ Ni.get("/", async (e) => {
8749
8734
  details: t.message || String(t)
8750
8735
  }, 500);
8751
8736
  }
8752
- }), Ni.post("/upload", async (e) => {
8737
+ }), Mi.post("/upload", async (e) => {
8753
8738
  try {
8754
8739
  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;
8755
8740
  s && (await Q(t, "SELECT id FROM assets WHERE id = ?", [s])).length === 0 && (s = null);
@@ -8768,7 +8753,7 @@ Ni.get("/", async (e) => {
8768
8753
  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;
8769
8754
  T && (await Q(t, "SELECT id FROM users WHERE id = ?", [T])).length === 0 && (T = null);
8770
8755
  let E = +!!h;
8771
- await Pi(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
8756
+ await Ni(t, "\n INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ", [
8772
8757
  p,
8773
8758
  i.name,
8774
8759
  S,
@@ -8783,7 +8768,7 @@ Ni.get("/", async (e) => {
8783
8768
  let D = x;
8784
8769
  if (s) {
8785
8770
  let n = await Q(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [s]);
8786
- n.length > 0 && (D = Fi(n[0].cdnUrl, n[0].storageKeyPrivate, y)), await Ii(e, t, s);
8771
+ n.length > 0 && (D = Pi(n[0].cdnUrl, n[0].storageKeyPrivate, y)), await Fi(e, t, s);
8787
8772
  }
8788
8773
  return e.json({
8789
8774
  id: p,
@@ -8802,7 +8787,7 @@ Ni.get("/", async (e) => {
8802
8787
  details: t.message || String(t)
8803
8788
  }, 500);
8804
8789
  }
8805
- }), Ni.get("/:id/details", async (e) => {
8790
+ }), Mi.get("/:id/details", async (e) => {
8806
8791
  try {
8807
8792
  let t = u(e), n = e.req.param("id"), r = await Q(t, "SELECT * FROM assets WHERE id = ?", [n]);
8808
8793
  if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8825,7 +8810,7 @@ Ni.get("/", async (e) => {
8825
8810
  ...JSON.parse(i.dataJson || "{}")
8826
8811
  };
8827
8812
  } catch {}
8828
- let l = Fi(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN);
8813
+ let l = Pi(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN);
8829
8814
  return e.json({
8830
8815
  id: i.id,
8831
8816
  filename: i.filename,
@@ -8852,7 +8837,7 @@ Ni.get("/", async (e) => {
8852
8837
  createdAt: t.createdAt,
8853
8838
  parentAssetId: t.parentAssetId || i.id,
8854
8839
  cropCoordinates: n,
8855
- url: Fi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN),
8840
+ url: Pi(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN),
8856
8841
  originalUrl: l
8857
8842
  };
8858
8843
  })
@@ -8860,7 +8845,7 @@ Ni.get("/", async (e) => {
8860
8845
  } catch (t) {
8861
8846
  return console.error("❌ [Asset Details Error]:", t), e.json({ error: "Failed to load details" }, 500);
8862
8847
  }
8863
- }), Ni.put("/:id", async (e) => {
8848
+ }), Mi.put("/:id", async (e) => {
8864
8849
  try {
8865
8850
  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]);
8866
8851
  if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
@@ -8868,18 +8853,18 @@ Ni.get("/", async (e) => {
8868
8853
  try {
8869
8854
  o = JSON.parse(a.dataJson || "{}");
8870
8855
  } catch {}
8871
- 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 = ?", [
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 Ni(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
8872
8857
  r.filename === void 0 ? a.filename : r.filename,
8873
8858
  JSON.stringify(o),
8874
8859
  n
8875
- ]), await Ii(e, t, n), e.json({ success: !0 });
8860
+ ]), await Fi(e, t, n), e.json({ success: !0 });
8876
8861
  } catch (t) {
8877
8862
  return console.error("❌ [Asset Update Error]:", t), e.json({ error: "Failed to update asset" }, 500);
8878
8863
  }
8879
- }), Ni.delete("/:id", async (e) => {
8864
+ }), Mi.delete("/:id", async (e) => {
8880
8865
  try {
8881
8866
  let t = u(e), n = e.req.param("id"), r = (await Q(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
8882
- 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 ?))", [
8867
+ return r ? (await Fi(e, t, n), r.isSystemVariant ? await Ni(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Ni(t, "UPDATE assets\n SET deletedAt = CURRENT_TIMESTAMP\n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
8883
8868
  n,
8884
8869
  n,
8885
8870
  `crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
@@ -8895,17 +8880,17 @@ Ni.get("/", async (e) => {
8895
8880
  details: t.message || String(t)
8896
8881
  }, 500);
8897
8882
  }
8898
- }), Ni.post("/restore", async (e) => {
8883
+ }), Mi.post("/restore", async (e) => {
8899
8884
  try {
8900
8885
  let t = u(e), n = await e.req.json(), r = n.id || n.assetId;
8901
8886
  if (!r) return e.json({ error: "Asset ID required" }, 400);
8902
8887
  let i = (await Q(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
8903
- 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 ?))", [
8888
+ return i ? (await Ni(t, "UPDATE assets \n SET deletedAt = NULL \n WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
8904
8889
  r,
8905
8890
  r,
8906
8891
  `crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
8907
8892
  `%${r}%`
8908
- ]), await Ii(e, t, r), e.json({
8893
+ ]), await Fi(e, t, r), e.json({
8909
8894
  success: !0,
8910
8895
  id: r,
8911
8896
  restored: !0
@@ -8916,11 +8901,11 @@ Ni.get("/", async (e) => {
8916
8901
  details: t.message
8917
8902
  }, 500);
8918
8903
  }
8919
- }), Ni.delete("/purge/:id", async (e) => {
8904
+ }), Mi.delete("/purge/:id", async (e) => {
8920
8905
  try {
8921
8906
  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];
8922
8907
  if (!i) return e.json({ error: "Asset not found" }, 404);
8923
- await Ii(e, t, r);
8908
+ await Fi(e, t, r);
8924
8909
  let a = [i];
8925
8910
  i.isSystemVariant || (a = [i, ...await Q(t, "SELECT id, storageKeyPrivate FROM assets \n WHERE parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
8926
8911
  r,
@@ -8936,7 +8921,7 @@ Ni.get("/", async (e) => {
8936
8921
  }
8937
8922
  }
8938
8923
  let s = o.map(() => "?").join(",");
8939
- 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({
8924
+ return await Ni(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await Ni(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
8940
8925
  success: !0,
8941
8926
  id: r,
8942
8927
  purged: !0,
@@ -8952,8 +8937,8 @@ Ni.get("/", async (e) => {
8952
8937
  });
8953
8938
  //#endregion
8954
8939
  //#region server/routes/public/node.ts
8955
- var Li = new e();
8956
- function Ri() {
8940
+ var Ii = new e();
8941
+ function Li() {
8957
8942
  return {
8958
8943
  fullPath: /* @__PURE__ */ new Map(),
8959
8944
  treeEdges: /* @__PURE__ */ new Map(),
@@ -8961,10 +8946,10 @@ function Ri() {
8961
8946
  assetUrls: /* @__PURE__ */ new Map()
8962
8947
  };
8963
8948
  }
8964
- function zi(...e) {
8949
+ function Ri(...e) {
8965
8950
  return e.map((e) => String(e ?? "")).join(":");
8966
8951
  }
8967
- function Bi(e, t) {
8952
+ function zi(e, t) {
8968
8953
  let n = Date.now();
8969
8954
  if (e && String(e).trim() !== "") {
8970
8955
  let t = Date.parse(e);
@@ -8976,7 +8961,7 @@ function Bi(e, t) {
8976
8961
  }
8977
8962
  return !0;
8978
8963
  }
8979
- async function Vi(e, t, n) {
8964
+ async function Bi(e, t, n) {
8980
8965
  let r = t.filter((e) => e.componentId === "content-feed" || e.componentId === "article-list");
8981
8966
  await Promise.all(r.map(async (t) => {
8982
8967
  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];
@@ -8997,7 +8982,7 @@ async function Vi(e, t, n) {
8997
8982
  if (e.dataJson) try {
8998
8983
  t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
8999
8984
  } catch {}
9000
- return Bi(t.startShowingAt, t.stopShowingAt) ? {
8985
+ return zi(t.startShowingAt, t.stopShowingAt) ? {
9001
8986
  id: e.id,
9002
8987
  title: e.title,
9003
8988
  slug: e.slug,
@@ -9014,7 +8999,7 @@ async function Vi(e, t, n) {
9014
8999
  }
9015
9000
  }));
9016
9001
  }
9017
- async function Hi(e, t, n, r, i = !1, a) {
9002
+ async function Vi(e, t, n, r, i = !1, a) {
9018
9003
  if (!t) return { blocks: [] };
9019
9004
  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 || [];
9020
9005
  if (!s || s.length === 0) return { blocks: [] };
@@ -9070,10 +9055,10 @@ async function Hi(e, t, n, r, i = !1, a) {
9070
9055
  try {
9071
9056
  a = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
9072
9057
  } catch {}
9073
- let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = Bi(a.startShowingAt, a.stopShowingAt);
9058
+ let o = a.hidden === !0 || a.hidden === 1 || a.hidden === "1" || a.hidden === "true", s = zi(a.startShowingAt, a.stopShowingAt);
9074
9059
  if (!i && (o || !s)) return null;
9075
- 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);
9076
- return d = await oi(e, d), d = Wi(d), d.blockId = u, {
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 = Hi(a, l);
9061
+ return d = await oi(e, d), d = Ui(d), d.blockId = u, {
9077
9062
  region: t.region || n,
9078
9063
  block: {
9079
9064
  instanceId: t.id,
@@ -9093,7 +9078,7 @@ async function Hi(e, t, n, r, i = !1, a) {
9093
9078
  }
9094
9079
  return { blocks: [] };
9095
9080
  }
9096
- function Ui(e, t = {}) {
9081
+ function Hi(e, t = {}) {
9097
9082
  let n = {};
9098
9083
  for (let [r, i] of Object.entries(e)) {
9099
9084
  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;
@@ -9102,14 +9087,14 @@ function Ui(e, t = {}) {
9102
9087
  }
9103
9088
  return n;
9104
9089
  }
9105
- function Wi(e) {
9106
- if (Array.isArray(e)) return e.map(Wi);
9090
+ function Ui(e) {
9091
+ if (Array.isArray(e)) return e.map(Ui);
9107
9092
  if (!e || typeof e != "object") return e;
9108
9093
  if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
9109
9094
  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 ? {
9110
9095
  ...t,
9111
9096
  ...t.crops?.[r] || {}
9112
- } : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Wi({
9097
+ } : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, Ui({
9113
9098
  ...n,
9114
9099
  title: n?.title ?? e.title ?? "",
9115
9100
  alt: n?.alt ?? e.alt ?? "",
@@ -9123,9 +9108,9 @@ function Wi(e) {
9123
9108
  ...Object.keys(a).length > 0 ? { variants: a } : {}
9124
9109
  };
9125
9110
  }
9126
- return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Wi(t)]));
9111
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Ui(t)]));
9127
9112
  }
9128
- async function Gi(e, t, n) {
9113
+ async function Wi(e, t, n) {
9129
9114
  if (typeof t == "string") {
9130
9115
  if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
9131
9116
  let r = (e, t) => {
@@ -9151,9 +9136,9 @@ async function Gi(e, t, n) {
9151
9136
  return await Promise.all(Array.from(t.matchAll(h)).map(async (t) => {
9152
9137
  let i = t[1], a = r(i, "data-node-id"), o = r(i, "data-tree-id");
9153
9138
  if (!a || !o) return;
9154
- let s = await qi(e, a, o, n);
9139
+ let s = await Ki(e, a, o, n);
9155
9140
  if (s?.treeNodeId) {
9156
- let t = await Zi(e, String(s.treeNodeId), o, n);
9141
+ let t = await Xi(e, String(s.treeNodeId), o, n);
9157
9142
  m.set(`${a}:${o}`, t);
9158
9143
  }
9159
9144
  })), t.replace(h, (e, t) => {
@@ -9173,39 +9158,39 @@ async function Gi(e, t, n) {
9173
9158
  return /href\s*=\s*["'][^"']*["']/i.test(_) ? _ = _.replace(/href\s*=\s*["'][^"']*["']/i, `href="${g || "/"}"`) : _ += ` href="${g || "/"}"`, `<a ${_}>`;
9174
9159
  });
9175
9160
  }
9176
- if (Array.isArray(t)) return Promise.all(t.map((t) => Gi(e, t, n)));
9161
+ if (Array.isArray(t)) return Promise.all(t.map((t) => Wi(e, t, n)));
9177
9162
  if (t && typeof t == "object") {
9178
9163
  if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
9179
9164
  ...t,
9180
- href: await Ki(e, t, n)
9165
+ href: await Gi(e, t, n)
9181
9166
  };
9182
- let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await Gi(e, r, n)]));
9167
+ let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await Wi(e, r, n)]));
9183
9168
  return Object.fromEntries(r);
9184
9169
  }
9185
9170
  return t;
9186
9171
  }
9187
- async function Ki(e, t, n) {
9172
+ async function Gi(e, t, n) {
9188
9173
  let r = t.href.match(/^#node:(.+)$/), i = t.href.match(/^#asset:(.+)$/);
9189
- if (i) return Yi(e, i[1], n);
9174
+ if (i) return Ji(e, i[1], n);
9190
9175
  if (!r) return t.href;
9191
9176
  let a = r[1];
9192
9177
  if (t.treeId) {
9193
- let r = await qi(e, a, String(t.treeId), n);
9178
+ let r = await Ki(e, a, String(t.treeId), n);
9194
9179
  if (r?.treeNodeId) {
9195
- let i = await Zi(e, String(r.treeNodeId), String(t.treeId), n);
9180
+ let i = await Xi(e, String(r.treeNodeId), String(t.treeId), n);
9196
9181
  if (i) return i;
9197
9182
  }
9198
9183
  }
9199
- let o = await Ji(e, a, n);
9184
+ let o = await qi(e, a, n);
9200
9185
  return o === void 0 ? "#" : `/${o}`;
9201
9186
  }
9202
- async function qi(e, t, n, r) {
9203
- let i = zi(t, n), a = r.treeEdges.get(i);
9187
+ async function Ki(e, t, n, r) {
9188
+ let i = Ri(t, n), a = r.treeEdges.get(i);
9204
9189
  if (a) return a;
9205
9190
  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);
9206
9191
  return r.treeEdges.set(i, Promise.resolve(o)), o;
9207
9192
  }
9208
- async function Ji(e, t, n) {
9193
+ async function qi(e, t, n) {
9209
9194
  let r = String(t), i = n.nodeSlugs.get(r);
9210
9195
  if (i) return i;
9211
9196
  let a = (async () => {
@@ -9214,7 +9199,7 @@ async function Ji(e, t, n) {
9214
9199
  })();
9215
9200
  return n.nodeSlugs.set(r, a), a;
9216
9201
  }
9217
- async function Yi(e, t, n) {
9202
+ async function Ji(e, t, n) {
9218
9203
  let r = String(t), i = n.assetUrls.get(r);
9219
9204
  if (i) return i;
9220
9205
  let a = (async () => {
@@ -9223,7 +9208,7 @@ async function Yi(e, t, n) {
9223
9208
  })();
9224
9209
  return n.assetUrls.set(r, a), a;
9225
9210
  }
9226
- function Xi(e) {
9211
+ function Yi(e) {
9227
9212
  let t = e.socialImage;
9228
9213
  if (!t || typeof t != "object") return null;
9229
9214
  let n = (e, t) => {
@@ -9254,9 +9239,9 @@ function Xi(e) {
9254
9239
  ])
9255
9240
  };
9256
9241
  }
9257
- async function Zi(e, t, n, r) {
9242
+ async function Xi(e, t, n, r) {
9258
9243
  if (!t) return "";
9259
- let i = zi(t, n);
9244
+ let i = Ri(t, n);
9260
9245
  if (r) {
9261
9246
  let e = r.fullPath.get(i);
9262
9247
  if (e) return e;
@@ -9271,7 +9256,7 @@ async function Zi(e, t, n, r) {
9271
9256
  })();
9272
9257
  return r && r.fullPath.set(i, a), a;
9273
9258
  }
9274
- async function Qi(e, t, n, r, i) {
9259
+ async function Zi(e, t, n, r, i) {
9275
9260
  let a = {}, o = null;
9276
9261
  if (t) {
9277
9262
  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([
@@ -9309,20 +9294,20 @@ async function Qi(e, t, n, r, i) {
9309
9294
  inheritedFields: a
9310
9295
  };
9311
9296
  }
9312
- function $i(e) {
9297
+ function Qi(e) {
9313
9298
  let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
9314
9299
  return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
9315
9300
  }
9316
- async function ea(e, t, n, r) {
9301
+ async function $i(e, t, n, r) {
9317
9302
  try {
9318
9303
  await e.set(t, n, r);
9319
9304
  } catch (e) {
9320
9305
  console.warn("[CMS Cache] Failed to write node response to cache:", e);
9321
9306
  }
9322
9307
  }
9323
- Li.get("/*", async (e) => {
9308
+ Ii.get("/*", async (e) => {
9324
9309
  try {
9325
- 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));
9310
+ let t = e.get("db"), n = Li(), 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));
9326
9311
  if (!c) return e.json({ error: `Channel '${a}' not found` }, 404);
9327
9312
  let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
9328
9313
  if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
@@ -9347,7 +9332,7 @@ Li.get("/*", async (e) => {
9347
9332
  if (E.length > 0) {
9348
9333
  let e = await Promise.all(E.map(async (e) => ({
9349
9334
  candidate: e,
9350
- calculatedPath: await Zi(t, String(e.treeNodeId), String(e.treeId), n)
9335
+ calculatedPath: await Xi(t, String(e.treeNodeId), String(e.treeId), n)
9351
9336
  }))), r = S.replace(/^\/+|\/+$/g, "");
9352
9337
  for (let { candidate: t, calculatedPath: n } of e) {
9353
9338
  let e = n.replace(/^\/+|\/+$/g, "");
@@ -9371,7 +9356,7 @@ Li.get("/*", async (e) => {
9371
9356
  LIMIT 1
9372
9357
  `).get(...e);
9373
9358
  }
9374
- 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 = {
9359
+ let D = v?.treeId || y || "main-nav", O = v?.parentId || null, k = v?.treeNodeId ? await Xi(t, String(v.treeNodeId), String(D), n) : `/${(_.slug || "").replace(/^\/+|\/+$/g, "")}`, A = {
9375
9360
  id: _.id,
9376
9361
  title: _.title,
9377
9362
  slug: _.slug,
@@ -9389,13 +9374,13 @@ Li.get("/*", async (e) => {
9389
9374
  M = typeof N == "string" ? JSON.parse(N) : N;
9390
9375
  } catch {}
9391
9376
  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;
9392
- 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;
9377
+ let oe = M.layoutId, se = oe && oe !== "inherit", { resolvedLayoutId: ce, inheritedFields: le } = await Zi(t, O, D, s, j), P = se ? oe : ce || te.defaultLayout || null;
9393
9378
  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);
9394
- let F = await oi(t, Ui(M, j));
9395
- F = Wi(F), F = await Gi(t, F, n);
9396
- let ue = Xi(F);
9379
+ let F = await oi(t, Hi(M, j));
9380
+ F = Ui(F), F = await Wi(t, F, n);
9381
+ let ue = Yi(F);
9397
9382
  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;
9398
- let de = Number(_.isHidden) === 1 || ae, fe = !Bi(re, ie);
9383
+ let de = Number(_.isHidden) === 1 || ae, fe = !zi(re, ie);
9399
9384
  if (!s && (de || fe)) return e.json({ error: "Node is hidden or outside its scheduled publishing window" }, 404);
9400
9385
  let pe = [];
9401
9386
  if (v?.treeNodeId) {
@@ -9405,7 +9390,7 @@ Li.get("/*", async (e) => {
9405
9390
  try {
9406
9391
  t = (typeof n == "string" ? JSON.parse(n) : n) || {};
9407
9392
  } catch {}
9408
- 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, "");
9393
+ let i = Number(e.isHidden) === 1 || t.hidden === !0 || t.hidden === 1 || t.hidden === "1", a = zi(t.startShowingAt, t.stopShowingAt), o = (e.slug || "").replace(/^\/+|\/+$/g, "");
9409
9394
  return !s && (i || !a) ? null : {
9410
9395
  treeNodeId: e.treeNodeId,
9411
9396
  id: e.id,
@@ -9425,10 +9410,10 @@ Li.get("/*", async (e) => {
9425
9410
  try {
9426
9411
  i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
9427
9412
  } catch {}
9428
- let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = Bi(i.startShowingAt, i.stopShowingAt);
9413
+ let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = zi(i.startShowingAt, i.stopShowingAt);
9429
9414
  if (!s && (a || !o)) return null;
9430
- 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);
9431
- return d = await oi(t, d), d = Wi(d), d = await Gi(t, d, n), d.blockId = u, {
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 = Hi(i, l);
9416
+ return d = await oi(t, d), d = Ui(d), d = await Wi(t, d, n), d.blockId = u, {
9432
9417
  region: r,
9433
9418
  block: {
9434
9419
  instanceId: e.id,
@@ -9453,7 +9438,7 @@ Li.get("/*", async (e) => {
9453
9438
  for (let [e, r] of Object.entries(ge)) {
9454
9439
  let i = R[e] && R[e].length > 0, a = !!ne[e];
9455
9440
  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) {
9456
- let r = await Hi(t, O, e, h, s, n);
9441
+ let r = await Vi(t, O, e, h, s, n);
9457
9442
  if (r.blocks.length > 0 && (R[e] = r.blocks, z[e] = {
9458
9443
  isInherited: !0,
9459
9444
  inheritedFromId: r.inheritedFromId,
@@ -9465,7 +9450,7 @@ Li.get("/*", async (e) => {
9465
9450
  });
9466
9451
  }
9467
9452
  }
9468
- await Promise.all(Object.keys(R).map((e) => Vi(t, R[e], u)));
9453
+ await Promise.all(Object.keys(R).map((e) => Bi(t, R[e], u)));
9469
9454
  let _e = {
9470
9455
  channelId: u || d,
9471
9456
  treeId: D,
@@ -9474,7 +9459,7 @@ Li.get("/*", async (e) => {
9474
9459
  content: R,
9475
9460
  regionMeta: z
9476
9461
  };
9477
- return !s && !m && (e.header("X-Cache", "MISS"), await ea(f, p, _e, $i(e))), e.json(_e);
9462
+ return !s && !m && (e.header("X-Cache", "MISS"), await $i(f, p, _e, Qi(e))), e.json(_e);
9478
9463
  } catch (t) {
9479
9464
  console.error("[CMS Public API] Error fetching node by path:", t);
9480
9465
  let n = e.env?.ENVIRONMENT === "development";
@@ -9486,8 +9471,8 @@ Li.get("/*", async (e) => {
9486
9471
  });
9487
9472
  //#endregion
9488
9473
  //#region server/routes/public/tree.ts
9489
- var ta = new e();
9490
- function na(e, t) {
9474
+ var ea = new e();
9475
+ function ta(e, t) {
9491
9476
  let n = /* @__PURE__ */ new Date();
9492
9477
  if (e && String(e).trim() !== "") {
9493
9478
  let t = new Date(e);
@@ -9499,14 +9484,14 @@ function na(e, t) {
9499
9484
  }
9500
9485
  return !0;
9501
9486
  }
9502
- async function ra(e, t, n, r) {
9487
+ async function na(e, t, n, r) {
9503
9488
  try {
9504
9489
  await e.set(t, n, r);
9505
9490
  } catch (e) {
9506
9491
  console.warn("[CMS Cache] Failed to write tree response to cache:", e);
9507
9492
  }
9508
9493
  }
9509
- ta.get("/:treeParam", async (e) => {
9494
+ ea.get("/:treeParam", async (e) => {
9510
9495
  try {
9511
9496
  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";
9512
9497
  if (r && r !== "default" && r !== "all") {
@@ -9560,7 +9545,7 @@ ta.get("/:treeParam", async (e) => {
9560
9545
  return (p.get(n) || []).map((e) => {
9561
9546
  let n = m.get(String(e.treeNodeId)) || {}, r = {};
9562
9547
  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);
9563
- 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 = {
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 = ta(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 = {
9564
9549
  id: e.id,
9565
9550
  treeNodeId: e.treeNodeId,
9566
9551
  parentId: e.parentId || null,
@@ -9585,7 +9570,7 @@ ta.get("/:treeParam", async (e) => {
9585
9570
  ...d,
9586
9571
  items: h(null)
9587
9572
  };
9588
- return !i && !s && (e.header("X-Cache", "MISS"), await ra(a, o, g, 300)), e.json(g);
9573
+ return !i && !s && (e.header("X-Cache", "MISS"), await na(a, o, g, 300)), e.json(g);
9589
9574
  } catch (t) {
9590
9575
  return console.error("[CMS Public Tree API] Error:", t), e.json({
9591
9576
  error: "Failed to fetch public tree",
@@ -9595,8 +9580,8 @@ ta.get("/:treeParam", async (e) => {
9595
9580
  });
9596
9581
  //#endregion
9597
9582
  //#region server/routes/public/assets.ts
9598
- var ia = new e();
9599
- function aa(e, t) {
9583
+ var ra = new e();
9584
+ function ia(e, t) {
9600
9585
  if (t === "webp") return "image/webp";
9601
9586
  if (t === "avif") return "image/avif";
9602
9587
  if (t === "jpeg" || t === "jpg") return "image/jpeg";
@@ -9604,7 +9589,7 @@ function aa(e, t) {
9604
9589
  let n = e.toLowerCase();
9605
9590
  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";
9606
9591
  }
9607
- ia.get("/*", async (e) => {
9592
+ ra.get("/*", async (e) => {
9608
9593
  let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
9609
9594
  if (!t) return e.text("Asset key missing", 400);
9610
9595
  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 = "";
@@ -9627,7 +9612,7 @@ ia.get("/*", async (e) => {
9627
9612
  c = await n.get(e);
9628
9613
  }
9629
9614
  if (!c) return e.text(`Asset not found: ${t}`, 404);
9630
- let d = c.httpMetadata?.contentType || aa(t), m = d.startsWith("image/") && !d.includes("svg"), g = !1;
9615
+ let d = c.httpMetadata?.contentType || ia(t), m = d.startsWith("image/") && !d.includes("svg"), g = !1;
9631
9616
  if (s && m && e.env?.IMAGES) {
9632
9617
  g = !0;
9633
9618
  try {
@@ -9690,7 +9675,7 @@ ia.get("/*", async (e) => {
9690
9675
  if (!s) {
9691
9676
  let n = _(C);
9692
9677
  return e.body(n, 200, {
9693
- "Content-Type": aa(t),
9678
+ "Content-Type": ia(t),
9694
9679
  "Cache-Control": "public, max-age=86400"
9695
9680
  });
9696
9681
  }
@@ -9698,7 +9683,7 @@ ia.get("/*", async (e) => {
9698
9683
  if (g(f)) {
9699
9684
  let n = _(f);
9700
9685
  return e.body(n, 200, {
9701
- "Content-Type": aa(t, u),
9686
+ "Content-Type": ia(t, u),
9702
9687
  "Cache-Control": "public, max-age=31536000, immutable",
9703
9688
  "X-Local-Cache": "HIT"
9704
9689
  });
@@ -9711,14 +9696,14 @@ ia.get("/*", async (e) => {
9711
9696
  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 }));
9712
9697
  let s = await i.toBuffer();
9713
9698
  return v(x(f), { recursive: !0 }), y(f, s), e.body(s, 200, {
9714
- "Content-Type": aa(t, u),
9699
+ "Content-Type": ia(t, u),
9715
9700
  "Cache-Control": "public, max-age=31536000, immutable",
9716
9701
  "X-Local-Cache": "MISS"
9717
9702
  });
9718
9703
  } catch {
9719
9704
  let n = _(C);
9720
9705
  return e.body(n, 200, {
9721
- "Content-Type": aa(t),
9706
+ "Content-Type": ia(t),
9722
9707
  "Cache-Control": "public, max-age=86400"
9723
9708
  });
9724
9709
  }
@@ -9729,8 +9714,8 @@ ia.get("/*", async (e) => {
9729
9714
  });
9730
9715
  //#endregion
9731
9716
  //#region server/routes/public/paths.ts
9732
- var oa = new e();
9733
- function sa(e, t) {
9717
+ var aa = new e();
9718
+ function oa(e, t) {
9734
9719
  let n = /* @__PURE__ */ new Date();
9735
9720
  if (e && String(e).trim() !== "") {
9736
9721
  let t = new Date(e);
@@ -9742,7 +9727,7 @@ function sa(e, t) {
9742
9727
  }
9743
9728
  return !0;
9744
9729
  }
9745
- oa.get("/", async (e) => {
9730
+ aa.get("/", async (e) => {
9746
9731
  try {
9747
9732
  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();
9748
9733
  for (let e of n) {
@@ -9766,7 +9751,7 @@ oa.get("/", async (e) => {
9766
9751
  function o(e = null, t = "") {
9767
9752
  let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
9768
9753
  for (let e of s) {
9769
- let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = sa(n.startShowingAt, n.stopShowingAt);
9754
+ let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = oa(n.startShowingAt, n.stopShowingAt);
9770
9755
  if (!i || !s) continue;
9771
9756
  let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
9772
9757
  e.nodeType !== "external-link" && r.push(l);
@@ -9783,7 +9768,7 @@ oa.get("/", async (e) => {
9783
9768
  });
9784
9769
  //#endregion
9785
9770
  //#region server/index.ts
9786
- var $ = new e(), ca = !1;
9771
+ var $ = new e(), sa = !1;
9787
9772
  $.use("*", o()), $.use("/media/*", o({
9788
9773
  origin: "*",
9789
9774
  allowMethods: [
@@ -9804,13 +9789,13 @@ $.use("*", o()), $.use("/media/*", o({
9804
9789
  let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
9805
9790
  e.set("currentDomain", r);
9806
9791
  let i = u(e);
9807
- if (e.set("db", i), !ca) try {
9808
- await Mr(i), ca = !0;
9792
+ if (e.set("db", i), !sa) try {
9793
+ await Mr(i), sa = !0;
9809
9794
  } catch (e) {
9810
9795
  console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
9811
9796
  }
9812
9797
  await t();
9813
- }), $.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) => {
9798
+ }), $.route("/media", ra), $.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", ji), $.route("/api/cms/stats.json", ji), $.route("/api/cms", bi), $.route("/api/cms/channels", wi), $.route("/api/cms/channels.json", wi), $.route("/api/cms/schemas", Ti), $.route("/api/cms/schemas.json", Ti), $.route("/api/cms", Oi), $.route("/api/admin/assets", Mi), $.route("/api/v1/node", Ii), $.route("/api/v1/page", Ii), $.route("/api/v1/tree", ea), $.route("/api/v1/all-paths", aa), $.get("*", async (e) => {
9814
9799
  if (e.env?.ASSETS) {
9815
9800
  let t = await e.env.ASSETS.fetch(e.req.raw);
9816
9801
  if (t.status === 404) {