@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
|
@@ -5552,7 +5552,7 @@ var b = { hasSubscribers: !1 }, x = b, S = b, C = typeof performance == "object"
|
|
|
5552
5552
|
async clear() {
|
|
5553
5553
|
this.cache.clear();
|
|
5554
5554
|
}
|
|
5555
|
-
},
|
|
5555
|
+
}, te = class {
|
|
5556
5556
|
kv;
|
|
5557
5557
|
constructor(e) {
|
|
5558
5558
|
this.kv = e;
|
|
@@ -5569,19 +5569,19 @@ var b = { hasSubscribers: !1 }, x = b, S = b, C = typeof performance == "object"
|
|
|
5569
5569
|
this.kv && await this.kv.delete(e);
|
|
5570
5570
|
}
|
|
5571
5571
|
async clear() {}
|
|
5572
|
-
},
|
|
5572
|
+
}, ne = class {
|
|
5573
5573
|
async get() {
|
|
5574
5574
|
return null;
|
|
5575
5575
|
}
|
|
5576
5576
|
async set() {}
|
|
5577
5577
|
async delete() {}
|
|
5578
5578
|
async clear() {}
|
|
5579
|
-
},
|
|
5580
|
-
function
|
|
5579
|
+
}, P = null;
|
|
5580
|
+
function F(e) {
|
|
5581
5581
|
let t = process.env.CACHE_DRIVER || "lru";
|
|
5582
|
-
return t === "none" || t === "off" || t === "false" ? new
|
|
5582
|
+
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();
|
|
5583
5583
|
}
|
|
5584
|
-
var
|
|
5584
|
+
var re = class {
|
|
5585
5585
|
customStoragePath;
|
|
5586
5586
|
constructor(e) {
|
|
5587
5587
|
this.customStoragePath = e;
|
|
@@ -5650,7 +5650,7 @@ var L = class {
|
|
|
5650
5650
|
if (e.code !== "ENOENT") throw e;
|
|
5651
5651
|
}
|
|
5652
5652
|
}
|
|
5653
|
-
},
|
|
5653
|
+
}, I = class {
|
|
5654
5654
|
async process(e, t, n) {
|
|
5655
5655
|
let r = await import(
|
|
5656
5656
|
/* @vite-ignore */
|
|
@@ -5677,7 +5677,7 @@ var L = class {
|
|
|
5677
5677
|
return console.warn("⚠️ [SharpImageOptimizer] Processing failed, returning raw buffer."), e;
|
|
5678
5678
|
}
|
|
5679
5679
|
}
|
|
5680
|
-
},
|
|
5680
|
+
}, ie = class {
|
|
5681
5681
|
bucket;
|
|
5682
5682
|
publicDomain;
|
|
5683
5683
|
constructor(e, t) {
|
|
@@ -5722,7 +5722,7 @@ var L = class {
|
|
|
5722
5722
|
async delete(e) {
|
|
5723
5723
|
await this.bucket.delete(e);
|
|
5724
5724
|
}
|
|
5725
|
-
},
|
|
5725
|
+
}, ae = class {
|
|
5726
5726
|
async process(e, t, n) {
|
|
5727
5727
|
let { env: r, key: i, req: a } = n;
|
|
5728
5728
|
if (r.IMAGES) try {
|
|
@@ -5757,16 +5757,16 @@ var L = class {
|
|
|
5757
5757
|
return e;
|
|
5758
5758
|
}
|
|
5759
5759
|
};
|
|
5760
|
-
function
|
|
5760
|
+
function oe(e) {
|
|
5761
5761
|
return e.KAMA_RUNTIME === "cloudflare" || e.MEDIA_BUCKET ? {
|
|
5762
|
-
storage: new
|
|
5763
|
-
optimizer: new
|
|
5762
|
+
storage: new ie(e.MEDIA_BUCKET, e.CDN_DOMAIN || ""),
|
|
5763
|
+
optimizer: new ae()
|
|
5764
5764
|
} : {
|
|
5765
|
-
storage: new
|
|
5766
|
-
optimizer: new
|
|
5765
|
+
storage: new re(e.LOCAL_MEDIA_PATH),
|
|
5766
|
+
optimizer: new I()
|
|
5767
5767
|
};
|
|
5768
5768
|
}
|
|
5769
|
-
function
|
|
5769
|
+
function se(e) {
|
|
5770
5770
|
if (!e || typeof e != "object") return {
|
|
5771
5771
|
cleanedData: e,
|
|
5772
5772
|
assetRefs: []
|
|
@@ -5825,7 +5825,7 @@ function R(e) {
|
|
|
5825
5825
|
assetRefs: t
|
|
5826
5826
|
};
|
|
5827
5827
|
}
|
|
5828
|
-
async function
|
|
5828
|
+
async function ce(e, t, n) {
|
|
5829
5829
|
if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
5830
5830
|
let r = /* @__PURE__ */ new Set();
|
|
5831
5831
|
for (let i of n) {
|
|
@@ -5833,23 +5833,23 @@ async function oe(e, t, n) {
|
|
|
5833
5833
|
r.has(n) || (r.add(n), await e.prepare("\n INSERT OR IGNORE INTO node_assets (nodeId, assetId, fieldKey, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(t, i.assetId, i.fieldKey, i.sortOrder));
|
|
5834
5834
|
}
|
|
5835
5835
|
}
|
|
5836
|
-
function
|
|
5836
|
+
function L(e) {
|
|
5837
5837
|
if (!e) return null;
|
|
5838
5838
|
if (typeof e == "string" && e.startsWith("ast_")) return e;
|
|
5839
5839
|
if (typeof e == "object" && e) {
|
|
5840
5840
|
if (typeof e.id == "string" && e.id.startsWith("ast_")) return e.id;
|
|
5841
|
-
if (typeof e.id == "object") return
|
|
5841
|
+
if (typeof e.id == "object") return L(e.id);
|
|
5842
5842
|
}
|
|
5843
5843
|
return null;
|
|
5844
5844
|
}
|
|
5845
|
-
async function
|
|
5845
|
+
async function R(e, t) {
|
|
5846
5846
|
if (!t || typeof t != "object") return t;
|
|
5847
5847
|
let n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
5848
5848
|
if (!e) return;
|
|
5849
|
-
let t =
|
|
5849
|
+
let t = L(e);
|
|
5850
5850
|
if (t) {
|
|
5851
5851
|
if (n.add(t), typeof e == "object" && e.parentAssetId) {
|
|
5852
|
-
let t =
|
|
5852
|
+
let t = L(e.parentAssetId);
|
|
5853
5853
|
t && n.add(t);
|
|
5854
5854
|
}
|
|
5855
5855
|
typeof e == "object" && e.variants && Object.values(e.variants).forEach(r);
|
|
@@ -5881,7 +5881,7 @@ async function B(e, t) {
|
|
|
5881
5881
|
AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
|
|
5882
5882
|
`).all(...Array.from(n), ...Array.from(n).map((e) => `%${e}%`)), c = Array.isArray(s) ? s : s?.results || [], l = /* @__PURE__ */ new Map();
|
|
5883
5883
|
for (let e of c) {
|
|
5884
|
-
let t =
|
|
5884
|
+
let t = L(e.parentAssetId) || Array.from(n).find((t) => e.filename.includes(t));
|
|
5885
5885
|
if (!t) continue;
|
|
5886
5886
|
let r = e.filename.match(/^crop_([a-z0-9]+)_/i), i = r ? r[1] : "standard", a = null;
|
|
5887
5887
|
if (e.cropCoordinatesJson) try {
|
|
@@ -5919,7 +5919,7 @@ async function B(e, t) {
|
|
|
5919
5919
|
id: e.id,
|
|
5920
5920
|
url: r,
|
|
5921
5921
|
originalUrl: i,
|
|
5922
|
-
parentAssetId:
|
|
5922
|
+
parentAssetId: L(e.parentAssetId) || null,
|
|
5923
5923
|
cropCoordinates: a,
|
|
5924
5924
|
variants: o && Object.keys(o).length > 0 ? o : void 0,
|
|
5925
5925
|
filename: e.filename,
|
|
@@ -5931,7 +5931,7 @@ async function B(e, t) {
|
|
|
5931
5931
|
}
|
|
5932
5932
|
let d = (e) => {
|
|
5933
5933
|
if (!e) return e;
|
|
5934
|
-
let t =
|
|
5934
|
+
let t = L(e);
|
|
5935
5935
|
if (t) {
|
|
5936
5936
|
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;
|
|
5937
5937
|
if (r || n?.variants) {
|
|
@@ -5942,7 +5942,7 @@ async function B(e, t) {
|
|
|
5942
5942
|
return {
|
|
5943
5943
|
...n || {},
|
|
5944
5944
|
id: t,
|
|
5945
|
-
parentAssetId: n?.parentAssetId ?
|
|
5945
|
+
parentAssetId: n?.parentAssetId ? L(n.parentAssetId) : null,
|
|
5946
5946
|
url: o,
|
|
5947
5947
|
originalUrl: s,
|
|
5948
5948
|
cropCoordinates: i || n?.cropCoordinates || null,
|
|
@@ -5960,7 +5960,7 @@ async function B(e, t) {
|
|
|
5960
5960
|
};
|
|
5961
5961
|
return d(t);
|
|
5962
5962
|
}
|
|
5963
|
-
function
|
|
5963
|
+
function le(e) {
|
|
5964
5964
|
return e ? {
|
|
5965
5965
|
nodes: e.nodes || {},
|
|
5966
5966
|
trees: e.trees || {},
|
|
@@ -5977,7 +5977,7 @@ function se(e) {
|
|
|
5977
5977
|
channels: {}
|
|
5978
5978
|
};
|
|
5979
5979
|
}
|
|
5980
|
-
var
|
|
5980
|
+
var z = class {
|
|
5981
5981
|
env;
|
|
5982
5982
|
constructor(e) {
|
|
5983
5983
|
this.env = e || {};
|
|
@@ -6042,7 +6042,7 @@ var V = class {
|
|
|
6042
6042
|
}
|
|
6043
6043
|
async purgeInternalWorkerCache(e, t, n, r, i) {
|
|
6044
6044
|
try {
|
|
6045
|
-
let a =
|
|
6045
|
+
let a = F(e);
|
|
6046
6046
|
if (n) {
|
|
6047
6047
|
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 || [];
|
|
6048
6048
|
for (let e of i) await a.delete(`tree:default:${e.treeId}`), await a.delete(`tree:all:${e.treeId}`);
|
|
@@ -6185,8 +6185,8 @@ var V = class {
|
|
|
6185
6185
|
console.warn("⚠️ [CacheWarmer] Tree-wide warming failed:", e);
|
|
6186
6186
|
}
|
|
6187
6187
|
}
|
|
6188
|
-
},
|
|
6189
|
-
async function
|
|
6188
|
+
}, B = new e();
|
|
6189
|
+
async function ue(e, t, n = []) {
|
|
6190
6190
|
let r = e.prepare(t);
|
|
6191
6191
|
if (typeof r.bind == "function") {
|
|
6192
6192
|
let e = await r.bind(...n).all();
|
|
@@ -6198,23 +6198,23 @@ async function ce(e, t, n = []) {
|
|
|
6198
6198
|
}
|
|
6199
6199
|
return [];
|
|
6200
6200
|
}
|
|
6201
|
-
async function
|
|
6201
|
+
async function de(e, t, n = []) {
|
|
6202
6202
|
let r = e.prepare(t);
|
|
6203
6203
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
6204
6204
|
if (typeof r.run == "function") return r.run(...n);
|
|
6205
6205
|
}
|
|
6206
|
-
function
|
|
6206
|
+
function fe(e) {
|
|
6207
6207
|
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;
|
|
6208
6208
|
}
|
|
6209
|
-
function
|
|
6209
|
+
function V(e) {
|
|
6210
6210
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6211
6211
|
}
|
|
6212
|
-
function
|
|
6212
|
+
function H(e) {
|
|
6213
6213
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6214
6214
|
let t = Number(e);
|
|
6215
6215
|
return isNaN(t) ? null : t;
|
|
6216
6216
|
}
|
|
6217
|
-
function
|
|
6217
|
+
function pe(e) {
|
|
6218
6218
|
let t = { ...e };
|
|
6219
6219
|
delete t.language, delete t.defaultLanguage;
|
|
6220
6220
|
for (let e of [
|
|
@@ -6243,22 +6243,22 @@ function fe(e) {
|
|
|
6243
6243
|
]) delete t[e];
|
|
6244
6244
|
return t;
|
|
6245
6245
|
}
|
|
6246
|
-
function
|
|
6247
|
-
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) =>
|
|
6246
|
+
function me(e, t = /* @__PURE__ */ new Set()) {
|
|
6247
|
+
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;
|
|
6248
6248
|
}
|
|
6249
|
-
function
|
|
6249
|
+
function he(e, t) {
|
|
6250
6250
|
if (!e) return !0;
|
|
6251
|
-
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 &&
|
|
6251
|
+
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;
|
|
6252
6252
|
return n || r || i || a || c;
|
|
6253
6253
|
}
|
|
6254
|
-
async function
|
|
6254
|
+
async function ge(e, t, n) {
|
|
6255
6255
|
for (let r of n) {
|
|
6256
|
-
let n = (await
|
|
6257
|
-
if (!n || (await
|
|
6256
|
+
let n = (await ue(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
|
|
6257
|
+
if (!n || (await ue(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0) continue;
|
|
6258
6258
|
let i = [n];
|
|
6259
6259
|
if (!n.isSystemVariant) {
|
|
6260
|
-
let t = await
|
|
6261
|
-
if (r.length > 0 && (await
|
|
6260
|
+
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);
|
|
6261
|
+
if (r.length > 0 && (await ue(e, `SELECT DISTINCT assetId FROM node_assets WHERE assetId IN (${r.map(() => "?").join(",")})`, r)).length > 0) continue;
|
|
6262
6262
|
i = [n, ...t];
|
|
6263
6263
|
}
|
|
6264
6264
|
for (let e of i) if (e.storageKeyPrivate) try {
|
|
@@ -6267,10 +6267,10 @@ async function he(e, t, n) {
|
|
|
6267
6267
|
console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
|
|
6268
6268
|
}
|
|
6269
6269
|
let a = i.map((e) => e.id), o = a.map(() => "?").join(",");
|
|
6270
|
-
await
|
|
6270
|
+
await de(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await de(e, `DELETE FROM assets WHERE id IN (${o})`, a);
|
|
6271
6271
|
}
|
|
6272
6272
|
}
|
|
6273
|
-
async function
|
|
6273
|
+
async function _e(e, t, n) {
|
|
6274
6274
|
let r = {}, i = null;
|
|
6275
6275
|
if (t) {
|
|
6276
6276
|
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 || [];
|
|
@@ -6295,7 +6295,7 @@ async function ge(e, t, n) {
|
|
|
6295
6295
|
inheritedFields: r
|
|
6296
6296
|
};
|
|
6297
6297
|
}
|
|
6298
|
-
|
|
6298
|
+
B.get("/", async (e) => {
|
|
6299
6299
|
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));
|
|
6300
6300
|
if (n) {
|
|
6301
6301
|
let r = Number(n);
|
|
@@ -6320,9 +6320,9 @@ H.get("/", async (e) => {
|
|
|
6320
6320
|
updatedAt: i.updatedAt
|
|
6321
6321
|
}, s = i.draftDataJson || i.dataJson;
|
|
6322
6322
|
if (s) try {
|
|
6323
|
-
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 =
|
|
6323
|
+
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;
|
|
6324
6324
|
if (a) {
|
|
6325
|
-
let { resolvedLayoutId: e, inheritedFields: r } = await
|
|
6325
|
+
let { resolvedLayoutId: e, inheritedFields: r } = await _e(t, a.parentId, a.treeId);
|
|
6326
6326
|
(l === "inherit" || !l) && (l = e);
|
|
6327
6327
|
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);
|
|
6328
6328
|
}
|
|
@@ -6337,7 +6337,7 @@ H.get("/", async (e) => {
|
|
|
6337
6337
|
let r = t.allowedLayouts;
|
|
6338
6338
|
return r ? typeof r == "string" ? r === e : !Array.isArray(r) || r.length === 0 || r.includes(e) : !0;
|
|
6339
6339
|
})(l) && (l = null), (l === "inherit" || !l) && (l = c.defaultLayout || null);
|
|
6340
|
-
let u = await
|
|
6340
|
+
let u = await R(t, pe(n));
|
|
6341
6341
|
Object.assign(o, u), o.resolvedLayoutId = l;
|
|
6342
6342
|
} catch {}
|
|
6343
6343
|
let c = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
|
|
@@ -6347,7 +6347,7 @@ H.get("/", async (e) => {
|
|
|
6347
6347
|
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) => {
|
|
6348
6348
|
let n = {};
|
|
6349
6349
|
try {
|
|
6350
|
-
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await
|
|
6350
|
+
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await R(t, n));
|
|
6351
6351
|
} catch {
|
|
6352
6352
|
n = {};
|
|
6353
6353
|
}
|
|
@@ -6435,7 +6435,7 @@ H.get("/", async (e) => {
|
|
|
6435
6435
|
assetCount: e.assetCount || 0
|
|
6436
6436
|
}, i = e.draftDataJson || e.dataJson;
|
|
6437
6437
|
if (i) try {
|
|
6438
|
-
let e = typeof i == "string" ? JSON.parse(i) : i, n = await
|
|
6438
|
+
let e = typeof i == "string" ? JSON.parse(i) : i, n = await R(t, pe(e));
|
|
6439
6439
|
Object.assign(r, n);
|
|
6440
6440
|
} catch {}
|
|
6441
6441
|
return r;
|
|
@@ -6447,8 +6447,8 @@ H.get("/", async (e) => {
|
|
|
6447
6447
|
offset: p,
|
|
6448
6448
|
limit: f
|
|
6449
6449
|
});
|
|
6450
|
-
}),
|
|
6451
|
-
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 } =
|
|
6450
|
+
}), B.post("/", async (e) => {
|
|
6451
|
+
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;
|
|
6452
6452
|
if (T) {
|
|
6453
6453
|
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(T) || -1, String(T));
|
|
6454
6454
|
if (e?.dataJson) try {
|
|
@@ -6470,12 +6470,12 @@ H.get("/", async (e) => {
|
|
|
6470
6470
|
}
|
|
6471
6471
|
}
|
|
6472
6472
|
C && E && C === E && (C = null);
|
|
6473
|
-
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null :
|
|
6473
|
+
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null : fe(s);
|
|
6474
6474
|
if (M) {
|
|
6475
6475
|
let n = [];
|
|
6476
6476
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
6477
6477
|
treeId: Number(e.treeId),
|
|
6478
|
-
parentId:
|
|
6478
|
+
parentId: H(e.parentId ?? e._draftParentId ?? null)
|
|
6479
6479
|
});
|
|
6480
6480
|
else if (a) {
|
|
6481
6481
|
let e = await t.prepare("SELECT treeId, parentId FROM tree_nodes WHERE contentId = ?").all(a), r = Array.isArray(e) ? e : e?.results || [];
|
|
@@ -6502,7 +6502,7 @@ H.get("/", async (e) => {
|
|
|
6502
6502
|
}
|
|
6503
6503
|
if (a) {
|
|
6504
6504
|
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
6505
|
-
k =
|
|
6505
|
+
k = he(e, {
|
|
6506
6506
|
title: o,
|
|
6507
6507
|
slug: M,
|
|
6508
6508
|
isHidden: b,
|
|
@@ -6510,7 +6510,7 @@ H.get("/", async (e) => {
|
|
|
6510
6510
|
});
|
|
6511
6511
|
let n = e?.draftDataJson || e?.dataJson || "{}";
|
|
6512
6512
|
try {
|
|
6513
|
-
|
|
6513
|
+
me(typeof n == "string" ? JSON.parse(n) : n, O);
|
|
6514
6514
|
} catch {}
|
|
6515
6515
|
let r = {};
|
|
6516
6516
|
try {
|
|
@@ -6561,7 +6561,7 @@ H.get("/", async (e) => {
|
|
|
6561
6561
|
}
|
|
6562
6562
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
6563
6563
|
if (!e || !e.treeId) continue;
|
|
6564
|
-
let n = Number(e.treeId) || e.treeId, r =
|
|
6564
|
+
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);
|
|
6565
6565
|
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));
|
|
6566
6566
|
}
|
|
6567
6567
|
let N = [];
|
|
@@ -6569,7 +6569,7 @@ H.get("/", async (e) => {
|
|
|
6569
6569
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
6570
6570
|
let e = [], n = [];
|
|
6571
6571
|
for (let t = 0; t < m.length; t++) {
|
|
6572
|
-
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 } =
|
|
6572
|
+
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({
|
|
6573
6573
|
...a,
|
|
6574
6574
|
blockId: o,
|
|
6575
6575
|
_instanceId: o
|
|
@@ -6585,21 +6585,21 @@ H.get("/", async (e) => {
|
|
|
6585
6585
|
}
|
|
6586
6586
|
if (D) {
|
|
6587
6587
|
let n = [...y, ...N];
|
|
6588
|
-
await
|
|
6588
|
+
await ce(t, D, n);
|
|
6589
6589
|
let r = new Set(n.map((e) => e.assetId)), i = new Set([...O].filter((e) => !r.has(e)));
|
|
6590
6590
|
if (i.size > 0) {
|
|
6591
|
-
let { storage: n } =
|
|
6592
|
-
await
|
|
6591
|
+
let { storage: n } = oe(e.env);
|
|
6592
|
+
await ge(t, n, i);
|
|
6593
6593
|
}
|
|
6594
6594
|
}
|
|
6595
|
-
return await
|
|
6595
|
+
return await F(e).clear(), e.json({
|
|
6596
6596
|
success: !0,
|
|
6597
6597
|
id: D,
|
|
6598
6598
|
status: A,
|
|
6599
6599
|
hasUnpublishedChanges: j === 1 || A === "draft",
|
|
6600
6600
|
isStructuralChange: k
|
|
6601
6601
|
});
|
|
6602
|
-
}),
|
|
6602
|
+
}), B.post("/publish", async (e) => {
|
|
6603
6603
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
6604
6604
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
6605
6605
|
let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
|
|
@@ -6632,7 +6632,7 @@ H.get("/", async (e) => {
|
|
|
6632
6632
|
},
|
|
6633
6633
|
blocks: v
|
|
6634
6634
|
};
|
|
6635
|
-
return await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, y, JSON.stringify(b), a), await
|
|
6635
|
+
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({
|
|
6636
6636
|
success: !0,
|
|
6637
6637
|
id: i,
|
|
6638
6638
|
status: "published",
|
|
@@ -6641,29 +6641,29 @@ H.get("/", async (e) => {
|
|
|
6641
6641
|
hasUnpublishedChanges: !1,
|
|
6642
6642
|
isStructuralChange: h
|
|
6643
6643
|
});
|
|
6644
|
-
}),
|
|
6644
|
+
}), B.delete("/", async (e) => {
|
|
6645
6645
|
let t = e.get("db"), n = e.req.query("id");
|
|
6646
6646
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
6647
6647
|
let r = Number(n);
|
|
6648
|
-
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await
|
|
6648
|
+
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({
|
|
6649
6649
|
success: !0,
|
|
6650
6650
|
deletedNodeId: r
|
|
6651
6651
|
});
|
|
6652
|
-
}),
|
|
6652
|
+
}), B.post("/restore", async (e) => {
|
|
6653
6653
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
6654
|
-
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
|
|
6654
|
+
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({
|
|
6655
6655
|
success: !0,
|
|
6656
6656
|
restoredNodeId: r
|
|
6657
6657
|
})) : e.json({ error: "Node not found" }, 404) : e.json({ error: "Node ID required" }, 400);
|
|
6658
|
-
}),
|
|
6658
|
+
}), B.delete("/purge", async (e) => {
|
|
6659
6659
|
let t = e.get("db"), n = e.req.query("id");
|
|
6660
6660
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
6661
6661
|
let r = Number(n);
|
|
6662
|
-
return new
|
|
6662
|
+
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({
|
|
6663
6663
|
success: !0,
|
|
6664
6664
|
purgedNodeId: r
|
|
6665
6665
|
});
|
|
6666
|
-
}),
|
|
6666
|
+
}), B.get("/:id/revisions", async (e) => {
|
|
6667
6667
|
let t = e.get("db"), n = Number(e.req.param("id"));
|
|
6668
6668
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
6669
6669
|
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) => {
|
|
@@ -6679,7 +6679,7 @@ H.get("/", async (e) => {
|
|
|
6679
6679
|
};
|
|
6680
6680
|
});
|
|
6681
6681
|
return e.json({ revisions: i });
|
|
6682
|
-
}),
|
|
6682
|
+
}), B.get("/:id/revisions/:version", async (e) => {
|
|
6683
6683
|
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);
|
|
6684
6684
|
if (!i) return e.json({ error: "Snapshot not found" }, 404);
|
|
6685
6685
|
let a = {};
|
|
@@ -6689,7 +6689,7 @@ H.get("/", async (e) => {
|
|
|
6689
6689
|
return e.json({ error: "Corrupt snapshot data" }, 500);
|
|
6690
6690
|
}
|
|
6691
6691
|
return e.json({ snapshot: a });
|
|
6692
|
-
}),
|
|
6692
|
+
}), B.post("/:id/revisions/:version/restore", async (e) => {
|
|
6693
6693
|
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);
|
|
6694
6694
|
if (!a) return e.json({ error: "Snapshot not found" }, 404);
|
|
6695
6695
|
let o = {};
|
|
@@ -6703,13 +6703,13 @@ H.get("/", async (e) => {
|
|
|
6703
6703
|
for (let t of o.blocks) e.push("(?, ?, ?, ?, ?, 1)"), r.push(n, t.sortOrder, t.elementType, t.dataJson, t.region || "content");
|
|
6704
6704
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...r);
|
|
6705
6705
|
}
|
|
6706
|
-
return await
|
|
6706
|
+
return await F(e).clear(), e.json({
|
|
6707
6707
|
success: !0,
|
|
6708
6708
|
restoredVersion: r
|
|
6709
6709
|
});
|
|
6710
6710
|
});
|
|
6711
|
-
var
|
|
6712
|
-
function
|
|
6711
|
+
var U = new e();
|
|
6712
|
+
function ve(e, t = null) {
|
|
6713
6713
|
let n = [];
|
|
6714
6714
|
for (let r = 0; r < e.length; r++) {
|
|
6715
6715
|
let i = e[r];
|
|
@@ -6721,19 +6721,19 @@ function _e(e, t = null) {
|
|
|
6721
6721
|
id: o,
|
|
6722
6722
|
parentId: t,
|
|
6723
6723
|
sortOrder: r
|
|
6724
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
6724
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...ve(i.children, o)));
|
|
6725
6725
|
}
|
|
6726
6726
|
return n;
|
|
6727
6727
|
}
|
|
6728
|
-
function
|
|
6728
|
+
function W(e) {
|
|
6729
6729
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
6730
6730
|
let t = Number(e);
|
|
6731
6731
|
return isNaN(t) ? null : t;
|
|
6732
6732
|
}
|
|
6733
|
-
function
|
|
6733
|
+
function G(e) {
|
|
6734
6734
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
6735
6735
|
}
|
|
6736
|
-
|
|
6736
|
+
U.get("/tree.json", async (e) => {
|
|
6737
6737
|
try {
|
|
6738
6738
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
6739
6739
|
if (isNaN(Number(n))) {
|
|
@@ -6786,9 +6786,9 @@ W.get("/tree.json", async (e) => {
|
|
|
6786
6786
|
} catch (t) {
|
|
6787
6787
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
6788
6788
|
}
|
|
6789
|
-
}),
|
|
6789
|
+
}), U.post("/tree.json", async (e) => {
|
|
6790
6790
|
try {
|
|
6791
|
-
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i =
|
|
6791
|
+
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;
|
|
6792
6792
|
if (isNaN(Number(r))) {
|
|
6793
6793
|
let e = await t.prepare("SELECT id FROM trees WHERE key = ?").get(r);
|
|
6794
6794
|
if (e && e.id) o = Number(e.id);
|
|
@@ -6798,7 +6798,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6798
6798
|
}
|
|
6799
6799
|
} else o = Number(r);
|
|
6800
6800
|
if (n.tree && Array.isArray(n.tree)) {
|
|
6801
|
-
let r =
|
|
6801
|
+
let r = ve(n.tree, null);
|
|
6802
6802
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
6803
6803
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
6804
6804
|
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
@@ -6818,9 +6818,9 @@ W.get("/tree.json", async (e) => {
|
|
|
6818
6818
|
reorderedCount: r.length
|
|
6819
6819
|
});
|
|
6820
6820
|
}
|
|
6821
|
-
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 =
|
|
6821
|
+
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);
|
|
6822
6822
|
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;
|
|
6823
|
-
let g =
|
|
6823
|
+
let g = W(u), _ = e.get("user")?.id || null;
|
|
6824
6824
|
if (s === "create") {
|
|
6825
6825
|
let r = m.slug || n.slug || c, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
6826
6826
|
if (a) {
|
|
@@ -6928,7 +6928,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6928
6928
|
details: t.message
|
|
6929
6929
|
}, 500);
|
|
6930
6930
|
}
|
|
6931
|
-
}),
|
|
6931
|
+
}), U.get("/trees.json", async (e) => {
|
|
6932
6932
|
try {
|
|
6933
6933
|
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) => {
|
|
6934
6934
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -6958,7 +6958,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6958
6958
|
} catch {
|
|
6959
6959
|
return e.json([]);
|
|
6960
6960
|
}
|
|
6961
|
-
}),
|
|
6961
|
+
}), U.post("/trees.json", async (e) => {
|
|
6962
6962
|
try {
|
|
6963
6963
|
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 };
|
|
6964
6964
|
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({
|
|
@@ -6983,7 +6983,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6983
6983
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
6984
6984
|
}
|
|
6985
6985
|
}
|
|
6986
|
-
return await
|
|
6986
|
+
return await F(e).clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
6987
6987
|
success: !0,
|
|
6988
6988
|
id: p,
|
|
6989
6989
|
key: o,
|
|
@@ -6997,12 +6997,12 @@ W.get("/tree.json", async (e) => {
|
|
|
6997
6997
|
} catch (t) {
|
|
6998
6998
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
6999
6999
|
}
|
|
7000
|
-
}),
|
|
7000
|
+
}), U.delete("/trees.json", async (e) => {
|
|
7001
7001
|
let t = e.get("db"), n = e.req.query("id");
|
|
7002
7002
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
7003
7003
|
let r = Number(n);
|
|
7004
7004
|
try {
|
|
7005
|
-
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
|
|
7005
|
+
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({
|
|
7006
7006
|
success: !0,
|
|
7007
7007
|
deletedTreeId: r
|
|
7008
7008
|
});
|
|
@@ -7035,7 +7035,7 @@ ye.get("/", async (e) => {
|
|
|
7035
7035
|
isHidden: !!e.isHidden,
|
|
7036
7036
|
trees: a[e.id] || []
|
|
7037
7037
|
};
|
|
7038
|
-
}), s = e.env?.BUNDLED_DEFINITIONS, c =
|
|
7038
|
+
}), s = e.env?.BUNDLED_DEFINITIONS, c = le(s), l = c?.channelTemplate || Object.values(c?.channels || {})[0] || {
|
|
7039
7039
|
label: "Channel Settings",
|
|
7040
7040
|
fields: {
|
|
7041
7041
|
key: {
|
|
@@ -7106,8 +7106,8 @@ ye.get("/", async (e) => {
|
|
|
7106
7106
|
VALUES ${e}
|
|
7107
7107
|
`).run(...n);
|
|
7108
7108
|
}
|
|
7109
|
-
let M =
|
|
7110
|
-
return await M.delete(`channel:${C}`), await M.delete(`channel:${A}`), await M.clear(), new
|
|
7109
|
+
let M = F(e);
|
|
7110
|
+
return await M.delete(`channel:${C}`), await M.delete(`channel:${A}`), await M.clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7111
7111
|
success: !0,
|
|
7112
7112
|
id: A
|
|
7113
7113
|
});
|
|
@@ -7123,8 +7123,8 @@ ye.get("/", async (e) => {
|
|
|
7123
7123
|
let r = Number(n);
|
|
7124
7124
|
try {
|
|
7125
7125
|
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);
|
|
7126
|
-
let n =
|
|
7127
|
-
return await n.delete(`channel:${r}`), await n.clear(), new
|
|
7126
|
+
let n = F(e);
|
|
7127
|
+
return await n.delete(`channel:${r}`), await n.clear(), new z(e.env).purgeGlobalCache(e, t), e.json({
|
|
7128
7128
|
success: !0,
|
|
7129
7129
|
deletedSiteId: r
|
|
7130
7130
|
});
|
|
@@ -7536,7 +7536,7 @@ function je(e) {
|
|
|
7536
7536
|
fields: n
|
|
7537
7537
|
};
|
|
7538
7538
|
});
|
|
7539
|
-
let
|
|
7539
|
+
let te = {};
|
|
7540
7540
|
Object.entries(T).forEach(([e, t]) => {
|
|
7541
7541
|
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { content: { label: "Content" } };
|
|
7542
7542
|
Object.entries(a).forEach(([e, t]) => {
|
|
@@ -7546,7 +7546,7 @@ function je(e) {
|
|
|
7546
7546
|
allowedBlocks: Se(t.allowedBlocks),
|
|
7547
7547
|
disallowedBlocks: t.disallowedBlocks ? Se(t.disallowedBlocks) : void 0
|
|
7548
7548
|
};
|
|
7549
|
-
}),
|
|
7549
|
+
}), te[e] = {
|
|
7550
7550
|
...t,
|
|
7551
7551
|
id: t.id || e,
|
|
7552
7552
|
label: t.label || e,
|
|
@@ -7559,7 +7559,7 @@ function je(e) {
|
|
|
7559
7559
|
tabs: n
|
|
7560
7560
|
};
|
|
7561
7561
|
});
|
|
7562
|
-
let
|
|
7562
|
+
let ne = {};
|
|
7563
7563
|
Object.entries(E).forEach(([e, t]) => {
|
|
7564
7564
|
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { main: { label: "Main Content" } };
|
|
7565
7565
|
Object.entries(a).forEach(([e, t]) => {
|
|
@@ -7569,7 +7569,7 @@ function je(e) {
|
|
|
7569
7569
|
allowedBlocks: Se(t.allowedBlocks),
|
|
7570
7570
|
disallowedBlocks: t.disallowedBlocks ? Se(t.disallowedBlocks) : void 0
|
|
7571
7571
|
};
|
|
7572
|
-
}),
|
|
7572
|
+
}), ne[e] = {
|
|
7573
7573
|
...t,
|
|
7574
7574
|
id: t.id || e,
|
|
7575
7575
|
label: t.label || e,
|
|
@@ -7582,39 +7582,39 @@ function je(e) {
|
|
|
7582
7582
|
tabs: n
|
|
7583
7583
|
};
|
|
7584
7584
|
});
|
|
7585
|
-
let
|
|
7585
|
+
let P = m?.fields || {};
|
|
7586
7586
|
Array.isArray(m?.fieldSets) && m?.fieldSets.forEach((e) => {
|
|
7587
7587
|
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
7588
7588
|
Object.entries(r).forEach(([e, t]) => {
|
|
7589
|
-
|
|
7589
|
+
P[e] = Y(P[e] || {}, t);
|
|
7590
7590
|
});
|
|
7591
7591
|
});
|
|
7592
|
-
let
|
|
7592
|
+
let F = m ? {
|
|
7593
7593
|
...m,
|
|
7594
|
-
fields:
|
|
7595
|
-
} : null,
|
|
7594
|
+
fields: P
|
|
7595
|
+
} : null, re = h?.fields || {};
|
|
7596
7596
|
Array.isArray(h?.fieldSets) && h?.fieldSets.forEach((e) => {
|
|
7597
7597
|
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
7598
7598
|
Object.entries(r).forEach(([e, t]) => {
|
|
7599
|
-
|
|
7599
|
+
re[e] = Y(re[e] || {}, t);
|
|
7600
7600
|
});
|
|
7601
7601
|
});
|
|
7602
|
-
let
|
|
7602
|
+
let I = h ? {
|
|
7603
7603
|
...h,
|
|
7604
|
-
fields:
|
|
7604
|
+
fields: re
|
|
7605
7605
|
} : null;
|
|
7606
7606
|
return {
|
|
7607
7607
|
nodes: j,
|
|
7608
7608
|
trees: M,
|
|
7609
7609
|
channels: N,
|
|
7610
7610
|
blocks: ee,
|
|
7611
|
-
nodeLayouts:
|
|
7612
|
-
blockLayouts:
|
|
7611
|
+
nodeLayouts: te,
|
|
7612
|
+
blockLayouts: ne,
|
|
7613
7613
|
fieldSets: O,
|
|
7614
7614
|
nodeTemplate: f || null,
|
|
7615
7615
|
treeTemplate: p || null,
|
|
7616
|
-
channelTemplate:
|
|
7617
|
-
userTemplate:
|
|
7616
|
+
channelTemplate: F,
|
|
7617
|
+
userTemplate: I
|
|
7618
7618
|
};
|
|
7619
7619
|
}
|
|
7620
7620
|
var Me = new e(), Ne = (e) => {
|
|
@@ -7735,7 +7735,7 @@ Le.get("/", async (e) => {
|
|
|
7735
7735
|
isHidden: !!e.isHidden,
|
|
7736
7736
|
channelNames: e.channelLabels ? e.channelLabels.split(",") : [],
|
|
7737
7737
|
treeNames: e.treeLabels ? e.treeLabels.split(",") : []
|
|
7738
|
-
})), p = e.env?.BUNDLED_DEFINITIONS, m =
|
|
7738
|
+
})), p = e.env?.BUNDLED_DEFINITIONS, m = le(p), h = m.nodes || m.nodeSchemas || {}, g = c.map((e) => {
|
|
7739
7739
|
let t = e.type || "node", n = h[t]?.label || t.charAt(0).toUpperCase() + t.slice(1);
|
|
7740
7740
|
return {
|
|
7741
7741
|
type: t,
|
|
@@ -7863,7 +7863,7 @@ X.get("/", async (e) => {
|
|
|
7863
7863
|
}
|
|
7864
7864
|
}), X.post("/upload", async (e) => {
|
|
7865
7865
|
try {
|
|
7866
|
-
let t = l(e), { storage: n } =
|
|
7866
|
+
let t = l(e), { storage: n } = oe(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;
|
|
7867
7867
|
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
7868
7868
|
let d = r.cropCoordinates, f = null, p = null;
|
|
7869
7869
|
if (d) {
|
|
@@ -7878,7 +7878,7 @@ X.get("/", async (e) => {
|
|
|
7878
7878
|
if (!y) throw Error("Storage provider failed to return a valid storage key");
|
|
7879
7879
|
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;
|
|
7880
7880
|
E && (await Z(t, "SELECT id FROM users WHERE id = ?", [E])).length === 0 && (E = null);
|
|
7881
|
-
let D = new
|
|
7881
|
+
let D = new z(e.env);
|
|
7882
7882
|
if (s) {
|
|
7883
7883
|
let r = await Z(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
7884
7884
|
if (r.length > 0) {
|
|
@@ -8009,14 +8009,14 @@ X.get("/", async (e) => {
|
|
|
8009
8009
|
r.filename === void 0 ? a.filename : r.filename,
|
|
8010
8010
|
JSON.stringify(o),
|
|
8011
8011
|
n
|
|
8012
|
-
]), new
|
|
8012
|
+
]), new z(e.env).purgeAsset(e, t, n), e.json({ success: !0 });
|
|
8013
8013
|
} catch {
|
|
8014
8014
|
return e.json({ error: "Failed to update asset" }, 500);
|
|
8015
8015
|
}
|
|
8016
8016
|
}), X.delete("/:id", async (e) => {
|
|
8017
8017
|
try {
|
|
8018
8018
|
let t = l(e), n = e.req.param("id"), r = (await Z(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
8019
|
-
return r ? (new
|
|
8019
|
+
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({
|
|
8020
8020
|
success: !0,
|
|
8021
8021
|
id: n,
|
|
8022
8022
|
trashed: !0
|
|
@@ -8030,7 +8030,7 @@ X.get("/", async (e) => {
|
|
|
8030
8030
|
}), X.post("/restore", async (e) => {
|
|
8031
8031
|
try {
|
|
8032
8032
|
let t = l(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
8033
|
-
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
|
|
8033
|
+
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({
|
|
8034
8034
|
success: !0,
|
|
8035
8035
|
id: r,
|
|
8036
8036
|
restored: !0
|
|
@@ -8043,9 +8043,9 @@ X.get("/", async (e) => {
|
|
|
8043
8043
|
}
|
|
8044
8044
|
}), X.delete("/purge/:id", async (e) => {
|
|
8045
8045
|
try {
|
|
8046
|
-
let t = l(e), { storage: n } =
|
|
8046
|
+
let t = l(e), { storage: n } = oe(e.env), r = e.req.param("id"), i = (await Z(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
8047
8047
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
8048
|
-
new
|
|
8048
|
+
new z(e.env).purgeAsset(e, t, r);
|
|
8049
8049
|
let a = [i];
|
|
8050
8050
|
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
8051
8051
|
let o = a.map((e) => e.id);
|
|
@@ -8167,7 +8167,7 @@ async function We(e, t, n, r, i, a = !1, o) {
|
|
|
8167
8167
|
let o = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = He(n.startShowingAt, n.stopShowingAt);
|
|
8168
8168
|
if (!a && (o || !s)) return null;
|
|
8169
8169
|
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);
|
|
8170
|
-
return d = await
|
|
8170
|
+
return d = await R(e, d), d = Ke(d), d.blockId = u, {
|
|
8171
8171
|
region: t.region || r,
|
|
8172
8172
|
block: {
|
|
8173
8173
|
instanceId: t.id,
|
|
@@ -8415,85 +8415,94 @@ async function nt(e, t, n, r) {
|
|
|
8415
8415
|
}
|
|
8416
8416
|
ze.get("/*", async (e) => {
|
|
8417
8417
|
try {
|
|
8418
|
-
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));
|
|
8419
|
-
if (!
|
|
8420
|
-
let
|
|
8421
|
-
if (!s &&
|
|
8422
|
-
let
|
|
8418
|
+
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));
|
|
8419
|
+
if (!l) return e.json({ error: `Channel '${a}' not found` }, 404);
|
|
8420
|
+
let u = l.status === "disabled" || l.status === "inactive" || l.isEnabled === 0 || l.isEnabled === !1;
|
|
8421
|
+
if (!s && u) return e.json({ error: `Channel '${l.key || a}' is currently inactive` }, 404);
|
|
8422
|
+
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 = `
|
|
8423
8423
|
SELECT cn.*, tn.contentId as treeNodeId, tn.parentId, tn.treeId FROM content_nodes cn
|
|
8424
8424
|
INNER JOIN tree_nodes tn ON cn.id = tn.contentId
|
|
8425
|
-
${
|
|
8426
|
-
WHERE cn.slug = ? ${
|
|
8427
|
-
`,
|
|
8428
|
-
if (
|
|
8429
|
-
let e = await Promise.all(
|
|
8425
|
+
${d === null ? "" : "INNER JOIN node_channels nc ON cn.id = nc.nodeId"}
|
|
8426
|
+
WHERE cn.slug = ? ${d === null ? "" : "AND nc.channelId = ?"}
|
|
8427
|
+
`, C = d === null ? [b] : [b, d], w = await t.prepare(S).all(...C), T = Array.isArray(w) ? w : w?.results || [];
|
|
8428
|
+
if (T.length > 0) {
|
|
8429
|
+
let e = await Promise.all(T.map(async (e) => ({
|
|
8430
8430
|
candidate: e,
|
|
8431
8431
|
calculatedPath: await $e(t, String(e.treeNodeId), String(e.treeId), n)
|
|
8432
|
-
}))), r =
|
|
8432
|
+
}))), r = x.replace(/^\/+|\/+$/g, "");
|
|
8433
8433
|
for (let { candidate: t, calculatedPath: n } of e) {
|
|
8434
8434
|
let e = n.replace(/^\/+|\/+$/g, "");
|
|
8435
8435
|
if (e === r || r === "home" && (e === "" || e === "home")) {
|
|
8436
|
-
|
|
8436
|
+
g = t, _ = t;
|
|
8437
8437
|
break;
|
|
8438
8438
|
}
|
|
8439
8439
|
}
|
|
8440
8440
|
}
|
|
8441
|
-
if (!
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8441
|
+
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);
|
|
8442
|
+
let E = null;
|
|
8443
|
+
if (c) {
|
|
8444
|
+
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(g.id, Number(c));
|
|
8445
|
+
if (e && e.snapshotJson) try {
|
|
8446
|
+
E = JSON.parse(e.snapshotJson), E.node && (E.node.title && (g.title = E.node.title), E.node.slug && (g.slug = E.node.slug));
|
|
8447
|
+
} catch (e) {
|
|
8448
|
+
console.error("[CMS] Failed to parse snapshotJson", e);
|
|
8449
|
+
}
|
|
8450
|
+
}
|
|
8451
|
+
if (!_) {
|
|
8452
|
+
let e = v ? [g.id, v] : [g.id];
|
|
8453
|
+
_ = await t.prepare(`SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${v ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
|
|
8445
8454
|
}
|
|
8446
|
-
let
|
|
8447
|
-
if (
|
|
8448
|
-
let e = await t.prepare("\n SELECT dataJson \n FROM trees \n WHERE id = ? OR key = ? \n LIMIT 1\n ").get(Number(
|
|
8455
|
+
let D = _?.treeId || v || "main-nav", O = null;
|
|
8456
|
+
if (D) {
|
|
8457
|
+
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));
|
|
8449
8458
|
if (e?.dataJson) try {
|
|
8450
8459
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
8451
|
-
t.defaultLanguage ?
|
|
8460
|
+
t.defaultLanguage ? O = String(t.defaultLanguage).trim() : t.language && (O = String(t.language).trim());
|
|
8452
8461
|
} catch {}
|
|
8453
8462
|
}
|
|
8454
|
-
let
|
|
8455
|
-
if (
|
|
8456
|
-
if (
|
|
8457
|
-
else if (
|
|
8458
|
-
let e = typeof
|
|
8459
|
-
e.defaultLanguage ?
|
|
8463
|
+
let k = null;
|
|
8464
|
+
if (l) {
|
|
8465
|
+
if (l.defaultLanguage) k = String(l.defaultLanguage).trim();
|
|
8466
|
+
else if (l.dataJson) try {
|
|
8467
|
+
let e = typeof l.dataJson == "string" ? JSON.parse(l.dataJson) : l.dataJson;
|
|
8468
|
+
e.defaultLanguage ? k = String(e.defaultLanguage).trim() : e.language && (k = String(e.language).trim());
|
|
8460
8469
|
} catch {}
|
|
8461
8470
|
}
|
|
8462
|
-
let
|
|
8463
|
-
if (!s && !
|
|
8464
|
-
let t = await
|
|
8471
|
+
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;
|
|
8472
|
+
if (!s && !ee) {
|
|
8473
|
+
let t = await p.get(N);
|
|
8465
8474
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
8466
8475
|
}
|
|
8467
|
-
let
|
|
8468
|
-
id:
|
|
8469
|
-
title:
|
|
8470
|
-
slug:
|
|
8471
|
-
language:
|
|
8472
|
-
path:
|
|
8473
|
-
nodeType:
|
|
8474
|
-
createdAt:
|
|
8475
|
-
updatedAt:
|
|
8476
|
-
},
|
|
8477
|
-
|
|
8478
|
-
Object.assign(
|
|
8476
|
+
let te = _?.parentId || null, ne = _?.treeNodeId ? await $e(t, String(_.treeNodeId), String(D), n) : `/${(g.slug || "").replace(/^\/+|\/+$/g, "")}`, P = {
|
|
8477
|
+
id: g.id,
|
|
8478
|
+
title: g.title,
|
|
8479
|
+
slug: g.slug,
|
|
8480
|
+
language: M,
|
|
8481
|
+
path: ne === "" ? "/" : ne,
|
|
8482
|
+
nodeType: g.contentType,
|
|
8483
|
+
createdAt: g.createdAt,
|
|
8484
|
+
updatedAt: g.updatedAt
|
|
8485
|
+
}, re = g.contentType || "node", I = m.nodes?.[re] || Object.values(m.nodes || {})[0] || {}, ie = { ...I.fields || {} };
|
|
8486
|
+
I.tabs && Object.values(I.tabs).forEach((e) => {
|
|
8487
|
+
Object.assign(ie, e.fields || {});
|
|
8479
8488
|
});
|
|
8480
|
-
let
|
|
8481
|
-
if (
|
|
8482
|
-
|
|
8489
|
+
let ae = {}, oe = null, se = null, ce = !1, L = {}, z = s && g.draftDataJson || g.dataJson;
|
|
8490
|
+
if (E && E.node && E.node.dataJson && (z = E.node.dataJson), z) try {
|
|
8491
|
+
L = typeof z == "string" ? JSON.parse(z) : z;
|
|
8483
8492
|
} catch {}
|
|
8484
|
-
|
|
8485
|
-
let
|
|
8486
|
-
for (let [e, t] of Object.entries(
|
|
8487
|
-
let
|
|
8488
|
-
|
|
8489
|
-
let
|
|
8490
|
-
delete
|
|
8491
|
-
let
|
|
8492
|
-
if (!s && (
|
|
8493
|
-
let
|
|
8494
|
-
if (
|
|
8495
|
-
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(
|
|
8496
|
-
|
|
8493
|
+
L.disabledRegions && (ae = L.disabledRegions), ce = L.hidden === !0 || L.hidden === 1 || L.hidden === "1" || L.hidden === "true", oe = L.startShowingAt || null, se = L.stopShowingAt || null;
|
|
8494
|
+
let B = L.layoutId, ue = B && B !== "inherit", { resolvedLayoutId: de, inheritedFields: fe } = await et(t, te, D, s, ie), V = ue ? B : de || I.defaultLayout || null;
|
|
8495
|
+
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);
|
|
8496
|
+
let H = await R(t, Ge(L, ie));
|
|
8497
|
+
H = Ke(H), H = await qe(t, H, n), delete H.language;
|
|
8498
|
+
let pe = Qe(H);
|
|
8499
|
+
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;
|
|
8500
|
+
let me = Number(g.isHidden) === 1 || ce, he = !He(oe, se), ge = g.status === "draft" || g.status === "new", _e = g.dataJson && g.dataJson !== "{}" && g.dataJson !== "null";
|
|
8501
|
+
if (!s && (me || he || ge && !_e)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
8502
|
+
let U = [];
|
|
8503
|
+
if (_?.treeNodeId) {
|
|
8504
|
+
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;
|
|
8505
|
+
U = n.map((e) => {
|
|
8497
8506
|
let t = {}, n = s && e.draftDataJson || e.dataJson;
|
|
8498
8507
|
if (!n) return null;
|
|
8499
8508
|
try {
|
|
@@ -8505,22 +8514,31 @@ ze.get("/*", async (e) => {
|
|
|
8505
8514
|
id: e.id,
|
|
8506
8515
|
title: e.title,
|
|
8507
8516
|
slug: o,
|
|
8508
|
-
language: e.language?.trim() ||
|
|
8517
|
+
language: e.language?.trim() || M || null,
|
|
8509
8518
|
path: `${r}/${o}`.replace(/\/+/g, "/"),
|
|
8510
8519
|
nodeType: e.nodeType
|
|
8511
8520
|
};
|
|
8512
8521
|
}).filter(Boolean);
|
|
8513
8522
|
}
|
|
8514
|
-
P.children =
|
|
8515
|
-
let
|
|
8523
|
+
P.children = U;
|
|
8524
|
+
let ve = [];
|
|
8525
|
+
if (E && E.blocks && Array.isArray(E.blocks)) ve = E.blocks.map((e) => ({
|
|
8526
|
+
...e,
|
|
8527
|
+
isDraft: 1
|
|
8528
|
+
}));
|
|
8529
|
+
else {
|
|
8530
|
+
let e = +!!s, n = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(g.id, e);
|
|
8531
|
+
ve = Array.isArray(n) ? n : n?.results || [];
|
|
8532
|
+
}
|
|
8533
|
+
let W = {}, G = {}, ye = await Promise.all(ve.map(async (e) => {
|
|
8516
8534
|
let r = e.region || "main", i = {};
|
|
8517
8535
|
try {
|
|
8518
8536
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
8519
8537
|
} catch {}
|
|
8520
8538
|
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", o = He(i.startShowingAt, i.stopShowingAt);
|
|
8521
8539
|
if (!s && (a || !o)) return null;
|
|
8522
|
-
let c = e.elementType || e.componentId || "text-block", l =
|
|
8523
|
-
return d = await
|
|
8540
|
+
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);
|
|
8541
|
+
return d = await R(t, d), d = Ke(d), d = await qe(t, d, n), d.blockId = u, {
|
|
8524
8542
|
region: r,
|
|
8525
8543
|
block: {
|
|
8526
8544
|
instanceId: e.id,
|
|
@@ -8530,7 +8548,7 @@ ze.get("/*", async (e) => {
|
|
|
8530
8548
|
}
|
|
8531
8549
|
};
|
|
8532
8550
|
}));
|
|
8533
|
-
for (let e of ye) e && (
|
|
8551
|
+
for (let e of ye) e && (W[e.region] || (W[e.region] = [], G[e.region] = { isInherited: !1 }), W[e.region].push(e.block));
|
|
8534
8552
|
let K = {
|
|
8535
8553
|
header: {
|
|
8536
8554
|
label: "Header",
|
|
@@ -8540,33 +8558,33 @@ ze.get("/*", async (e) => {
|
|
|
8540
8558
|
label: "Footer",
|
|
8541
8559
|
inherit: "parent"
|
|
8542
8560
|
},
|
|
8543
|
-
...(
|
|
8561
|
+
...(V ? m.nodeLayouts?.[V] || m.layouts?.[V] : null)?.regions || { main: { label: "Content" } }
|
|
8544
8562
|
};
|
|
8545
8563
|
for (let [e, r] of Object.entries(K)) {
|
|
8546
|
-
let i =
|
|
8547
|
-
if (
|
|
8548
|
-
let r = await We(t,
|
|
8549
|
-
if (r.blocks.length > 0 && (
|
|
8564
|
+
let i = W[e] && W[e].length > 0, a = !!ae[e];
|
|
8565
|
+
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) {
|
|
8566
|
+
let r = await We(t, te, String(D), e, m, s, n);
|
|
8567
|
+
if (r.blocks.length > 0 && (W[e] = r.blocks, G[e] = {
|
|
8550
8568
|
isInherited: !0,
|
|
8551
8569
|
inheritedFromId: r.inheritedFromId,
|
|
8552
8570
|
inheritedFromTitle: r.inheritedFromTitle
|
|
8553
|
-
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (
|
|
8571
|
+
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (W[t] = n, G[t] = {
|
|
8554
8572
|
isInherited: !0,
|
|
8555
8573
|
inheritedFromId: r.inheritedFromId,
|
|
8556
8574
|
inheritedFromTitle: r.inheritedFromTitle
|
|
8557
8575
|
});
|
|
8558
8576
|
}
|
|
8559
8577
|
}
|
|
8560
|
-
await Promise.all(Object.keys(
|
|
8578
|
+
await Promise.all(Object.keys(W).map((e) => Ue(t, W[e], d, M)));
|
|
8561
8579
|
let q = {
|
|
8562
|
-
channelId:
|
|
8563
|
-
treeId:
|
|
8564
|
-
language:
|
|
8580
|
+
channelId: d || f,
|
|
8581
|
+
treeId: D,
|
|
8582
|
+
language: M,
|
|
8565
8583
|
node: P,
|
|
8566
|
-
content:
|
|
8567
|
-
regionMeta:
|
|
8584
|
+
content: W,
|
|
8585
|
+
regionMeta: G
|
|
8568
8586
|
};
|
|
8569
|
-
return !s && !
|
|
8587
|
+
return !s && !ee && (e.header("X-Cache", "MISS"), await nt(p, N, q, tt(e))), e.json(q);
|
|
8570
8588
|
} catch (t) {
|
|
8571
8589
|
return console.error("[CMS Public API] Error fetching node by path:", t), e.json({
|
|
8572
8590
|
error: "Failed to fetch JSON payload",
|
|
@@ -8615,14 +8633,14 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8615
8633
|
e.defaultLanguage && (l = String(e.defaultLanguage).trim());
|
|
8616
8634
|
} catch {}
|
|
8617
8635
|
}
|
|
8618
|
-
let u = l || o || i?.trim() || null, d =
|
|
8636
|
+
let u = l || o || i?.trim() || null, d = F(e), f = `tree:${r}:${n}:${u || "default"}`, p = e.req.header("x-bypass-cache") === "true";
|
|
8619
8637
|
if (!a && !p) {
|
|
8620
8638
|
let t = await d.get(f);
|
|
8621
8639
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
8622
8640
|
}
|
|
8623
8641
|
let m = c?.id || (s ? Number(n) : null), h = {};
|
|
8624
8642
|
if (c && c.dataJson) try {
|
|
8625
|
-
let t = typeof c.dataJson == "string" ? JSON.parse(c.dataJson) : c.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i =
|
|
8643
|
+
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 || {};
|
|
8626
8644
|
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (h[e] = n);
|
|
8627
8645
|
} catch (e) {
|
|
8628
8646
|
console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
|
|
@@ -8795,7 +8813,7 @@ async function ft(e, t) {
|
|
|
8795
8813
|
}
|
|
8796
8814
|
ot.get("/:channelParam", async (e) => {
|
|
8797
8815
|
try {
|
|
8798
|
-
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 =
|
|
8816
|
+
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);
|
|
8799
8817
|
if (!r && !i) {
|
|
8800
8818
|
let t = await o.get(a);
|
|
8801
8819
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
@@ -8804,7 +8822,7 @@ ot.get("/:channelParam", async (e) => {
|
|
|
8804
8822
|
if (!s) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
8805
8823
|
let c = s.status === "disabled" || s.status === "inactive" || s.isEnabled === 0 || s.isEnabled === !1;
|
|
8806
8824
|
if (!r && c) return e.json({ error: `Channel '${s.key || n}' is currently inactive` }, 404);
|
|
8807
|
-
let l = e.env?.BUNDLED_DEFINITIONS, u =
|
|
8825
|
+
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;
|
|
8808
8826
|
if (m) try {
|
|
8809
8827
|
p = typeof m == "string" ? JSON.parse(m) : m;
|
|
8810
8828
|
} catch (e) {
|
|
@@ -8814,7 +8832,7 @@ ot.get("/:channelParam", async (e) => {
|
|
|
8814
8832
|
...p,
|
|
8815
8833
|
...s
|
|
8816
8834
|
}, f);
|
|
8817
|
-
h = await
|
|
8835
|
+
h = await R(t, h), h = dt(h), h = await ft(t, h);
|
|
8818
8836
|
let g = {
|
|
8819
8837
|
id: s.id,
|
|
8820
8838
|
key: s.key,
|
|
@@ -8853,7 +8871,7 @@ pt.get("/*", async (e) => {
|
|
|
8853
8871
|
let e = await l.match(d);
|
|
8854
8872
|
if (e) return e;
|
|
8855
8873
|
}
|
|
8856
|
-
let { storage: f, optimizer: p } =
|
|
8874
|
+
let { storage: f, optimizer: p } = oe(e.env), m = await f.get(t);
|
|
8857
8875
|
if (!m) return e.text(`Asset not found: ${t}`, 404);
|
|
8858
8876
|
if (!o) {
|
|
8859
8877
|
let n = e.body(m, 200, {
|
|
@@ -8959,7 +8977,7 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
8959
8977
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
8960
8978
|
}
|
|
8961
8979
|
await t();
|
|
8962
|
-
}), $.route("/media", pt), $.use("/media/*", y()), $.route("/api/cms/nodes",
|
|
8980
|
+
}), $.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) => {
|
|
8963
8981
|
if (e.env?.ASSETS) {
|
|
8964
8982
|
let t = await e.env.ASSETS.fetch(e.req.raw);
|
|
8965
8983
|
if (t.status === 404) {
|