@brightsideoy/kama 0.1.0-alpha.170 → 0.1.0-alpha.172
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-DAoG05nh.css +1 -0
- package/dist/assets/index-iWK1NrI-.js +164 -0
- package/dist/{dist-DkBY_SfG.js → dist-CZH1oldV.js} +223 -205
- package/dist/index.html +2 -2
- package/dist/index.js +223 -205
- package/dist/schema-compiler.js +1 -1
- package/package.json +1 -1
- package/templates/astro-starter/src/components/global/Footer.astro +63 -24
- package/templates/astro-starter/src/components/global/NavigationMenu.astro +134 -50
- package/templates/astro-starter/src/pages/[...slug].astro +1 -6
- package/dist/assets/index-CDo1UNaK.js +0 -164
- package/dist/assets/index-D5W5U152.css +0 -1
package/dist/index.js
CHANGED
|
@@ -5558,7 +5558,7 @@ var b = { hasSubscribers: !1 }, x = b, S = b, C = typeof performance == "object"
|
|
|
5558
5558
|
async clear() {
|
|
5559
5559
|
this.cache.clear();
|
|
5560
5560
|
}
|
|
5561
|
-
},
|
|
5561
|
+
}, te = class {
|
|
5562
5562
|
kv;
|
|
5563
5563
|
constructor(e) {
|
|
5564
5564
|
this.kv = e;
|
|
@@ -5575,21 +5575,21 @@ var b = { hasSubscribers: !1 }, x = b, S = b, C = typeof performance == "object"
|
|
|
5575
5575
|
this.kv && await this.kv.delete(e);
|
|
5576
5576
|
}
|
|
5577
5577
|
async clear() {}
|
|
5578
|
-
},
|
|
5578
|
+
}, ne = class {
|
|
5579
5579
|
async get() {
|
|
5580
5580
|
return null;
|
|
5581
5581
|
}
|
|
5582
5582
|
async set() {}
|
|
5583
5583
|
async delete() {}
|
|
5584
5584
|
async clear() {}
|
|
5585
|
-
},
|
|
5586
|
-
function
|
|
5585
|
+
}, P = null;
|
|
5586
|
+
function F(e) {
|
|
5587
5587
|
let t = process.env.CACHE_DRIVER || "lru";
|
|
5588
|
-
return t === "none" || t === "off" || t === "false" ? new
|
|
5588
|
+
return t === "none" || t === "off" || t === "false" ? new ne() : e?.env?.CMS_CACHE_KV ? new te(e.env.CMS_CACHE_KV) : t === "lru" ? (P ||= new ee(), P) : new ne();
|
|
5589
5589
|
}
|
|
5590
5590
|
//#endregion
|
|
5591
5591
|
//#region server/storage/local.ts
|
|
5592
|
-
var
|
|
5592
|
+
var re = class {
|
|
5593
5593
|
customStoragePath;
|
|
5594
5594
|
constructor(e) {
|
|
5595
5595
|
this.customStoragePath = e;
|
|
@@ -5658,7 +5658,7 @@ var L = class {
|
|
|
5658
5658
|
if (e.code !== "ENOENT") throw e;
|
|
5659
5659
|
}
|
|
5660
5660
|
}
|
|
5661
|
-
},
|
|
5661
|
+
}, ie = class {
|
|
5662
5662
|
async process(e, t, n) {
|
|
5663
5663
|
let r = await import(
|
|
5664
5664
|
/* @vite-ignore */
|
|
@@ -5685,7 +5685,7 @@ var L = class {
|
|
|
5685
5685
|
return console.warn("⚠️ [SharpImageOptimizer] Processing failed, returning raw buffer."), e;
|
|
5686
5686
|
}
|
|
5687
5687
|
}
|
|
5688
|
-
},
|
|
5688
|
+
}, ae = class {
|
|
5689
5689
|
bucket;
|
|
5690
5690
|
publicDomain;
|
|
5691
5691
|
constructor(e, t) {
|
|
@@ -5730,7 +5730,7 @@ var L = class {
|
|
|
5730
5730
|
async delete(e) {
|
|
5731
5731
|
await this.bucket.delete(e);
|
|
5732
5732
|
}
|
|
5733
|
-
},
|
|
5733
|
+
}, oe = class {
|
|
5734
5734
|
async process(e, t, n) {
|
|
5735
5735
|
let { env: r, key: i, req: a } = n;
|
|
5736
5736
|
if (r.IMAGES) try {
|
|
@@ -5767,18 +5767,18 @@ var L = class {
|
|
|
5767
5767
|
};
|
|
5768
5768
|
//#endregion
|
|
5769
5769
|
//#region server/storage/factory.ts
|
|
5770
|
-
function
|
|
5770
|
+
function I(e) {
|
|
5771
5771
|
return e.KAMA_RUNTIME === "cloudflare" || e.MEDIA_BUCKET ? {
|
|
5772
|
-
storage: new
|
|
5773
|
-
optimizer: new
|
|
5772
|
+
storage: new ae(e.MEDIA_BUCKET, e.CDN_DOMAIN || ""),
|
|
5773
|
+
optimizer: new oe()
|
|
5774
5774
|
} : {
|
|
5775
|
-
storage: new
|
|
5776
|
-
optimizer: new
|
|
5775
|
+
storage: new re(e.LOCAL_MEDIA_PATH),
|
|
5776
|
+
optimizer: new ie()
|
|
5777
5777
|
};
|
|
5778
5778
|
}
|
|
5779
5779
|
//#endregion
|
|
5780
5780
|
//#region server/utils/node-assets-interceptor.ts
|
|
5781
|
-
function
|
|
5781
|
+
function se(e) {
|
|
5782
5782
|
if (!e || typeof e != "object") return {
|
|
5783
5783
|
cleanedData: e,
|
|
5784
5784
|
assetRefs: []
|
|
@@ -5837,7 +5837,7 @@ function R(e) {
|
|
|
5837
5837
|
assetRefs: t
|
|
5838
5838
|
};
|
|
5839
5839
|
}
|
|
5840
|
-
async function
|
|
5840
|
+
async function ce(e, t, n) {
|
|
5841
5841
|
if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
5842
5842
|
let r = /* @__PURE__ */ new Set();
|
|
5843
5843
|
for (let i of n) {
|
|
@@ -5847,23 +5847,23 @@ async function oe(e, t, n) {
|
|
|
5847
5847
|
}
|
|
5848
5848
|
//#endregion
|
|
5849
5849
|
//#region server/utils/asset-hydrator.ts
|
|
5850
|
-
function
|
|
5850
|
+
function L(e) {
|
|
5851
5851
|
if (!e) return null;
|
|
5852
5852
|
if (typeof e == "string" && e.startsWith("ast_")) return e;
|
|
5853
5853
|
if (typeof e == "object" && e) {
|
|
5854
5854
|
if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
|
|
5855
|
-
if (typeof e.id == "object") return
|
|
5855
|
+
if (typeof e.id == "object") return L(e.id);
|
|
5856
5856
|
}
|
|
5857
5857
|
return null;
|
|
5858
5858
|
}
|
|
5859
|
-
async function
|
|
5859
|
+
async function R(e, t) {
|
|
5860
5860
|
if (!t || typeof t != "object") return t;
|
|
5861
5861
|
let n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
5862
5862
|
if (!e) return;
|
|
5863
|
-
let t =
|
|
5863
|
+
let t = L(e);
|
|
5864
5864
|
if (t) {
|
|
5865
5865
|
if (n.add(t), typeof e == "object" && e.parentAssetId) {
|
|
5866
|
-
let t =
|
|
5866
|
+
let t = L(e.parentAssetId);
|
|
5867
5867
|
t && n.add(t);
|
|
5868
5868
|
}
|
|
5869
5869
|
typeof e == "object" && e.variants && Object.values(e.variants).forEach(r);
|
|
@@ -5895,7 +5895,7 @@ async function B(e, t) {
|
|
|
5895
5895
|
AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
|
|
5896
5896
|
`).all(...Array.from(n), ...Array.from(n).map((e) => `%${e}%`)), c = Array.isArray(s) ? s : s?.results || [], l = /* @__PURE__ */ new Map();
|
|
5897
5897
|
for (let e of c) {
|
|
5898
|
-
let t =
|
|
5898
|
+
let t = L(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
|
|
5899
5899
|
if (!t) continue;
|
|
5900
5900
|
let r = e.filename.match(/^crop_([a-z0-9]+)_/i), i = r ? r[1] : "standard", a = null;
|
|
5901
5901
|
if (e.cropCoordinatesJson) try {
|
|
@@ -5933,7 +5933,7 @@ async function B(e, t) {
|
|
|
5933
5933
|
id: e.id,
|
|
5934
5934
|
url: r,
|
|
5935
5935
|
originalUrl: i,
|
|
5936
|
-
parentAssetId:
|
|
5936
|
+
parentAssetId: L(e.parentAssetId) || null,
|
|
5937
5937
|
cropCoordinates: a,
|
|
5938
5938
|
variants: o && Object.keys(o).length > 0 ? o : void 0,
|
|
5939
5939
|
filename: e.filename,
|
|
@@ -5945,7 +5945,7 @@ async function B(e, t) {
|
|
|
5945
5945
|
}
|
|
5946
5946
|
let d = (e) => {
|
|
5947
5947
|
if (!e) return e;
|
|
5948
|
-
let t =
|
|
5948
|
+
let t = L(e);
|
|
5949
5949
|
if (t) {
|
|
5950
5950
|
let n = u.get(t), r = typeof e == "object" && e.variants ? e.variants : void 0, i = typeof e == "object" && e.cropCoordinates ? e.cropCoordinates : void 0, a = typeof e == "object" && e.metadataOverrides ? e.metadataOverrides : void 0, o = n?.url || (typeof e == "object" && e.url && !e.url.startsWith("blob:") ? e.url : ""), s = n?.originalUrl || (typeof e == "object" && e.originalUrl && !e.originalUrl.startsWith("blob:") ? e.originalUrl : o), c;
|
|
5951
5951
|
if (r || n?.variants) {
|
|
@@ -5956,7 +5956,7 @@ async function B(e, t) {
|
|
|
5956
5956
|
return {
|
|
5957
5957
|
...n || {},
|
|
5958
5958
|
id: t,
|
|
5959
|
-
parentAssetId: n?.parentAssetId ?
|
|
5959
|
+
parentAssetId: n?.parentAssetId ? L(n.parentAssetId) : null,
|
|
5960
5960
|
url: o,
|
|
5961
5961
|
originalUrl: s,
|
|
5962
5962
|
cropCoordinates: i || n?.cropCoordinates || null,
|
|
@@ -5976,7 +5976,7 @@ async function B(e, t) {
|
|
|
5976
5976
|
}
|
|
5977
5977
|
//#endregion
|
|
5978
5978
|
//#region src/utils/schema-loader.ts
|
|
5979
|
-
function
|
|
5979
|
+
function le(e) {
|
|
5980
5980
|
return e ? {
|
|
5981
5981
|
nodes: e.nodes || {},
|
|
5982
5982
|
trees: e.trees || {},
|
|
@@ -5995,7 +5995,7 @@ function se(e) {
|
|
|
5995
5995
|
}
|
|
5996
5996
|
//#endregion
|
|
5997
5997
|
//#region server/services/cache-manager.ts
|
|
5998
|
-
var
|
|
5998
|
+
var z = class {
|
|
5999
5999
|
env;
|
|
6000
6000
|
constructor(e) {
|
|
6001
6001
|
this.env = e || {};
|
|
@@ -6060,7 +6060,7 @@ var V = class {
|
|
|
6060
6060
|
}
|
|
6061
6061
|
async purgeInternalWorkerCache(e, t, n, r, i) {
|
|
6062
6062
|
try {
|
|
6063
|
-
let a =
|
|
6063
|
+
let a = F(e);
|
|
6064
6064
|
if (n) {
|
|
6065
6065
|
let e = t.prepare("SELECT treeId FROM tree_nodes WHERE contentId = ?"), r = typeof e.all == "function" ? await e.all(n) : await e.bind(n).all(), i = Array.isArray(r) ? r : r?.results || [];
|
|
6066
6066
|
for (let e of i) await a.delete(`tree:default:${e.treeId}`), await a.delete(`tree:all:${e.treeId}`);
|
|
@@ -6203,8 +6203,8 @@ var V = class {
|
|
|
6203
6203
|
console.warn("⚠️ [CacheWarmer] Tree-wide warming failed:", e);
|
|
6204
6204
|
}
|
|
6205
6205
|
}
|
|
6206
|
-
},
|
|
6207
|
-
async function
|
|
6206
|
+
}, B = new e();
|
|
6207
|
+
async function ue(e, t, n = []) {
|
|
6208
6208
|
let r = e.prepare(t);
|
|
6209
6209
|
if (typeof r.bind == "function") {
|
|
6210
6210
|
let e = await r.bind(...n).all();
|
|
@@ -6216,23 +6216,23 @@ async function ce(e, t, n = []) {
|
|
|
6216
6216
|
}
|
|
6217
6217
|
return [];
|
|
6218
6218
|
}
|
|
6219
|
-
async function
|
|
6219
|
+
async function de(e, t, n = []) {
|
|
6220
6220
|
let r = e.prepare(t);
|
|
6221
6221
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
6222
6222
|
if (typeof r.run == "function") return r.run(...n);
|
|
6223
6223
|
}
|
|
6224
|
-
function
|
|
6224
|
+
function fe(e) {
|
|
6225
6225
|
return !e || !e.trim() ? null : e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
6226
6226
|
}
|
|
6227
|
-
function
|
|
6227
|
+
function V(e) {
|
|
6228
6228
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6229
6229
|
}
|
|
6230
|
-
function
|
|
6230
|
+
function H(e) {
|
|
6231
6231
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6232
6232
|
let t = Number(e);
|
|
6233
6233
|
return isNaN(t) ? null : t;
|
|
6234
6234
|
}
|
|
6235
|
-
function
|
|
6235
|
+
function pe(e) {
|
|
6236
6236
|
let t = { ...e };
|
|
6237
6237
|
delete t.language, delete t.defaultLanguage;
|
|
6238
6238
|
for (let e of [
|
|
@@ -6261,22 +6261,22 @@ function fe(e) {
|
|
|
6261
6261
|
]) delete t[e];
|
|
6262
6262
|
return t;
|
|
6263
6263
|
}
|
|
6264
|
-
function
|
|
6265
|
-
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) =>
|
|
6264
|
+
function me(e, t = /* @__PURE__ */ new Set()) {
|
|
6265
|
+
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) => me(e, t)), t) : (typeof e == "object" && Object.values(e).forEach((e) => me(e, t)), t) : t;
|
|
6266
6266
|
}
|
|
6267
|
-
function
|
|
6267
|
+
function he(e, t) {
|
|
6268
6268
|
if (!e) return !0;
|
|
6269
|
-
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 &&
|
|
6269
|
+
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 && V(t.isHidden) !== V(e.isHidden), a = t.status !== void 0 && t.status !== e.status, o = typeof e.draftDataJson == "string" ? JSON.parse(e.draftDataJson || "{}") : e.draftDataJson || {}, s = t.sanitizedFields || {}, c = s.menuTitle !== void 0 && s.menuTitle !== o.menuTitle;
|
|
6270
6270
|
return n || r || i || a || c;
|
|
6271
6271
|
}
|
|
6272
|
-
async function
|
|
6272
|
+
async function ge(e, t, n) {
|
|
6273
6273
|
for (let r of n) {
|
|
6274
|
-
let n = (await
|
|
6275
|
-
if (!n || (await
|
|
6274
|
+
let n = (await ue(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
|
|
6275
|
+
if (!n || (await ue(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0) continue;
|
|
6276
6276
|
let i = [n];
|
|
6277
6277
|
if (!n.isSystemVariant) {
|
|
6278
|
-
let t = await
|
|
6279
|
-
if (r.length > 0 && (await
|
|
6278
|
+
let t = await ue(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets\n WHERE parentAssetId = ? OR (isSystemVariant = 1 AND filename LIKE ?)\n ", [n.id, `crop_%${String(n.filename || "").replace(/\.[^/.]+$/, "")}%`]), r = t.map((e) => e.id);
|
|
6279
|
+
if (r.length > 0 && (await ue(e, `SELECT DISTINCT assetId FROM node_assets WHERE assetId IN (${r.map(() => "?").join(",")})`, r)).length > 0) continue;
|
|
6280
6280
|
i = [n, ...t];
|
|
6281
6281
|
}
|
|
6282
6282
|
for (let e of i) if (e.storageKeyPrivate) try {
|
|
@@ -6285,10 +6285,10 @@ async function he(e, t, n) {
|
|
|
6285
6285
|
console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
|
|
6286
6286
|
}
|
|
6287
6287
|
let a = i.map((e) => e.id), o = a.map(() => "?").join(",");
|
|
6288
|
-
await
|
|
6288
|
+
await de(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await de(e, `DELETE FROM assets WHERE id IN (${o})`, a);
|
|
6289
6289
|
}
|
|
6290
6290
|
}
|
|
6291
|
-
async function
|
|
6291
|
+
async function _e(e, t, n) {
|
|
6292
6292
|
let r = {}, i = null;
|
|
6293
6293
|
if (t) {
|
|
6294
6294
|
let a = await e.prepare("\n WITH RECURSIVE ancestor_path(id, parentId, draftDataJson, dataJson, level) AS (\n SELECT t.contentId as id, t.parentId, c.draftDataJson, c.dataJson, 0\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId as id, t.parentId, c.draftDataJson, c.dataJson, ap.level + 1\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT draftDataJson, dataJson FROM ancestor_path ORDER BY level ASC\n ").all(t, n, n), o = Array.isArray(a) ? a : a?.results || [];
|
|
@@ -6313,7 +6313,7 @@ async function ge(e, t, n) {
|
|
|
6313
6313
|
inheritedFields: r
|
|
6314
6314
|
};
|
|
6315
6315
|
}
|
|
6316
|
-
|
|
6316
|
+
B.get("/", async (e) => {
|
|
6317
6317
|
let t = e.get("db"), n = e.req.query("id"), r = e.req.query("type"), i = e.req.query("q") || e.req.query("search"), a = e.req.query("channelId"), o = e.req.query("trashed") === "true", s = e.req.query("assetId"), c = e.req.query("sort") || "updatedAt", l = (e.req.query("order") || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC", u = e.req.query("limit"), d = e.req.query("offset"), f = Math.max(1, Math.min(100, parseInt(u || "50", 10))), p = Math.max(0, parseInt(d || "0", 10));
|
|
6318
6318
|
if (n) {
|
|
6319
6319
|
let r = Number(n);
|
|
@@ -6338,9 +6338,9 @@ H.get("/", async (e) => {
|
|
|
6338
6338
|
updatedAt: i.updatedAt
|
|
6339
6339
|
}, s = i.draftDataJson || i.dataJson;
|
|
6340
6340
|
if (s) try {
|
|
6341
|
-
let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), c =
|
|
6341
|
+
let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), c = le(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
|
|
6342
6342
|
if (a) {
|
|
6343
|
-
let { resolvedLayoutId: e, inheritedFields: r } = await
|
|
6343
|
+
let { resolvedLayoutId: e, inheritedFields: r } = await _e(t, a.parentId, a.treeId);
|
|
6344
6344
|
(l === "inherit" || !l) && (l = e);
|
|
6345
6345
|
for (let [e, t] of Object.entries(r)) e !== "layoutId" && e !== "subpageLayoutId" && (n[e] === void 0 || n[e] === null || n[e] === "") && t !== void 0 && (n[e] = t);
|
|
6346
6346
|
}
|
|
@@ -6355,7 +6355,7 @@ H.get("/", async (e) => {
|
|
|
6355
6355
|
let r = t.allowedLayouts;
|
|
6356
6356
|
return r ? typeof r == "string" ? r === e : !Array.isArray(r) || r.length === 0 || r.includes(e) : !0;
|
|
6357
6357
|
})(l) && (l = null), (l === "inherit" || !l) && (l = c.defaultLayout || null);
|
|
6358
|
-
let u = await
|
|
6358
|
+
let u = await R(t, pe(n));
|
|
6359
6359
|
Object.assign(o, u), o.resolvedLayoutId = l;
|
|
6360
6360
|
} catch {}
|
|
6361
6361
|
let c = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
|
|
@@ -6365,7 +6365,7 @@ H.get("/", async (e) => {
|
|
|
6365
6365
|
let u = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(r), d = Array.isArray(u) ? u : u?.results || [], f = await Promise.all(d.map(async (e) => {
|
|
6366
6366
|
let n = {};
|
|
6367
6367
|
try {
|
|
6368
|
-
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await
|
|
6368
|
+
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await R(t, n));
|
|
6369
6369
|
} catch {
|
|
6370
6370
|
n = {};
|
|
6371
6371
|
}
|
|
@@ -6453,7 +6453,7 @@ H.get("/", async (e) => {
|
|
|
6453
6453
|
assetCount: e.assetCount || 0
|
|
6454
6454
|
}, i = e.draftDataJson || e.dataJson;
|
|
6455
6455
|
if (i) try {
|
|
6456
|
-
let e = typeof i == "string" ? JSON.parse(i) : i, n = await
|
|
6456
|
+
let e = typeof i == "string" ? JSON.parse(i) : i, n = await R(t, pe(e));
|
|
6457
6457
|
Object.assign(r, n);
|
|
6458
6458
|
} catch {}
|
|
6459
6459
|
return r;
|
|
@@ -6465,8 +6465,8 @@ H.get("/", async (e) => {
|
|
|
6465
6465
|
offset: p,
|
|
6466
6466
|
limit: f
|
|
6467
6467
|
});
|
|
6468
|
-
}),
|
|
6469
|
-
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, ..._ } = r, { cleanedData: v, assetRefs: y } =
|
|
6468
|
+
}), B.post("/", async (e) => {
|
|
6469
|
+
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, ..._ } = r, { cleanedData: v, assetRefs: y } = se(pe(_)), b = V(d === void 0 ? f === void 0 ? p : f : d), x = l || u || "page", S = e.get("user")?.id || null, C = typeof c == "string" && c.trim() !== "" ? c.trim() : null, w = g && Array.isArray(g) && g.length > 0 ? g[0] : null, T = w ? w.treeId || w.id : null, E = null;
|
|
6470
6470
|
if (T) {
|
|
6471
6471
|
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(T) || -1, String(T));
|
|
6472
6472
|
if (e?.dataJson) try {
|
|
@@ -6488,12 +6488,12 @@ H.get("/", async (e) => {
|
|
|
6488
6488
|
}
|
|
6489
6489
|
}
|
|
6490
6490
|
C && E && C === E && (C = null);
|
|
6491
|
-
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null :
|
|
6491
|
+
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null : fe(s);
|
|
6492
6492
|
if (M) {
|
|
6493
6493
|
let n = [];
|
|
6494
6494
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
6495
6495
|
treeId: Number(e.treeId),
|
|
6496
|
-
parentId:
|
|
6496
|
+
parentId: H(e.parentId ?? e._draftParentId ?? null)
|
|
6497
6497
|
});
|
|
6498
6498
|
else if (a) {
|
|
6499
6499
|
let e = await t.prepare("SELECT treeId, parentId FROM tree_nodes WHERE contentId = ?").all(a), r = Array.isArray(e) ? e : e?.results || [];
|
|
@@ -6520,7 +6520,7 @@ H.get("/", async (e) => {
|
|
|
6520
6520
|
}
|
|
6521
6521
|
if (a) {
|
|
6522
6522
|
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
6523
|
-
k =
|
|
6523
|
+
k = he(e, {
|
|
6524
6524
|
title: o,
|
|
6525
6525
|
slug: M,
|
|
6526
6526
|
isHidden: b,
|
|
@@ -6528,7 +6528,7 @@ H.get("/", async (e) => {
|
|
|
6528
6528
|
});
|
|
6529
6529
|
let n = e?.draftDataJson || e?.dataJson || "{}";
|
|
6530
6530
|
try {
|
|
6531
|
-
|
|
6531
|
+
me(typeof n == "string" ? JSON.parse(n) : n, O);
|
|
6532
6532
|
} catch {}
|
|
6533
6533
|
let r = {};
|
|
6534
6534
|
try {
|
|
@@ -6579,7 +6579,7 @@ H.get("/", async (e) => {
|
|
|
6579
6579
|
}
|
|
6580
6580
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
6581
6581
|
if (!e || !e.treeId) continue;
|
|
6582
|
-
let n = Number(e.treeId) || e.treeId, r =
|
|
6582
|
+
let n = Number(e.treeId) || e.treeId, r = H(e.parentId ?? e._draftParentId ?? null), i = typeof e.sortOrder == "number" ? e.sortOrder : 0, a = await t.prepare("SELECT contentId, parentId, sortOrder FROM tree_nodes WHERE treeId = ? AND contentId = ?").get(n, D);
|
|
6583
6583
|
a ? ((a.parentId !== r || a.sortOrder !== i) && (k = !0), await t.prepare("UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE treeId = ? AND contentId = ?").run(r, i, n, D)) : (k = !0, await t.prepare("INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES (?, ?, ?, ?)").run(n, D, r, i));
|
|
6584
6584
|
}
|
|
6585
6585
|
let N = [];
|
|
@@ -6587,7 +6587,7 @@ H.get("/", async (e) => {
|
|
|
6587
6587
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
6588
6588
|
let e = [], n = [];
|
|
6589
6589
|
for (let t = 0; t < m.length; t++) {
|
|
6590
|
-
let r = m[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c } =
|
|
6590
|
+
let r = m[t], i = r.componentId || r.elementType || "text-block", a = r.data || {}, o = String(r.blockId || a.blockId || r.instanceId || r.id || `block-${Date.now()}`), { cleanedData: s, assetRefs: c } = se({
|
|
6591
6591
|
...a,
|
|
6592
6592
|
blockId: o,
|
|
6593
6593
|
_instanceId: o
|
|
@@ -6603,21 +6603,21 @@ H.get("/", async (e) => {
|
|
|
6603
6603
|
}
|
|
6604
6604
|
if (D) {
|
|
6605
6605
|
let n = [...y, ...N];
|
|
6606
|
-
await
|
|
6606
|
+
await ce(t, D, n);
|
|
6607
6607
|
let r = new Set(n.map((e) => e.assetId)), i = new Set([...O].filter((e) => !r.has(e)));
|
|
6608
6608
|
if (i.size > 0) {
|
|
6609
|
-
let { storage: n } =
|
|
6610
|
-
await
|
|
6609
|
+
let { storage: n } = I(e.env);
|
|
6610
|
+
await ge(t, n, i);
|
|
6611
6611
|
}
|
|
6612
6612
|
}
|
|
6613
|
-
return await
|
|
6613
|
+
return await F(e).clear(), e.json({
|
|
6614
6614
|
success: !0,
|
|
6615
6615
|
id: D,
|
|
6616
6616
|
status: A,
|
|
6617
6617
|
hasUnpublishedChanges: j === 1 || A === "draft",
|
|
6618
6618
|
isStructuralChange: k
|
|
6619
6619
|
});
|
|
6620
|
-
}),
|
|
6620
|
+
}), B.post("/publish", async (e) => {
|
|
6621
6621
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
6622
6622
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
6623
6623
|
let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
|
|
@@ -6650,7 +6650,7 @@ H.get("/", async (e) => {
|
|
|
6650
6650
|
},
|
|
6651
6651
|
blocks: v
|
|
6652
6652
|
};
|
|
6653
|
-
return await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, y, JSON.stringify(b), a), await
|
|
6653
|
+
return await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, y, JSON.stringify(b), a), await F(e).clear(), new z(e.env).purgeNode(e, t, i, h), e.json({
|
|
6654
6654
|
success: !0,
|
|
6655
6655
|
id: i,
|
|
6656
6656
|
status: "published",
|
|
@@ -6659,29 +6659,29 @@ H.get("/", async (e) => {
|
|
|
6659
6659
|
hasUnpublishedChanges: !1,
|
|
6660
6660
|
isStructuralChange: h
|
|
6661
6661
|
});
|
|
6662
|
-
}),
|
|
6662
|
+
}), B.delete("/", async (e) => {
|
|
6663
6663
|
let t = e.get("db"), n = e.req.query("id");
|
|
6664
6664
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
6665
6665
|
let r = Number(n);
|
|
6666
|
-
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await
|
|
6666
|
+
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await F(e).clear(), new z(e.env).purgeNode(e, t, r, !0), e.json({
|
|
6667
6667
|
success: !0,
|
|
6668
6668
|
deletedNodeId: r
|
|
6669
6669
|
});
|
|
6670
|
-
}),
|
|
6670
|
+
}), B.post("/restore", async (e) => {
|
|
6671
6671
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
6672
|
-
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await
|
|
6672
|
+
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await F(e).clear(), new z(e.env).purgeNode(e, t, r, !0), e.json({
|
|
6673
6673
|
success: !0,
|
|
6674
6674
|
restoredNodeId: r
|
|
6675
6675
|
})) : e.json({ error: "Node not found" }, 404) : e.json({ error: "Node ID required" }, 400);
|
|
6676
|
-
}),
|
|
6676
|
+
}), B.delete("/purge", async (e) => {
|
|
6677
6677
|
let t = e.get("db"), n = e.req.query("id");
|
|
6678
6678
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
6679
6679
|
let r = Number(n);
|
|
6680
|
-
return new
|
|
6680
|
+
return new z(e.env).purgeNode(e, t, r, !0), 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 F(e).clear(), e.json({
|
|
6681
6681
|
success: !0,
|
|
6682
6682
|
purgedNodeId: r
|
|
6683
6683
|
});
|
|
6684
|
-
}),
|
|
6684
|
+
}), B.get("/:id/revisions", async (e) => {
|
|
6685
6685
|
let t = e.get("db"), n = Number(e.req.param("id"));
|
|
6686
6686
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
6687
6687
|
let r = await t.prepare("\n SELECT version, createdById, snapshotJson \n FROM node_revisions \n WHERE nodeId = ? \n ORDER BY version DESC\n ").all(n), i = (Array.isArray(r) ? r : r?.results || []).map((e) => {
|
|
@@ -6697,7 +6697,7 @@ H.get("/", async (e) => {
|
|
|
6697
6697
|
};
|
|
6698
6698
|
});
|
|
6699
6699
|
return e.json({ revisions: i });
|
|
6700
|
-
}),
|
|
6700
|
+
}), B.get("/:id/revisions/:version", async (e) => {
|
|
6701
6701
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
6702
6702
|
if (!i) return e.json({ error: "Snapshot not found" }, 404);
|
|
6703
6703
|
let a = {};
|
|
@@ -6707,7 +6707,7 @@ H.get("/", async (e) => {
|
|
|
6707
6707
|
return e.json({ error: "Corrupt snapshot data" }, 500);
|
|
6708
6708
|
}
|
|
6709
6709
|
return e.json({ snapshot: a });
|
|
6710
|
-
}),
|
|
6710
|
+
}), B.post("/:id/revisions/:version/restore", async (e) => {
|
|
6711
6711
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = e.get("user")?.id || null, a = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
6712
6712
|
if (!a) return e.json({ error: "Snapshot not found" }, 404);
|
|
6713
6713
|
let o = {};
|
|
@@ -6721,15 +6721,15 @@ H.get("/", async (e) => {
|
|
|
6721
6721
|
for (let t of o.blocks) e.push("(?, ?, ?, ?, ?, 1)"), r.push(n, t.sortOrder, t.elementType, t.dataJson, t.region || "content");
|
|
6722
6722
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...r);
|
|
6723
6723
|
}
|
|
6724
|
-
return await
|
|
6724
|
+
return await F(e).clear(), e.json({
|
|
6725
6725
|
success: !0,
|
|
6726
6726
|
restoredVersion: r
|
|
6727
6727
|
});
|
|
6728
6728
|
});
|
|
6729
6729
|
//#endregion
|
|
6730
6730
|
//#region server/routes/admin/trees.ts
|
|
6731
|
-
var
|
|
6732
|
-
function
|
|
6731
|
+
var U = new e();
|
|
6732
|
+
function ve(e, t = null) {
|
|
6733
6733
|
let n = [];
|
|
6734
6734
|
for (let r = 0; r < e.length; r++) {
|
|
6735
6735
|
let i = e[r];
|
|
@@ -6741,19 +6741,19 @@ function _e(e, t = null) {
|
|
|
6741
6741
|
id: o,
|
|
6742
6742
|
parentId: t,
|
|
6743
6743
|
sortOrder: r
|
|
6744
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
6744
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...ve(i.children, o)));
|
|
6745
6745
|
}
|
|
6746
6746
|
return n;
|
|
6747
6747
|
}
|
|
6748
|
-
function
|
|
6748
|
+
function W(e) {
|
|
6749
6749
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6750
6750
|
let t = Number(e);
|
|
6751
6751
|
return isNaN(t) ? null : t;
|
|
6752
6752
|
}
|
|
6753
|
-
function
|
|
6753
|
+
function G(e) {
|
|
6754
6754
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6755
6755
|
}
|
|
6756
|
-
|
|
6756
|
+
U.get("/tree.json", async (e) => {
|
|
6757
6757
|
try {
|
|
6758
6758
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
6759
6759
|
if (isNaN(Number(n))) {
|
|
@@ -6806,9 +6806,9 @@ W.get("/tree.json", async (e) => {
|
|
|
6806
6806
|
} catch (t) {
|
|
6807
6807
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
6808
6808
|
}
|
|
6809
|
-
}),
|
|
6809
|
+
}), U.post("/tree.json", async (e) => {
|
|
6810
6810
|
try {
|
|
6811
|
-
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i =
|
|
6811
|
+
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = F(e), a = new z(e.env), o = 1;
|
|
6812
6812
|
if (isNaN(Number(r))) {
|
|
6813
6813
|
let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
|
|
6814
6814
|
if (e && e.id) o = Number(e.id);
|
|
@@ -6818,7 +6818,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6818
6818
|
}
|
|
6819
6819
|
} else o = Number(r);
|
|
6820
6820
|
if (n.tree && Array.isArray(n.tree)) {
|
|
6821
|
-
let r =
|
|
6821
|
+
let r = ve(n.tree, null);
|
|
6822
6822
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
6823
6823
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
6824
6824
|
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
@@ -6838,9 +6838,9 @@ W.get("/tree.json", async (e) => {
|
|
|
6838
6838
|
reorderedCount: r.length
|
|
6839
6839
|
});
|
|
6840
6840
|
}
|
|
6841
|
-
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h =
|
|
6841
|
+
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h = G(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
|
|
6842
6842
|
delete m._isTreeDraft, delete m._draftParentId, delete m.isNew, delete m.nodeType, delete m.contentType, delete m.title, delete m.slug, delete m.hidden, delete m.is_hidden, delete m.isHidden, delete m.status;
|
|
6843
|
-
let g =
|
|
6843
|
+
let g = W(u), _ = e.get("user")?.id || null;
|
|
6844
6844
|
if (s === "create") {
|
|
6845
6845
|
let r = m.slug || n.slug || c, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
6846
6846
|
if (a) {
|
|
@@ -6948,7 +6948,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6948
6948
|
details: t.message
|
|
6949
6949
|
}, 500);
|
|
6950
6950
|
}
|
|
6951
|
-
}),
|
|
6951
|
+
}), U.get("/trees.json", async (e) => {
|
|
6952
6952
|
try {
|
|
6953
6953
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM trees ORDER BY LOWER(label) ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId FROM channel_trees").all(), a = (Array.isArray(i) ? i : i?.results || []).reduce((e, t) => {
|
|
6954
6954
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -6978,7 +6978,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6978
6978
|
} catch {
|
|
6979
6979
|
return e.json([]);
|
|
6980
6980
|
}
|
|
6981
|
-
}),
|
|
6981
|
+
}), U.post("/trees.json", async (e) => {
|
|
6982
6982
|
try {
|
|
6983
6983
|
let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, a = `tree-${Date.now().toString(36)}`, o = (n.key || n.slug || a).toLowerCase().replace(/[^a-z0-9_-]/g, "-"), s = n.label?.trim() || o, c = n.treeType !== void 0 && n.treeType !== null ? n.treeType : n.type ?? "site", l = n.channelId !== void 0 && n.channelId !== null && Number(n.channelId) || null, u = +(n.isHidden === !0 || n.isHidden === 1 || n.isHidden === "true"), d = e.get("user")?.id || null, f = { ...n };
|
|
6984
6984
|
if (delete f.id, delete f.key, delete f.label, delete f.treeType, delete f.type, delete f.channelId, delete f.channels, delete f.isHidden, delete f.createdById, delete f.updatedById, delete f.createdAt, delete f.updatedAt, await t.prepare("SELECT id FROM trees WHERE key = ? AND id != ? LIMIT 1").get(o, i ?? -1)) return e.json({
|
|
@@ -7003,7 +7003,7 @@ W.get("/tree.json", async (e) => {
|
|
|
7003
7003
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
7004
7004
|
}
|
|
7005
7005
|
}
|
|
7006
|
-
return await
|
|
7006
|
+
return await F(e).clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7007
7007
|
success: !0,
|
|
7008
7008
|
id: p,
|
|
7009
7009
|
key: o,
|
|
@@ -7017,12 +7017,12 @@ W.get("/tree.json", async (e) => {
|
|
|
7017
7017
|
} catch (t) {
|
|
7018
7018
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
7019
7019
|
}
|
|
7020
|
-
}),
|
|
7020
|
+
}), U.delete("/trees.json", async (e) => {
|
|
7021
7021
|
let t = e.get("db"), n = e.req.query("id");
|
|
7022
7022
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
7023
7023
|
let r = Number(n);
|
|
7024
7024
|
try {
|
|
7025
|
-
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
|
|
7025
|
+
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 F(e).clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7026
7026
|
success: !0,
|
|
7027
7027
|
deletedTreeId: r
|
|
7028
7028
|
});
|
|
@@ -7057,7 +7057,7 @@ ye.get("/", async (e) => {
|
|
|
7057
7057
|
isHidden: !!e.isHidden,
|
|
7058
7058
|
trees: a[e.id] || []
|
|
7059
7059
|
};
|
|
7060
|
-
}), s = e.env?.BUNDLED_DEFINITIONS, c =
|
|
7060
|
+
}), s = e.env?.BUNDLED_DEFINITIONS, c = le(s), l = c?.channelTemplate || Object.values(c?.channels || {})[0] || {
|
|
7061
7061
|
label: "Channel Settings",
|
|
7062
7062
|
fields: {
|
|
7063
7063
|
key: {
|
|
@@ -7128,8 +7128,8 @@ ye.get("/", async (e) => {
|
|
|
7128
7128
|
VALUES ${e}
|
|
7129
7129
|
`).run(...n);
|
|
7130
7130
|
}
|
|
7131
|
-
let M =
|
|
7132
|
-
return await M.delete(`channel:${C}`), await M.delete(`channel:${A}`), await M.clear(), new
|
|
7131
|
+
let M = F(e);
|
|
7132
|
+
return await M.delete(`channel:${C}`), await M.delete(`channel:${A}`), await M.clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7133
7133
|
success: !0,
|
|
7134
7134
|
id: A
|
|
7135
7135
|
});
|
|
@@ -7145,8 +7145,8 @@ ye.get("/", async (e) => {
|
|
|
7145
7145
|
let r = Number(n);
|
|
7146
7146
|
try {
|
|
7147
7147
|
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);
|
|
7148
|
-
let n =
|
|
7149
|
-
return await n.delete(`channel:${r}`), await n.clear(), new
|
|
7148
|
+
let n = F(e);
|
|
7149
|
+
return await n.delete(`channel:${r}`), await n.clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7150
7150
|
success: !0,
|
|
7151
7151
|
deletedSiteId: r
|
|
7152
7152
|
});
|
|
@@ -7560,7 +7560,7 @@ function je(e) {
|
|
|
7560
7560
|
fields: n
|
|
7561
7561
|
};
|
|
7562
7562
|
});
|
|
7563
|
-
let
|
|
7563
|
+
let te = {};
|
|
7564
7564
|
Object.entries(T).forEach(([e, t]) => {
|
|
7565
7565
|
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { content: { label: "Content" } };
|
|
7566
7566
|
Object.entries(a).forEach(([e, t]) => {
|
|
@@ -7570,7 +7570,7 @@ function je(e) {
|
|
|
7570
7570
|
allowedBlocks: Se(t.allowedBlocks),
|
|
7571
7571
|
disallowedBlocks: t.disallowedBlocks ? Se(t.disallowedBlocks) : void 0
|
|
7572
7572
|
};
|
|
7573
|
-
}),
|
|
7573
|
+
}), te[e] = {
|
|
7574
7574
|
...t,
|
|
7575
7575
|
id: t.id || e,
|
|
7576
7576
|
label: t.label || e,
|
|
@@ -7583,7 +7583,7 @@ function je(e) {
|
|
|
7583
7583
|
tabs: n
|
|
7584
7584
|
};
|
|
7585
7585
|
});
|
|
7586
|
-
let
|
|
7586
|
+
let ne = {};
|
|
7587
7587
|
Object.entries(E).forEach(([e, t]) => {
|
|
7588
7588
|
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { main: { label: "Main Content" } };
|
|
7589
7589
|
Object.entries(a).forEach(([e, t]) => {
|
|
@@ -7593,7 +7593,7 @@ function je(e) {
|
|
|
7593
7593
|
allowedBlocks: Se(t.allowedBlocks),
|
|
7594
7594
|
disallowedBlocks: t.disallowedBlocks ? Se(t.disallowedBlocks) : void 0
|
|
7595
7595
|
};
|
|
7596
|
-
}),
|
|
7596
|
+
}), ne[e] = {
|
|
7597
7597
|
...t,
|
|
7598
7598
|
id: t.id || e,
|
|
7599
7599
|
label: t.label || e,
|
|
@@ -7606,39 +7606,39 @@ function je(e) {
|
|
|
7606
7606
|
tabs: n
|
|
7607
7607
|
};
|
|
7608
7608
|
});
|
|
7609
|
-
let
|
|
7609
|
+
let P = m?.fields || {};
|
|
7610
7610
|
Array.isArray(m?.fieldSets) && m?.fieldSets.forEach((e) => {
|
|
7611
7611
|
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
7612
7612
|
Object.entries(r).forEach(([e, t]) => {
|
|
7613
|
-
|
|
7613
|
+
P[e] = Y(P[e] || {}, t);
|
|
7614
7614
|
});
|
|
7615
7615
|
});
|
|
7616
|
-
let
|
|
7616
|
+
let F = m ? {
|
|
7617
7617
|
...m,
|
|
7618
|
-
fields:
|
|
7619
|
-
} : null,
|
|
7618
|
+
fields: P
|
|
7619
|
+
} : null, re = h?.fields || {};
|
|
7620
7620
|
Array.isArray(h?.fieldSets) && h?.fieldSets.forEach((e) => {
|
|
7621
7621
|
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
7622
7622
|
Object.entries(r).forEach(([e, t]) => {
|
|
7623
|
-
|
|
7623
|
+
re[e] = Y(re[e] || {}, t);
|
|
7624
7624
|
});
|
|
7625
7625
|
});
|
|
7626
|
-
let
|
|
7626
|
+
let ie = h ? {
|
|
7627
7627
|
...h,
|
|
7628
|
-
fields:
|
|
7628
|
+
fields: re
|
|
7629
7629
|
} : null;
|
|
7630
7630
|
return {
|
|
7631
7631
|
nodes: j,
|
|
7632
7632
|
trees: M,
|
|
7633
7633
|
channels: N,
|
|
7634
7634
|
blocks: ee,
|
|
7635
|
-
nodeLayouts:
|
|
7636
|
-
blockLayouts:
|
|
7635
|
+
nodeLayouts: te,
|
|
7636
|
+
blockLayouts: ne,
|
|
7637
7637
|
fieldSets: O,
|
|
7638
7638
|
nodeTemplate: f || null,
|
|
7639
7639
|
treeTemplate: p || null,
|
|
7640
|
-
channelTemplate:
|
|
7641
|
-
userTemplate:
|
|
7640
|
+
channelTemplate: F,
|
|
7641
|
+
userTemplate: ie
|
|
7642
7642
|
};
|
|
7643
7643
|
}
|
|
7644
7644
|
//#endregion
|
|
@@ -7765,7 +7765,7 @@ Le.get("/", async (e) => {
|
|
|
7765
7765
|
isHidden: !!e.isHidden,
|
|
7766
7766
|
channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
|
|
7767
7767
|
treeNames: e.treeLabels ? e.treeLabels.split(",") : []
|
|
7768
|
-
})), p = e.env?.BUNDLED_DEFINITIONS, m =
|
|
7768
|
+
})), p = e.env?.BUNDLED_DEFINITIONS, m = le(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
|
|
7769
7769
|
let t = e.type || "node", n = h[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
|
|
7770
7770
|
return {
|
|
7771
7771
|
type: t,
|
|
@@ -7895,7 +7895,7 @@ X.get("/", async (e) => {
|
|
|
7895
7895
|
}
|
|
7896
7896
|
}), X.post("/upload", async (e) => {
|
|
7897
7897
|
try {
|
|
7898
|
-
let t = l(e), { storage: n } =
|
|
7898
|
+
let t = l(e), { storage: n } = I(e.env), r = await e.req.parseBody(), i = r.file, a = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", o = r.replaceAssetId, s = typeof o == "string" && o.trim().length > 0 ? o.trim() : null, c = r.parentAssetId || r.parentAsset, u = typeof c == "string" && c.trim().length > 0 ? c.trim() : null;
|
|
7899
7899
|
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
7900
7900
|
let d = r.cropCoordinates, f = null, p = null;
|
|
7901
7901
|
if (d) {
|
|
@@ -7910,7 +7910,7 @@ X.get("/", async (e) => {
|
|
|
7910
7910
|
if (!y) throw Error("Storage provider failed to return a valid storage key");
|
|
7911
7911
|
let b = e.env.CDN_DOMAIN, x = y.replace(/^\//, ""), S = b ? `https://${b}/media/${x}` : `/media/${x}`, C = i.type || "application/octet-stream", w = i.size || 0, T = e.get("userId"), E = typeof T == "string" && T.trim().length > 0 ? T : null;
|
|
7912
7912
|
E && (await Z(t, "SELECT id FROM users WHERE id = ?", [E])).length === 0 && (E = null);
|
|
7913
|
-
let D = new
|
|
7913
|
+
let D = new z(e.env);
|
|
7914
7914
|
if (s) {
|
|
7915
7915
|
let r = await Z(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
7916
7916
|
if (r.length > 0) {
|
|
@@ -8041,14 +8041,14 @@ X.get("/", async (e) => {
|
|
|
8041
8041
|
r.filename === void 0 ? a.filename : r.filename,
|
|
8042
8042
|
JSON.stringify(o),
|
|
8043
8043
|
n
|
|
8044
|
-
]), new
|
|
8044
|
+
]), new z(e.env).purgeAsset(e, t, n), e.json({ success: !0 });
|
|
8045
8045
|
} catch {
|
|
8046
8046
|
return e.json({ error: "Failed to update asset" }, 500);
|
|
8047
8047
|
}
|
|
8048
8048
|
}), X.delete("/:id", async (e) => {
|
|
8049
8049
|
try {
|
|
8050
8050
|
let t = l(e), n = e.req.param("id"), r = (await Z(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
8051
|
-
return r ? (new
|
|
8051
|
+
return r ? (new z(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await Q(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await Q(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [n, n]), e.json({
|
|
8052
8052
|
success: !0,
|
|
8053
8053
|
id: n,
|
|
8054
8054
|
trashed: !0
|
|
@@ -8062,7 +8062,7 @@ X.get("/", async (e) => {
|
|
|
8062
8062
|
}), X.post("/restore", async (e) => {
|
|
8063
8063
|
try {
|
|
8064
8064
|
let t = l(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
8065
|
-
return r ? (await Z(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0] ? (await Q(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [r, r]), new
|
|
8065
|
+
return r ? (await Z(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0] ? (await Q(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [r, r]), new z(e.env).purgeAsset(e, t, r), e.json({
|
|
8066
8066
|
success: !0,
|
|
8067
8067
|
id: r,
|
|
8068
8068
|
restored: !0
|
|
@@ -8075,9 +8075,9 @@ X.get("/", async (e) => {
|
|
|
8075
8075
|
}
|
|
8076
8076
|
}), X.delete("/purge/:id", async (e) => {
|
|
8077
8077
|
try {
|
|
8078
|
-
let t = l(e), { storage: n } =
|
|
8078
|
+
let t = l(e), { storage: n } = I(e.env), r = e.req.param("id"), i = (await Z(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
8079
8079
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
8080
|
-
new
|
|
8080
|
+
new z(e.env).purgeAsset(e, t, r);
|
|
8081
8081
|
let a = [i];
|
|
8082
8082
|
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
8083
8083
|
let o = a.map((e) => e.id);
|
|
@@ -8201,7 +8201,7 @@ async function We(e, t, n, r, i, a = !1, o) {
|
|
|
8201
8201
|
let o = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = He(n.startShowingAt, n.stopShowingAt);
|
|
8202
8202
|
if (!a && (o || !s)) return null;
|
|
8203
8203
|
let c = t.elementType || t.componentId || "text-block", l = i.blocks?.[c]?.fields || i.elements?.[c]?.fields || i.components?.[c]?.fields || {}, u = String(n.blockId || n._instanceId || n.id || t.blockId || t.id), d = Ge(n, l);
|
|
8204
|
-
return d = await
|
|
8204
|
+
return d = await R(e, d), d = Ke(d), d.blockId = u, {
|
|
8205
8205
|
region: t.region || r,
|
|
8206
8206
|
block: {
|
|
8207
8207
|
instanceId: t.id,
|
|
@@ -8449,85 +8449,94 @@ async function nt(e, t, n, r) {
|
|
|
8449
8449
|
}
|
|
8450
8450
|
ze.get("/*", async (e) => {
|
|
8451
8451
|
try {
|
|
8452
|
-
let t = e.get("db"), n = Be(), 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"), 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));
|
|
8453
|
-
if (!
|
|
8454
|
-
let
|
|
8455
|
-
if (!s &&
|
|
8456
|
-
let
|
|
8452
|
+
let t = e.get("db"), n = Be(), 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"), s = e.req.query("preview") === "true", c = e.req.query("revisionId"), l = isNaN(Number(a)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(a) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(a));
|
|
8453
|
+
if (!l) return e.json({ error: `Channel '${a}' not found` }, 404);
|
|
8454
|
+
let u = l.status === "disabled" || l.status === "inactive" || l.isEnabled === 0 || l.isEnabled === !1;
|
|
8455
|
+
if (!s && u) return e.json({ error: `Channel '${l.key || a}' is currently inactive` }, 404);
|
|
8456
|
+
let d = l.id, f = l.key || a, p = F(e), m = le(e.env?.BUNDLED_DEFINITIONS), h = /^\d+$/.test(i), g = null, _ = null, v = e.req.query("treeId"), y = i.split("/"), b = y[y.length - 1], x = "/" + i.replace(/^\/+|\/+$/g, ""), S = `
|
|
8457
8457
|
SELECT cn.*, tn.contentId as treeNodeId, tn.parentId, tn.treeId FROM content_nodes cn
|
|
8458
8458
|
INNER JOIN tree_nodes tn ON cn.id = tn.contentId
|
|
8459
|
-
${
|
|
8460
|
-
WHERE cn.slug = ? ${
|
|
8461
|
-
`,
|
|
8462
|
-
if (
|
|
8463
|
-
let e = await Promise.all(
|
|
8459
|
+
${d === null ? "" : "INNER JOIN node_channels nc ON cn.id = nc.nodeId"}
|
|
8460
|
+
WHERE cn.slug = ? ${d === null ? "" : "AND nc.channelId = ?"}
|
|
8461
|
+
`, C = d === null ? [b] : [b, d], w = await t.prepare(S).all(...C), T = Array.isArray(w) ? w : w?.results || [];
|
|
8462
|
+
if (T.length > 0) {
|
|
8463
|
+
let e = await Promise.all(T.map(async (e) => ({
|
|
8464
8464
|
candidate: e,
|
|
8465
8465
|
calculatedPath: await $e(t, String(e.treeNodeId), String(e.treeId), n)
|
|
8466
|
-
}))), r =
|
|
8466
|
+
}))), r = x.replace(/^\/+|\/+$/g, "");
|
|
8467
8467
|
for (let { candidate: t, calculatedPath: n } of e) {
|
|
8468
8468
|
let e = n.replace(/^\/+|\/+$/g, "");
|
|
8469
8469
|
if (e === r || r === "home" && (e === "" || e === "home")) {
|
|
8470
|
-
|
|
8470
|
+
g = t, _ = t;
|
|
8471
8471
|
break;
|
|
8472
8472
|
}
|
|
8473
8473
|
}
|
|
8474
8474
|
}
|
|
8475
|
-
if (!
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8475
|
+
if (!g && y.length === 1 && (g = d === null ? await t.prepare("SELECT * FROM content_nodes WHERE slug = ?").get(b) : await t.prepare("SELECT cn.* FROM content_nodes cn INNER JOIN node_channels nc ON cn.id = nc.nodeId WHERE cn.slug = ? AND nc.channelId = ?").get(b, d)), !g && h && (g = d === null ? await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(Number(i)) : await t.prepare("SELECT cn.* FROM content_nodes cn INNER JOIN node_channels nc ON cn.id = nc.nodeId WHERE cn.id = ? AND nc.channelId = ?").get(Number(i), d)), !g) return e.json({ error: `Node '${i}' not found for Channel '${a}'` }, 404);
|
|
8476
|
+
let E = null;
|
|
8477
|
+
if (c) {
|
|
8478
|
+
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(g.id, Number(c));
|
|
8479
|
+
if (e && e.snapshotJson) try {
|
|
8480
|
+
E = JSON.parse(e.snapshotJson), E.node && (E.node.title && (g.title = E.node.title), E.node.slug && (g.slug = E.node.slug));
|
|
8481
|
+
} catch (e) {
|
|
8482
|
+
console.error("[CMS] Failed to parse snapshotJson", e);
|
|
8483
|
+
}
|
|
8484
|
+
}
|
|
8485
|
+
if (!_) {
|
|
8486
|
+
let e = v ? [g.id, v] : [g.id];
|
|
8487
|
+
_ = await t.prepare(`SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${v ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
|
|
8479
8488
|
}
|
|
8480
|
-
let
|
|
8481
|
-
if (
|
|
8482
|
-
let e = await t.prepare("\n SELECT dataJson \n FROM trees \n WHERE id = ? OR key = ? \n LIMIT 1\n ").get(Number(
|
|
8489
|
+
let D = _?.treeId || v || "main-nav", O = null;
|
|
8490
|
+
if (D) {
|
|
8491
|
+
let e = await t.prepare("\n SELECT dataJson \n FROM trees \n WHERE id = ? OR key = ? \n LIMIT 1\n ").get(Number(D) || -1, String(D));
|
|
8483
8492
|
if (e?.dataJson) try {
|
|
8484
8493
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
8485
|
-
t.defaultLanguage ?
|
|
8494
|
+
t.defaultLanguage ? O = String(t.defaultLanguage).trim() : t.language && (O = String(t.language).trim());
|
|
8486
8495
|
} catch {}
|
|
8487
8496
|
}
|
|
8488
|
-
let
|
|
8489
|
-
if (
|
|
8490
|
-
if (
|
|
8491
|
-
else if (
|
|
8492
|
-
let e = typeof
|
|
8493
|
-
e.defaultLanguage ?
|
|
8497
|
+
let k = null;
|
|
8498
|
+
if (l) {
|
|
8499
|
+
if (l.defaultLanguage) k = String(l.defaultLanguage).trim();
|
|
8500
|
+
else if (l.dataJson) try {
|
|
8501
|
+
let e = typeof l.dataJson == "string" ? JSON.parse(l.dataJson) : l.dataJson;
|
|
8502
|
+
e.defaultLanguage ? k = String(e.defaultLanguage).trim() : e.language && (k = String(e.language).trim());
|
|
8494
8503
|
} catch {}
|
|
8495
8504
|
}
|
|
8496
|
-
let
|
|
8497
|
-
if (!s && !
|
|
8498
|
-
let t = await
|
|
8505
|
+
let A = g.language?.trim() || null, j = O || k || o?.trim() || null, M = A || j || null, N = `node:${d || f}:${M || "default"}:${i}`, ee = e.req.header("x-bypass-cache") === "true" || !!c;
|
|
8506
|
+
if (!s && !ee) {
|
|
8507
|
+
let t = await p.get(N);
|
|
8499
8508
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
8500
8509
|
}
|
|
8501
|
-
let
|
|
8502
|
-
id:
|
|
8503
|
-
title:
|
|
8504
|
-
slug:
|
|
8505
|
-
language:
|
|
8506
|
-
path:
|
|
8507
|
-
nodeType:
|
|
8508
|
-
createdAt:
|
|
8509
|
-
updatedAt:
|
|
8510
|
-
},
|
|
8511
|
-
|
|
8512
|
-
Object.assign(
|
|
8510
|
+
let te = _?.parentId || null, ne = _?.treeNodeId ? await $e(t, String(_.treeNodeId), String(D), n) : `/${(g.slug || "").replace(/^\/+|\/+$/g, "")}`, P = {
|
|
8511
|
+
id: g.id,
|
|
8512
|
+
title: g.title,
|
|
8513
|
+
slug: g.slug,
|
|
8514
|
+
language: M,
|
|
8515
|
+
path: ne === "" ? "/" : ne,
|
|
8516
|
+
nodeType: g.contentType,
|
|
8517
|
+
createdAt: g.createdAt,
|
|
8518
|
+
updatedAt: g.updatedAt
|
|
8519
|
+
}, re = g.contentType || "node", ie = m.nodes?.[re] || Object.values(m.nodes || {})[0] || {}, ae = { ...ie.fields || {} };
|
|
8520
|
+
ie.tabs && Object.values(ie.tabs).forEach((e) => {
|
|
8521
|
+
Object.assign(ae, e.fields || {});
|
|
8513
8522
|
});
|
|
8514
|
-
let
|
|
8515
|
-
if (
|
|
8516
|
-
|
|
8523
|
+
let oe = {}, I = null, se = null, ce = !1, L = {}, z = s && g.draftDataJson || g.dataJson;
|
|
8524
|
+
if (E && E.node && E.node.dataJson && (z = E.node.dataJson), z) try {
|
|
8525
|
+
L = typeof z == "string" ? JSON.parse(z) : z;
|
|
8517
8526
|
} catch {}
|
|
8518
|
-
|
|
8519
|
-
let
|
|
8520
|
-
for (let [e, t] of Object.entries(
|
|
8521
|
-
let
|
|
8522
|
-
|
|
8523
|
-
let
|
|
8524
|
-
delete
|
|
8525
|
-
let
|
|
8526
|
-
if (!s && (
|
|
8527
|
-
let
|
|
8528
|
-
if (
|
|
8529
|
-
let e = await t.prepare("\n SELECT t.contentId as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.dataJson, c.draftDataJson\n FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? ORDER BY t.sortOrder ASC\n ").all(
|
|
8530
|
-
|
|
8527
|
+
L.disabledRegions && (oe = L.disabledRegions), ce = L.hidden === !0 || L.hidden === 1 || L.hidden === "1" || L.hidden === "true", I = L.startShowingAt || null, se = L.stopShowingAt || null;
|
|
8528
|
+
let B = L.layoutId, ue = B && B !== "inherit", { resolvedLayoutId: de, inheritedFields: fe } = await et(t, te, D, s, ae), V = ue ? B : de || ie.defaultLayout || null;
|
|
8529
|
+
for (let [e, t] of Object.entries(fe)) (L[e] === void 0 || L[e] === null || L[e] === "" || L[e] === "inherit") && t !== void 0 && (L[e] = t);
|
|
8530
|
+
let H = await R(t, Ge(L, ae));
|
|
8531
|
+
H = Ke(H), H = await qe(t, H, n), delete H.language;
|
|
8532
|
+
let pe = Qe(H);
|
|
8533
|
+
delete H.socialImage, delete H.fbImage, delete H.xImage, delete H.whatsappImage, pe && (H.socialImages = pe), P.slug = g.slug, P.title = g.title, Object.assign(P, H), P.layoutId = V;
|
|
8534
|
+
let me = Number(g.isHidden) === 1 || ce, he = !He(I, se), ge = g.status === "draft" || g.status === "new", _e = g.dataJson && g.dataJson !== "{}" && g.dataJson !== "null";
|
|
8535
|
+
if (!s && (me || he || ge && !_e)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
8536
|
+
let U = [];
|
|
8537
|
+
if (_?.treeNodeId) {
|
|
8538
|
+
let e = await t.prepare("\n SELECT t.contentId as treeNodeId, t.contentId as id, c.title, c.slug, c.language, c.contentType as nodeType, c.isHidden, c.dataJson, c.draftDataJson\n FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.parentId = ? AND t.treeId = ? ORDER BY t.sortOrder ASC\n ").all(_.treeNodeId, D), n = Array.isArray(e) ? e : e?.results || [], r = P.path === "/" ? "" : P.path;
|
|
8539
|
+
U = n.map((e) => {
|
|
8531
8540
|
let t = {}, n = s && e.draftDataJson || e.dataJson;
|
|
8532
8541
|
if (!n) return null;
|
|
8533
8542
|
try {
|
|
@@ -8539,22 +8548,31 @@ ze.get("/*", async (e) => {
|
|
|
8539
8548
|
id: e.id,
|
|
8540
8549
|
title: e.title,
|
|
8541
8550
|
slug: o,
|
|
8542
|
-
language: e.language?.trim() ||
|
|
8551
|
+
language: e.language?.trim() || M || null,
|
|
8543
8552
|
path: `${r}/${o}`.replace(/\/+/g, "/"),
|
|
8544
8553
|
nodeType: e.nodeType
|
|
8545
8554
|
};
|
|
8546
8555
|
}).filter(Boolean);
|
|
8547
8556
|
}
|
|
8548
|
-
P.children =
|
|
8549
|
-
let
|
|
8557
|
+
P.children = U;
|
|
8558
|
+
let ve = [];
|
|
8559
|
+
if (E && E.blocks && Array.isArray(E.blocks)) ve = E.blocks.map((e) => ({
|
|
8560
|
+
...e,
|
|
8561
|
+
isDraft: 1
|
|
8562
|
+
}));
|
|
8563
|
+
else {
|
|
8564
|
+
let e = +!!s, n = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(g.id, e);
|
|
8565
|
+
ve = Array.isArray(n) ? n : n?.results || [];
|
|
8566
|
+
}
|
|
8567
|
+
let W = {}, G = {}, ye = await Promise.all(ve.map(async (e) => {
|
|
8550
8568
|
let r = e.region || "main", i = {};
|
|
8551
8569
|
try {
|
|
8552
8570
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
8553
8571
|
} catch {}
|
|
8554
8572
|
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = He(i.startShowingAt, i.stopShowingAt);
|
|
8555
8573
|
if (!s && (a || !o)) return null;
|
|
8556
|
-
let c = e.elementType || e.componentId || "text-block", l =
|
|
8557
|
-
return d = await
|
|
8574
|
+
let c = e.elementType || e.componentId || "text-block", l = m.blocks?.[c]?.fields || m.elements?.[c]?.fields || m.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || i.id || e.blockId || e.id), d = Ge(i, l);
|
|
8575
|
+
return d = await R(t, d), d = Ke(d), d = await qe(t, d, n), d.blockId = u, {
|
|
8558
8576
|
region: r,
|
|
8559
8577
|
block: {
|
|
8560
8578
|
instanceId: e.id,
|
|
@@ -8564,7 +8582,7 @@ ze.get("/*", async (e) => {
|
|
|
8564
8582
|
}
|
|
8565
8583
|
};
|
|
8566
8584
|
}));
|
|
8567
|
-
for (let e of ye) e && (
|
|
8585
|
+
for (let e of ye) e && (W[e.region] || (W[e.region] = [], G[e.region] = { isInherited: !1 }), W[e.region].push(e.block));
|
|
8568
8586
|
let K = {
|
|
8569
8587
|
header: {
|
|
8570
8588
|
label: "Header",
|
|
@@ -8574,33 +8592,33 @@ ze.get("/*", async (e) => {
|
|
|
8574
8592
|
label: "Footer",
|
|
8575
8593
|
inherit: "parent"
|
|
8576
8594
|
},
|
|
8577
|
-
...(
|
|
8595
|
+
...(V ? m.nodeLayouts?.[V] || m.layouts?.[V] : null)?.regions || { main: { label: "Content" } }
|
|
8578
8596
|
};
|
|
8579
8597
|
for (let [e, r] of Object.entries(K)) {
|
|
8580
|
-
let i =
|
|
8581
|
-
if (
|
|
8582
|
-
let r = await We(t,
|
|
8583
|
-
if (r.blocks.length > 0 && (
|
|
8598
|
+
let i = W[e] && W[e].length > 0, a = !!oe[e];
|
|
8599
|
+
if (W[e] || (W[e] = [], G[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && te) {
|
|
8600
|
+
let r = await We(t, te, String(D), e, m, s, n);
|
|
8601
|
+
if (r.blocks.length > 0 && (W[e] = r.blocks, G[e] = {
|
|
8584
8602
|
isInherited: !0,
|
|
8585
8603
|
inheritedFromId: r.inheritedFromId,
|
|
8586
8604
|
inheritedFromTitle: r.inheritedFromTitle
|
|
8587
|
-
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (
|
|
8605
|
+
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (W[t] = n, G[t] = {
|
|
8588
8606
|
isInherited: !0,
|
|
8589
8607
|
inheritedFromId: r.inheritedFromId,
|
|
8590
8608
|
inheritedFromTitle: r.inheritedFromTitle
|
|
8591
8609
|
});
|
|
8592
8610
|
}
|
|
8593
8611
|
}
|
|
8594
|
-
await Promise.all(Object.keys(
|
|
8612
|
+
await Promise.all(Object.keys(W).map((e) => Ue(t, W[e], d, M)));
|
|
8595
8613
|
let q = {
|
|
8596
|
-
channelId:
|
|
8597
|
-
treeId:
|
|
8598
|
-
language:
|
|
8614
|
+
channelId: d || f,
|
|
8615
|
+
treeId: D,
|
|
8616
|
+
language: M,
|
|
8599
8617
|
node: P,
|
|
8600
|
-
content:
|
|
8601
|
-
regionMeta:
|
|
8618
|
+
content: W,
|
|
8619
|
+
regionMeta: G
|
|
8602
8620
|
};
|
|
8603
|
-
return !s && !
|
|
8621
|
+
return !s && !ee && (e.header("X-Cache", "MISS"), await nt(p, N, q, tt(e))), e.json(q);
|
|
8604
8622
|
} catch (t) {
|
|
8605
8623
|
return console.error("[CMS Public API] Error fetching node by path:", t), e.json({
|
|
8606
8624
|
error: "Failed to fetch JSON payload",
|
|
@@ -8651,14 +8669,14 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8651
8669
|
e.defaultLanguage && (l = String(e.defaultLanguage).trim());
|
|
8652
8670
|
} catch {}
|
|
8653
8671
|
}
|
|
8654
|
-
let u = l || o || i?.trim() || null, d =
|
|
8672
|
+
let u = l || o || i?.trim() || null, d = F(e), f = `tree:${r}:${n}:${u || "default"}`, p = e.req.header("x-bypass-cache") === "true";
|
|
8655
8673
|
if (!a && !p) {
|
|
8656
8674
|
let t = await d.get(f);
|
|
8657
8675
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
8658
8676
|
}
|
|
8659
8677
|
let m = c?.id || (s ? Number(n) : null), h = {};
|
|
8660
8678
|
if (c && c.dataJson) try {
|
|
8661
|
-
let t = typeof c.dataJson == "string" ? JSON.parse(c.dataJson) : c.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i =
|
|
8679
|
+
let t = typeof c.dataJson == "string" ? JSON.parse(c.dataJson) : c.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = le(r), a = (i.trees?.[c.treeType || n] || i.trees?.site || {}).fields || {};
|
|
8662
8680
|
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (h[e] = n);
|
|
8663
8681
|
} catch (e) {
|
|
8664
8682
|
console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
|
|
@@ -8833,7 +8851,7 @@ async function ft(e, t) {
|
|
|
8833
8851
|
}
|
|
8834
8852
|
ot.get("/:channelParam", async (e) => {
|
|
8835
8853
|
try {
|
|
8836
|
-
let t = e.get("db"), n = e.req.param("channelParam"), r = e.req.query("preview") === "true", i = e.req.header("x-bypass-cache") === "true", a = `channel:${n}:${r ? "preview" : "live"}`, o =
|
|
8854
|
+
let t = e.get("db"), n = e.req.param("channelParam"), r = e.req.query("preview") === "true", i = e.req.header("x-bypass-cache") === "true", a = `channel:${n}:${r ? "preview" : "live"}`, o = F(e);
|
|
8837
8855
|
if (!r && !i) {
|
|
8838
8856
|
let t = await o.get(a);
|
|
8839
8857
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
@@ -8842,7 +8860,7 @@ ot.get("/:channelParam", async (e) => {
|
|
|
8842
8860
|
if (!s) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
8843
8861
|
let c = s.status === "disabled" || s.status === "inactive" || s.isEnabled === 0 || s.isEnabled === !1;
|
|
8844
8862
|
if (!r && c) return e.json({ error: `Channel '${s.key || n}' is currently inactive` }, 404);
|
|
8845
|
-
let l = e.env?.BUNDLED_DEFINITIONS, u =
|
|
8863
|
+
let l = e.env?.BUNDLED_DEFINITIONS, u = le(l), d = s.channelType || s.key || "website", f = lt(u.channels?.[d] || u.channels?.[s.key] || u.channels?.website || u.definitions?.["channel-base"] || {}, u), p = {}, m = r && s.draftDataJson || s.dataJson;
|
|
8846
8864
|
if (m) try {
|
|
8847
8865
|
p = typeof m == "string" ? JSON.parse(m) : m;
|
|
8848
8866
|
} catch (e) {
|
|
@@ -8852,7 +8870,7 @@ ot.get("/:channelParam", async (e) => {
|
|
|
8852
8870
|
...p,
|
|
8853
8871
|
...s
|
|
8854
8872
|
}, f);
|
|
8855
|
-
h = await
|
|
8873
|
+
h = await R(t, h), h = dt(h), h = await ft(t, h);
|
|
8856
8874
|
let g = {
|
|
8857
8875
|
id: s.id,
|
|
8858
8876
|
key: s.key,
|
|
@@ -8893,7 +8911,7 @@ pt.get("/*", async (e) => {
|
|
|
8893
8911
|
let e = await l.match(d);
|
|
8894
8912
|
if (e) return e;
|
|
8895
8913
|
}
|
|
8896
|
-
let { storage: f, optimizer: p } =
|
|
8914
|
+
let { storage: f, optimizer: p } = I(e.env), m = await f.get(t);
|
|
8897
8915
|
if (!m) return e.text(`Asset not found: ${t}`, 404);
|
|
8898
8916
|
if (!o) {
|
|
8899
8917
|
let n = e.body(m, 200, {
|
|
@@ -9003,7 +9021,7 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
9003
9021
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
9004
9022
|
}
|
|
9005
9023
|
await t();
|
|
9006
|
-
}), $.route("/media", pt), $.use("/media/*", y()), $.route("/api/cms/nodes",
|
|
9024
|
+
}), $.route("/media", pt), $.use("/media/*", y()), $.route("/api/cms/nodes", B), $.route("/api/cms/nodes.json", B), $.route("/api/cms/formcsv", B), $.route("/api/cms/formcsv.json", B), $.route("/api/cms/stats", Le), $.route("/api/cms/stats.json", Le), $.route("/api/cms", U), $.route("/api/cms/channels", ye), $.route("/api/cms/channels.json", ye), $.route("/api/cms/schemas", Me), $.route("/api/cms/schemas.json", Me), $.route("/api/cms", Pe), $.route("/api/admin/assets", X), $.route("/api/v1/node", ze), $.route("/api/v1/page", ze), $.route("/api/v1/tree", rt), $.route("/api/v1/channel", ot), $.route("/api/v1/all-paths", ht), $.get("*", async (e, t) => {
|
|
9007
9025
|
if (e.env?.ASSETS) {
|
|
9008
9026
|
let t = await e.env.ASSETS.fetch(e.req.raw);
|
|
9009
9027
|
if (t.status === 404) {
|