@brightsideoy/kama 0.1.0-alpha.162 → 0.1.0-alpha.164
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-DNasJfw-.js +164 -0
- package/dist/assets/index-jMWDExiG.css +1 -0
- package/dist/{dist-V9vwVhix.js → dist-DkBY_SfG.js} +259 -197
- package/dist/index.html +2 -2
- package/dist/index.js +259 -197
- package/dist/schema-compiler.js +1 -1
- package/package.json +1 -1
- package/schema.sql +2 -2
- package/dist/assets/index-C5TmJVER.css +0 -1
- package/dist/assets/index-D7WfJ4cB.js +0 -164
package/dist/index.js
CHANGED
|
@@ -4787,7 +4787,7 @@ var u = /* @__PURE__ */ o({
|
|
|
4787
4787
|
channel_trees: "\n channelId INTEGER NOT NULL,\n treeId INTEGER NOT NULL,\n key TEXT NOT NULL DEFAULT 'main',\n metaJson TEXT,\n PRIMARY KEY (channelId, treeId, key),\n FOREIGN KEY (channelId) REFERENCES channels(id) ON DELETE CASCADE,\n FOREIGN KEY (treeId) REFERENCES trees(id) ON DELETE CASCADE\n ",
|
|
4788
4788
|
content_nodes: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n contentType TEXT NOT NULL,\n title TEXT NOT NULL,\n slug TEXT,\n language TEXT,\n isHidden INTEGER NOT NULL DEFAULT 0,\n status TEXT DEFAULT 'draft',\n hasUnpublishedChanges INTEGER DEFAULT 0,\n disabledRegionsJson TEXT DEFAULT '{}',\n dataJson TEXT,\n draftDataJson TEXT,\n publishedDataJson TEXT,\n publishedAt TEXT,\n createdById TEXT,\n updatedById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n deletedAt TEXT,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL,\n FOREIGN KEY (updatedById) REFERENCES users(id) ON DELETE SET NULL\n ",
|
|
4789
4789
|
node_channels: "\n nodeId INTEGER NOT NULL,\n channelId INTEGER NOT NULL,\n PRIMARY KEY (nodeId, channelId),\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (channelId) REFERENCES channels(id) ON DELETE CASCADE\n ",
|
|
4790
|
-
tree_nodes: "\n
|
|
4790
|
+
tree_nodes: "\n treeId INTEGER NOT NULL,\n contentId INTEGER NOT NULL,\n parentId INTEGER,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (treeId, contentId),\n FOREIGN KEY (treeId) REFERENCES trees(id) ON DELETE CASCADE,\n FOREIGN KEY (contentId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (parentId) REFERENCES content_nodes(id) ON DELETE CASCADE\n ",
|
|
4791
4791
|
content_blocks: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n contentId INTEGER NOT NULL,\n region TEXT DEFAULT 'main',\n elementType TEXT NOT NULL,\n dataJson TEXT,\n sortOrder INTEGER DEFAULT 0,\n isDraft INTEGER NOT NULL DEFAULT 1,\n FOREIGN KEY (contentId) REFERENCES content_nodes(id) ON DELETE CASCADE\n ",
|
|
4792
4792
|
node_revisions: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n nodeId INTEGER NOT NULL,\n version INTEGER NOT NULL DEFAULT 1,\n snapshotJson TEXT NOT NULL,\n createdById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL\n ",
|
|
4793
4793
|
assets: "\n id TEXT PRIMARY KEY,\n filename TEXT NOT NULL,\n mimeType TEXT NOT NULL,\n sizeBytes INTEGER NOT NULL,\n storageKeyPrivate TEXT,\n cdnUrl TEXT,\n parentAssetId TEXT,\n cropCoordinatesJson TEXT,\n isSystemVariant INTEGER DEFAULT 0,\n dataJson TEXT DEFAULT '{}',\n createdById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n deletedAt TEXT,\n FOREIGN KEY (parentAssetId) REFERENCES assets(id) ON DELETE SET NULL,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL\n ",
|
|
@@ -4832,6 +4832,14 @@ async function _(e, t) {
|
|
|
4832
4832
|
await e.prepare("ALTER TABLE \"assets\" ADD COLUMN cropCoordinatesJson TEXT;").run();
|
|
4833
4833
|
} catch {}
|
|
4834
4834
|
}
|
|
4835
|
+
if (t === "tree_nodes" && n.has("id")) {
|
|
4836
|
+
console.log("[Schema Sync] Migrating tree_nodes to Content-to-Content hierarchy...");
|
|
4837
|
+
try {
|
|
4838
|
+
await e.prepare("\n CREATE TABLE \"tree_nodes_new\" (\n treeId INTEGER NOT NULL,\n contentId INTEGER NOT NULL,\n parentId INTEGER,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (treeId, contentId),\n FOREIGN KEY (treeId) REFERENCES trees(id) ON DELETE CASCADE,\n FOREIGN KEY (contentId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (parentId) REFERENCES content_nodes(id) ON DELETE CASCADE\n )\n ").run(), await e.prepare("\n INSERT OR IGNORE INTO tree_nodes_new (treeId, contentId, parentId, sortOrder)\n SELECT t1.treeId, t1.contentId, t2.contentId as parentId, t1.sortOrder\n FROM tree_nodes t1\n LEFT JOIN tree_nodes t2 ON t1.parentId = t2.id\n ").run(), await e.prepare("DROP TABLE \"tree_nodes\"").run(), await e.prepare("ALTER TABLE \"tree_nodes_new\" RENAME TO \"tree_nodes\"").run(), console.log("[Schema Sync] Tree migration complete.");
|
|
4839
|
+
} catch (e) {
|
|
4840
|
+
console.error("[Schema Sync] Failed to migrate tree_nodes schema:", e);
|
|
4841
|
+
}
|
|
4842
|
+
}
|
|
4835
4843
|
}
|
|
4836
4844
|
}
|
|
4837
4845
|
for (let t of m) try {
|
|
@@ -5858,6 +5866,7 @@ async function B(e, t) {
|
|
|
5858
5866
|
let t = z(e.parentAssetId);
|
|
5859
5867
|
t && n.add(t);
|
|
5860
5868
|
}
|
|
5869
|
+
typeof e == "object" && e.variants && Object.values(e.variants).forEach(r);
|
|
5861
5870
|
} else Array.isArray(e) ? e.forEach(r) : typeof e == "object" && Object.values(e).forEach(r);
|
|
5862
5871
|
};
|
|
5863
5872
|
if (r(t), n.size === 0) return t;
|
|
@@ -5871,14 +5880,16 @@ async function B(e, t) {
|
|
|
5871
5880
|
a.parentAssetId,
|
|
5872
5881
|
a.cropCoordinatesJson,
|
|
5873
5882
|
a.dataJson,
|
|
5883
|
+
a.updatedAt,
|
|
5874
5884
|
p.cdnUrl AS parentCdnUrl,
|
|
5875
5885
|
p.storageKeyPrivate AS parentStorageKeyPrivate,
|
|
5876
|
-
p.dataJson AS parentDataJson
|
|
5886
|
+
p.dataJson AS parentDataJson,
|
|
5887
|
+
p.updatedAt AS parentUpdatedAt
|
|
5877
5888
|
FROM assets a
|
|
5878
5889
|
LEFT JOIN assets p ON a.parentAssetId = p.id
|
|
5879
5890
|
WHERE a.id IN (${i})
|
|
5880
5891
|
`).all(...Array.from(n)), o = Array.isArray(a) ? a : a?.results || [], s = await e.prepare(`
|
|
5881
|
-
SELECT id, cdnUrl, storageKeyPrivate, filename, parentAssetId, cropCoordinatesJson, dataJson
|
|
5892
|
+
SELECT id, cdnUrl, storageKeyPrivate, filename, parentAssetId, cropCoordinatesJson, dataJson, updatedAt
|
|
5882
5893
|
FROM assets
|
|
5883
5894
|
WHERE isSystemVariant = 1
|
|
5884
5895
|
AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
|
|
@@ -5890,62 +5901,66 @@ async function B(e, t) {
|
|
|
5890
5901
|
if (e.cropCoordinatesJson) try {
|
|
5891
5902
|
a = typeof e.cropCoordinatesJson == "string" ? JSON.parse(e.cropCoordinatesJson) : e.cropCoordinatesJson;
|
|
5892
5903
|
} catch {}
|
|
5893
|
-
let o = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : "");
|
|
5904
|
+
let o = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""), s = e.updatedAt ? new Date(e.updatedAt).getTime() : Date.now(), c = o ? `${o}?v=${s}` : "";
|
|
5894
5905
|
l.has(t) || l.set(t, {}), l.get(t)[i] = {
|
|
5895
5906
|
id: e.id,
|
|
5896
|
-
url:
|
|
5907
|
+
url: c,
|
|
5897
5908
|
cropCoordinates: a
|
|
5898
5909
|
};
|
|
5899
5910
|
}
|
|
5900
5911
|
let u = /* @__PURE__ */ new Map();
|
|
5901
5912
|
for (let e of o) {
|
|
5902
|
-
let t = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""), n =
|
|
5903
|
-
e.parentAssetId && (e.parentCdnUrl || e.parentStorageKeyPrivate)
|
|
5904
|
-
|
|
5913
|
+
let t = e.updatedAt ? new Date(e.updatedAt).getTime() : Date.now(), n = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""), r = n ? `${n}?v=${t}` : "", i = r;
|
|
5914
|
+
if (e.parentAssetId && (e.parentCdnUrl || e.parentStorageKeyPrivate)) {
|
|
5915
|
+
let n = e.parentUpdatedAt ? new Date(e.parentUpdatedAt).getTime() : t;
|
|
5916
|
+
i = `${e.parentCdnUrl || `/media/${e.parentStorageKeyPrivate}`}?v=${n}`;
|
|
5917
|
+
}
|
|
5918
|
+
let a = null;
|
|
5905
5919
|
if (e.cropCoordinatesJson) try {
|
|
5906
|
-
|
|
5920
|
+
a = typeof e.cropCoordinatesJson == "string" ? JSON.parse(e.cropCoordinatesJson) : e.cropCoordinatesJson;
|
|
5907
5921
|
} catch {}
|
|
5908
|
-
let
|
|
5922
|
+
let o = l.get(e.id), s = {};
|
|
5909
5923
|
try {
|
|
5910
|
-
|
|
5924
|
+
s = JSON.parse(e.dataJson || "{}");
|
|
5911
5925
|
} catch {}
|
|
5912
5926
|
if (e.parentAssetId && e.parentDataJson) try {
|
|
5913
|
-
|
|
5927
|
+
s = {
|
|
5914
5928
|
...JSON.parse(e.parentDataJson),
|
|
5915
|
-
...
|
|
5929
|
+
...s
|
|
5916
5930
|
};
|
|
5917
5931
|
} catch {}
|
|
5918
5932
|
u.set(e.id, {
|
|
5919
5933
|
id: e.id,
|
|
5920
|
-
url:
|
|
5921
|
-
originalUrl:
|
|
5934
|
+
url: r,
|
|
5935
|
+
originalUrl: i,
|
|
5922
5936
|
parentAssetId: z(e.parentAssetId) || null,
|
|
5923
|
-
cropCoordinates:
|
|
5924
|
-
variants:
|
|
5937
|
+
cropCoordinates: a,
|
|
5938
|
+
variants: o && Object.keys(o).length > 0 ? o : void 0,
|
|
5925
5939
|
filename: e.filename,
|
|
5926
5940
|
mimeType: e.mimeType,
|
|
5927
|
-
title:
|
|
5928
|
-
alt:
|
|
5929
|
-
description:
|
|
5941
|
+
title: s.title || "",
|
|
5942
|
+
alt: s.alt || "",
|
|
5943
|
+
description: s.description || ""
|
|
5930
5944
|
});
|
|
5931
5945
|
}
|
|
5932
5946
|
let d = (e) => {
|
|
5933
5947
|
if (!e) return e;
|
|
5934
5948
|
let t = z(e);
|
|
5935
5949
|
if (t) {
|
|
5936
|
-
let n = u.get(t) ||
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
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
|
+
if (r || n?.variants) {
|
|
5952
|
+
c = {};
|
|
5953
|
+
let e = r || n?.variants;
|
|
5954
|
+
for (let [t, n] of Object.entries(e)) c[t] = d(n);
|
|
5955
|
+
}
|
|
5941
5956
|
return {
|
|
5942
|
-
...n,
|
|
5957
|
+
...n || {},
|
|
5943
5958
|
id: t,
|
|
5944
|
-
parentAssetId: n
|
|
5945
|
-
url:
|
|
5946
|
-
originalUrl:
|
|
5947
|
-
cropCoordinates: i || n
|
|
5948
|
-
variants:
|
|
5959
|
+
parentAssetId: n?.parentAssetId ? z(n.parentAssetId) : null,
|
|
5960
|
+
url: o,
|
|
5961
|
+
originalUrl: s,
|
|
5962
|
+
cropCoordinates: i || n?.cropCoordinates || null,
|
|
5963
|
+
variants: c,
|
|
5949
5964
|
metadataOverrides: a
|
|
5950
5965
|
};
|
|
5951
5966
|
}
|
|
@@ -6276,8 +6291,8 @@ async function he(e, t, n) {
|
|
|
6276
6291
|
async function ge(e, t, n) {
|
|
6277
6292
|
let r = {}, i = null;
|
|
6278
6293
|
if (t) {
|
|
6279
|
-
let
|
|
6280
|
-
for (let e of
|
|
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 || [];
|
|
6295
|
+
for (let e of o) {
|
|
6281
6296
|
let t = e.draftDataJson || e.dataJson;
|
|
6282
6297
|
if (t) try {
|
|
6283
6298
|
let e = typeof t == "string" ? JSON.parse(t) : t;
|
|
@@ -6289,7 +6304,7 @@ async function ge(e, t, n) {
|
|
|
6289
6304
|
if (!i) {
|
|
6290
6305
|
let t = await e.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(n) || -1, String(n));
|
|
6291
6306
|
if (t && t.dataJson) try {
|
|
6292
|
-
let e = typeof t.dataJson == "string" ? JSON.parse(t.dataJson) :
|
|
6307
|
+
let e = typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : e.dataJson;
|
|
6293
6308
|
e.subpageLayoutId && e.subpageLayoutId !== "inherit" && (i = e.subpageLayoutId);
|
|
6294
6309
|
} catch {}
|
|
6295
6310
|
}
|
|
@@ -6323,7 +6338,7 @@ H.get("/", async (e) => {
|
|
|
6323
6338
|
updatedAt: i.updatedAt
|
|
6324
6339
|
}, s = i.draftDataJson || i.dataJson;
|
|
6325
6340
|
if (s) try {
|
|
6326
|
-
let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT
|
|
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 = se(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
|
|
6327
6342
|
if (a) {
|
|
6328
6343
|
let { resolvedLayoutId: e, inheritedFields: r } = await ge(t, a.parentId, a.treeId);
|
|
6329
6344
|
(l === "inherit" || !l) && (l = e);
|
|
@@ -6473,8 +6488,8 @@ H.get("/", async (e) => {
|
|
|
6473
6488
|
}
|
|
6474
6489
|
}
|
|
6475
6490
|
C && E && C === E && (C = null);
|
|
6476
|
-
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = s === void 0 ? null : U(s);
|
|
6477
|
-
if (
|
|
6491
|
+
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null : U(s);
|
|
6492
|
+
if (M) {
|
|
6478
6493
|
let n = [];
|
|
6479
6494
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
6480
6495
|
treeId: Number(e.treeId),
|
|
@@ -6488,26 +6503,26 @@ H.get("/", async (e) => {
|
|
|
6488
6503
|
});
|
|
6489
6504
|
}
|
|
6490
6505
|
for (let r of n) {
|
|
6491
|
-
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId,
|
|
6506
|
+
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId, M] : [
|
|
6492
6507
|
r.treeId,
|
|
6493
6508
|
r.parentId,
|
|
6494
|
-
|
|
6509
|
+
M
|
|
6495
6510
|
], o = `
|
|
6496
6511
|
SELECT cn.id FROM tree_nodes tn
|
|
6497
6512
|
INNER JOIN content_nodes cn ON tn.contentId = cn.id
|
|
6498
6513
|
WHERE tn.treeId = ? AND ${n} AND cn.slug = ? AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
6499
6514
|
`;
|
|
6500
6515
|
if (a && (o += " AND cn.id != ?", i.push(a)), o += " LIMIT 1", await t.prepare(o).get(...i)) return e.json({
|
|
6501
|
-
error: `The slug '${
|
|
6516
|
+
error: `The slug '${M}' is already in use by another page in this section.`,
|
|
6502
6517
|
field: "slug"
|
|
6503
6518
|
}, 409);
|
|
6504
6519
|
}
|
|
6505
6520
|
}
|
|
6506
6521
|
if (a) {
|
|
6507
|
-
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status FROM content_nodes WHERE id = ?").get(a);
|
|
6522
|
+
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
6508
6523
|
k = me(e, {
|
|
6509
6524
|
title: o,
|
|
6510
|
-
slug:
|
|
6525
|
+
slug: M,
|
|
6511
6526
|
isHidden: b,
|
|
6512
6527
|
sanitizedFields: v
|
|
6513
6528
|
});
|
|
@@ -6515,26 +6530,43 @@ H.get("/", async (e) => {
|
|
|
6515
6530
|
try {
|
|
6516
6531
|
pe(typeof n == "string" ? JSON.parse(n) : n, O);
|
|
6517
6532
|
} catch {}
|
|
6518
|
-
|
|
6519
|
-
let e = await t.prepare("SELECT dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 1").all(a);
|
|
6520
|
-
(Array.isArray(e) ? e : e?.results || []).forEach((e) => {
|
|
6521
|
-
try {
|
|
6522
|
-
pe(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, O);
|
|
6523
|
-
} catch {}
|
|
6524
|
-
});
|
|
6525
|
-
}
|
|
6526
|
-
let r = o === void 0 ? e?.title || "Untitled" : o, i = A ?? e?.slug ?? null, s = x || e?.contentType || "page", l = c === void 0 ? e?.language : C, u = e?.draftDataJson || e?.dataJson || "{}", d = {};
|
|
6533
|
+
let r = {};
|
|
6527
6534
|
try {
|
|
6528
|
-
|
|
6535
|
+
r = JSON.parse(n);
|
|
6529
6536
|
} catch {}
|
|
6530
|
-
let
|
|
6531
|
-
...
|
|
6537
|
+
let i = JSON.stringify({
|
|
6538
|
+
...r,
|
|
6532
6539
|
...v
|
|
6533
|
-
}),
|
|
6534
|
-
|
|
6540
|
+
}), l = !1;
|
|
6541
|
+
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (l = !0), s !== void 0 && M !== e?.slug && (l = !0), c !== void 0 && C !== e?.language && (l = !0), !l && Object.keys(v).length > 0) {
|
|
6542
|
+
for (let e of Object.keys(v)) if (JSON.stringify(v[e]) !== JSON.stringify(r[e])) {
|
|
6543
|
+
l = !0;
|
|
6544
|
+
break;
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
if (!l && m !== void 0) {
|
|
6548
|
+
let e = await t.prepare("SELECT region, elementType, dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(a), n = Array.isArray(e) ? e : e?.results || [];
|
|
6549
|
+
if (m.length !== n.length) l = !0;
|
|
6550
|
+
else for (let e = 0; e < m.length; e++) {
|
|
6551
|
+
let t = m[e], r = n[e], i = t.componentId || t.elementType || "text-block", a = t.region || "content", o = { ...t.data || {} };
|
|
6552
|
+
delete o._instanceId, delete o.blockId;
|
|
6553
|
+
let s = {};
|
|
6554
|
+
try {
|
|
6555
|
+
s = JSON.parse(r.dataJson);
|
|
6556
|
+
} catch {}
|
|
6557
|
+
if (delete s._instanceId, delete s.blockId, i !== r.elementType || a !== r.region || JSON.stringify(o) !== JSON.stringify(s)) {
|
|
6558
|
+
l = !0;
|
|
6559
|
+
break;
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
let u = o === void 0 ? e?.title || "Untitled" : o, d = M ?? e?.slug ?? null, f = x || e?.contentType || "page", p = c === void 0 ? e?.language : C;
|
|
6564
|
+
A = e?.status === "published" || e?.publishedAt ? "published" : "draft";
|
|
6565
|
+
let h = e?.hasUnpublishedChanges === 1 || e?.hasUnpublishedChanges === !0;
|
|
6566
|
+
j = l ? 1 : +!!h, await t.prepare("\n UPDATE content_nodes \n SET title = ?, slug = ?, language = ?, contentType = ?, isHidden = ?, status = ?, draftDataJson = ?, hasUnpublishedChanges = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(u, d, p, f, b, A, i, j, S, a);
|
|
6535
6567
|
} else {
|
|
6536
6568
|
k = !0;
|
|
6537
|
-
let e = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, hasUnpublishedChanges, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, 0, ?, ?)\n ").run(x, o || "Untitled",
|
|
6569
|
+
let e = await t.prepare("\n INSERT INTO content_nodes (contentType, title, slug, language, isHidden, status, draftDataJson, dataJson, hasUnpublishedChanges, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, 'draft', ?, NULL, 0, ?, ?)\n ").run(x, o || "Untitled", M, C, b, JSON.stringify(v), S, S);
|
|
6538
6570
|
D = Number(e.lastInsertRowid);
|
|
6539
6571
|
}
|
|
6540
6572
|
if (h !== void 0 && Array.isArray(h) && D) {
|
|
@@ -6547,10 +6579,10 @@ H.get("/", async (e) => {
|
|
|
6547
6579
|
}
|
|
6548
6580
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
6549
6581
|
if (!e || !e.treeId) continue;
|
|
6550
|
-
let n = Number(e.treeId) || e.treeId, r = de(e.parentId ?? e._draftParentId ?? null), i = typeof e.sortOrder == "number" ? e.sortOrder : 0, a = await t.prepare("SELECT
|
|
6551
|
-
a ? ((a.parentId !== r || a.sortOrder !== i) && (k = !0), await t.prepare("UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE
|
|
6582
|
+
let n = Number(e.treeId) || e.treeId, r = de(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
|
+
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));
|
|
6552
6584
|
}
|
|
6553
|
-
let
|
|
6585
|
+
let N = [];
|
|
6554
6586
|
if (m !== void 0 && Array.isArray(m) && D) {
|
|
6555
6587
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
6556
6588
|
let e = [], n = [];
|
|
@@ -6560,7 +6592,7 @@ H.get("/", async (e) => {
|
|
|
6560
6592
|
blockId: o,
|
|
6561
6593
|
_instanceId: o
|
|
6562
6594
|
});
|
|
6563
|
-
c.forEach((e) =>
|
|
6595
|
+
c.forEach((e) => N.push({
|
|
6564
6596
|
...e,
|
|
6565
6597
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
6566
6598
|
}));
|
|
@@ -6570,7 +6602,7 @@ H.get("/", async (e) => {
|
|
|
6570
6602
|
e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
6571
6603
|
}
|
|
6572
6604
|
if (D) {
|
|
6573
|
-
let n = [...y, ...
|
|
6605
|
+
let n = [...y, ...N];
|
|
6574
6606
|
await oe(t, D, n);
|
|
6575
6607
|
let r = new Set(n.map((e) => e.assetId)), i = new Set([...O].filter((e) => !r.has(e)));
|
|
6576
6608
|
if (i.size > 0) {
|
|
@@ -6581,7 +6613,8 @@ H.get("/", async (e) => {
|
|
|
6581
6613
|
return await I(e).clear(), e.json({
|
|
6582
6614
|
success: !0,
|
|
6583
6615
|
id: D,
|
|
6584
|
-
status:
|
|
6616
|
+
status: A,
|
|
6617
|
+
hasUnpublishedChanges: j === 1 || A === "draft",
|
|
6585
6618
|
isStructuralChange: k
|
|
6586
6619
|
});
|
|
6587
6620
|
}), H.post("/publish", async (e) => {
|
|
@@ -6701,7 +6734,7 @@ function _e(e, t = null) {
|
|
|
6701
6734
|
for (let r = 0; r < e.length; r++) {
|
|
6702
6735
|
let i = e[r];
|
|
6703
6736
|
if (!i) continue;
|
|
6704
|
-
let a = i.
|
|
6737
|
+
let a = i.id || i.contentId;
|
|
6705
6738
|
if (!a || typeof a == "string" && a.startsWith("draft-")) continue;
|
|
6706
6739
|
let o = Number(a);
|
|
6707
6740
|
isNaN(o) || (n.push({
|
|
@@ -6731,7 +6764,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6731
6764
|
e && e.id && (i = Number(e.id));
|
|
6732
6765
|
}
|
|
6733
6766
|
} else i = Number(n);
|
|
6734
|
-
let a = await t.prepare("\n SELECT \n t.
|
|
6767
|
+
let a = await t.prepare("\n SELECT \n t.contentId as treeNodeId, \n t.treeId,\n t.contentId,\n t.parentId,\n t.sortOrder,\n c.title,\n c.slug,\n c.language,\n c.contentType as nodeType,\n c.isHidden,\n c.status,\n c.publishedAt,\n c.hasUnpublishedChanges,\n c.dataJson,\n c.draftDataJson,\n (SELECT COUNT(*) FROM node_assets WHERE nodeId = t.contentId) as assetCount\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE t.treeId = ? AND (c.deletedAt IS NULL OR c.deletedAt = '')\n ORDER BY t.sortOrder ASC\n ").all(i), o = Array.isArray(a) ? a : a?.results || [], s = [], c = /* @__PURE__ */ new Set();
|
|
6735
6768
|
for (let e of o) {
|
|
6736
6769
|
let t = e.contentId;
|
|
6737
6770
|
c.has(t) || (c.add(t), s.push(e));
|
|
@@ -6753,16 +6786,19 @@ W.get("/tree.json", async (e) => {
|
|
|
6753
6786
|
return {
|
|
6754
6787
|
...o,
|
|
6755
6788
|
id: e.contentId,
|
|
6756
|
-
treeNodeId: e.
|
|
6789
|
+
treeNodeId: e.contentId,
|
|
6757
6790
|
parentId: e.parentId || null,
|
|
6758
6791
|
language: e.language?.trim() || null,
|
|
6759
6792
|
hidden: +!!s,
|
|
6760
6793
|
isHidden: s,
|
|
6761
6794
|
status: e.status || "draft",
|
|
6795
|
+
isDraft: e.status === "draft",
|
|
6762
6796
|
publishedAt: e.publishedAt || null,
|
|
6763
6797
|
hasUnpublishedChanges: c,
|
|
6764
6798
|
assetCount: e.assetCount || 0,
|
|
6765
|
-
|
|
6799
|
+
dataJson: e.dataJson ? typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson : null,
|
|
6800
|
+
draftDataJson: e.draftDataJson ? typeof e.draftDataJson == "string" ? JSON.parse(e.draftDataJson) : e.draftDataJson : null,
|
|
6801
|
+
children: l(e.contentId)
|
|
6766
6802
|
};
|
|
6767
6803
|
}).filter((e) => r || !e.hidden);
|
|
6768
6804
|
}
|
|
@@ -6785,11 +6821,11 @@ W.get("/tree.json", async (e) => {
|
|
|
6785
6821
|
let r = _e(n.tree, null);
|
|
6786
6822
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
6787
6823
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
6788
|
-
s += "parentId = CASE
|
|
6824
|
+
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
6789
6825
|
s += "WHEN ? THEN ? \n";
|
|
6790
|
-
}), s += "ELSE parentId END, \n", s += "sortOrder = CASE
|
|
6826
|
+
}), s += "ELSE parentId END, \n", s += "sortOrder = CASE contentId \n", n.forEach(() => {
|
|
6791
6827
|
s += "WHEN ? THEN ? \n";
|
|
6792
|
-
}), s += "ELSE sortOrder END \n", s += `WHERE
|
|
6828
|
+
}), s += "ELSE sortOrder END \n", s += `WHERE contentId IN (${a}) AND treeId = ?`;
|
|
6793
6829
|
let c = [];
|
|
6794
6830
|
n.forEach((e) => {
|
|
6795
6831
|
c.push(e.id, e.parentId);
|
|
@@ -6850,18 +6886,21 @@ W.get("/tree.json", async (e) => {
|
|
|
6850
6886
|
SELECT COALESCE(MAX(sortOrder), -1) + 1 as nextSort
|
|
6851
6887
|
FROM tree_nodes
|
|
6852
6888
|
WHERE treeId = ? AND ${p}
|
|
6853
|
-
`).get(...v))?.nextSort ?? 0
|
|
6854
|
-
|
|
6855
|
-
let
|
|
6856
|
-
|
|
6857
|
-
|
|
6889
|
+
`).get(...v))?.nextSort ?? 0;
|
|
6890
|
+
await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(o, f, g, y);
|
|
6891
|
+
let b = [];
|
|
6892
|
+
n.channels && Array.isArray(n.channels) ? b = n.channels : n.channelId && n.channelId !== "all" && (b = [n.channelId]);
|
|
6893
|
+
let x = [...new Set(b)].filter((e) => e && e !== "all").map((e) => Number(e));
|
|
6894
|
+
if (x.length > 0) {
|
|
6895
|
+
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [f, e]);
|
|
6858
6896
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
6859
6897
|
}
|
|
6860
6898
|
return await i.clear(), e.json({
|
|
6861
6899
|
success: !0,
|
|
6862
6900
|
id: f,
|
|
6863
|
-
treeNodeId:
|
|
6864
|
-
status: "draft"
|
|
6901
|
+
treeNodeId: f,
|
|
6902
|
+
status: "draft",
|
|
6903
|
+
isDraft: !0
|
|
6865
6904
|
}, 201);
|
|
6866
6905
|
}
|
|
6867
6906
|
if (s === "attach") {
|
|
@@ -6893,16 +6932,14 @@ W.get("/tree.json", async (e) => {
|
|
|
6893
6932
|
field: "slug"
|
|
6894
6933
|
}, 409);
|
|
6895
6934
|
}
|
|
6896
|
-
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d)
|
|
6897
|
-
let r = await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), s = Number(r.lastInsertRowid);
|
|
6898
|
-
return await i.clear(), a.purgeNode(e, t, d, !0), e.json({
|
|
6935
|
+
return await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d), await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, 0)\n ").run(o, d, g), await i.clear(), a.purgeNode(e, t, d, !0), e.json({
|
|
6899
6936
|
success: !0,
|
|
6900
|
-
treeNodeId:
|
|
6937
|
+
treeNodeId: d
|
|
6901
6938
|
});
|
|
6902
6939
|
}
|
|
6903
6940
|
if (s === "detach") {
|
|
6904
|
-
let r = n.
|
|
6905
|
-
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE
|
|
6941
|
+
let r = n.contentId || n.id || n.treeNodeId;
|
|
6942
|
+
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE contentId = ? AND treeId = ?) \n WHERE parentId = ? AND treeId = ?\n ").run(r, o, r, o), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ? AND treeId = ?").run(r, o), await i.clear(), a.purgeNode(e, t, r, !0), e.json({ success: !0 })) : e.json({ error: "contentId required for detach" }, 400);
|
|
6906
6943
|
}
|
|
6907
6944
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
6908
6945
|
} catch (t) {
|
|
@@ -7791,7 +7828,7 @@ X.get("/", async (e) => {
|
|
|
7791
7828
|
let e = await Z(t, "SELECT a.id, a.filename, a.isSystemVariant FROM node_assets na JOIN assets a ON na.assetId = a.id WHERE na.nodeId = ?", [Number(c)]);
|
|
7792
7829
|
if (e.length === 0) v.push("1 = 0");
|
|
7793
7830
|
else {
|
|
7794
|
-
let t = e.map((e) => e.isSystemVariant ? `(a.id = '${e.id}' OR
|
|
7831
|
+
let t = e.map((e) => e.isSystemVariant ? `(a.id = '${e.id}' OR a.id IN (SELECT parentAssetId FROM assets WHERE id = '${e.id}'))` : `a.id = '${e.id}'`).join(" OR ");
|
|
7795
7832
|
v.push(`(${t})`);
|
|
7796
7833
|
}
|
|
7797
7834
|
}
|
|
@@ -7802,9 +7839,24 @@ X.get("/", async (e) => {
|
|
|
7802
7839
|
n && n.trim() !== "" && (v.push("a.filename LIKE ?"), _.push(`%${n.trim()}%`)), r && r !== "all" && (r === "image" ? (v.push("a.mimeType LIKE ?"), _.push("image/%")) : r === "document" ? (v.push("(a.mimeType LIKE ? OR a.mimeType LIKE ? OR a.mimeType LIKE ?)"), _.push("application/pdf%", "application/msword%", "application/vnd%")) : r === "video" && (v.push("(a.mimeType LIKE ? OR a.mimeType LIKE ?)"), _.push("video/%", "audio/%")));
|
|
7803
7840
|
let y = `SELECT a.id, a.filename, a.mimeType, a.sizeBytes, a.cdnUrl, a.storageKeyPrivate, a.createdAt, a.updatedAt, a.deletedAt, a.dataJson FROM assets a ${` WHERE ${v.join(" AND ")}`} ORDER BY ${h} ${g} LIMIT ? OFFSET ?`;
|
|
7804
7841
|
_.push(p, m);
|
|
7805
|
-
let b = await Z(t, y, _), x = b.map((e) => e.id), S = /* @__PURE__ */ new Map();
|
|
7806
|
-
x.length > 0
|
|
7807
|
-
|
|
7842
|
+
let b = await Z(t, y, _), x = b.map((e) => e.id), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map();
|
|
7843
|
+
if (x.length > 0) {
|
|
7844
|
+
let e = x.map(() => "?").join(",");
|
|
7845
|
+
(await Z(t, `
|
|
7846
|
+
SELECT master.id AS assetId, COUNT(DISTINCT na.nodeId) AS count
|
|
7847
|
+
FROM assets master
|
|
7848
|
+
INNER JOIN node_assets na ON (
|
|
7849
|
+
na.assetId = master.id OR
|
|
7850
|
+
EXISTS (SELECT 1 FROM assets crop WHERE crop.id = na.assetId AND crop.isSystemVariant = 1 AND crop.parentAssetId = master.id)
|
|
7851
|
+
)
|
|
7852
|
+
WHERE master.id IN (${e})
|
|
7853
|
+
GROUP BY master.id`, x)).forEach((e) => S.set(String(e.assetId), e.count || 0)), (await Z(t, `
|
|
7854
|
+
SELECT parentAssetId, COUNT(id) AS count
|
|
7855
|
+
FROM assets
|
|
7856
|
+
WHERE isSystemVariant = 1 AND parentAssetId IN (${e})
|
|
7857
|
+
GROUP BY parentAssetId`, x)).forEach((e) => C.set(String(e.parentAssetId), e.count || 0));
|
|
7858
|
+
}
|
|
7859
|
+
let w = b.map((t) => {
|
|
7808
7860
|
let n = {
|
|
7809
7861
|
title: "",
|
|
7810
7862
|
alt: "",
|
|
@@ -7829,11 +7881,12 @@ X.get("/", async (e) => {
|
|
|
7829
7881
|
updatedAt: t.updatedAt,
|
|
7830
7882
|
deletedAt: t.deletedAt || null,
|
|
7831
7883
|
usageCount: S.get(String(t.id)) || 0,
|
|
7884
|
+
variantCount: C.get(String(t.id)) || 0,
|
|
7832
7885
|
url: r,
|
|
7833
7886
|
originalUrl: r
|
|
7834
7887
|
};
|
|
7835
7888
|
});
|
|
7836
|
-
return e.json(
|
|
7889
|
+
return e.json(w);
|
|
7837
7890
|
} catch (t) {
|
|
7838
7891
|
return e.json({
|
|
7839
7892
|
error: "Failed to fetch assets",
|
|
@@ -7842,50 +7895,82 @@ X.get("/", async (e) => {
|
|
|
7842
7895
|
}
|
|
7843
7896
|
}), X.post("/upload", async (e) => {
|
|
7844
7897
|
try {
|
|
7845
|
-
let t = l(e), { storage: n } = ae(e.env), r = await e.req.parseBody(), i = r.file, a = r.isVariant === "true" || r.isVariant === "1" || r.temporary === "true", o = r.parentAssetId || r.parentAsset,
|
|
7846
|
-
|
|
7847
|
-
let
|
|
7848
|
-
if (
|
|
7849
|
-
if (typeof
|
|
7850
|
-
|
|
7898
|
+
let t = l(e), { storage: n } = ae(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
|
+
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
7900
|
+
let d = r.cropCoordinates, f = null, p = null;
|
|
7901
|
+
if (d) {
|
|
7902
|
+
if (typeof d == "string") {
|
|
7903
|
+
f = d;
|
|
7851
7904
|
try {
|
|
7852
|
-
|
|
7905
|
+
p = JSON.parse(d);
|
|
7853
7906
|
} catch {}
|
|
7854
|
-
} else
|
|
7907
|
+
} else f = JSON.stringify(d), p = d;
|
|
7855
7908
|
}
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7909
|
+
let m = crypto.randomUUID().replace(/-/g, "").slice(0, 12), h = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7).replace("-", "/"), g = a || i.name.startsWith("crop_"), _ = g ? `kama/cache/${h}/${m}` : `kama/uploads/${h}/${m}`, v = await n.upload(i, _), y = typeof v == "string" ? v : v?.key || v?.storageKeyPrivate || v?.storageKey || `${_}/${m}_${i.name}`;
|
|
7910
|
+
if (!y) throw Error("Storage provider failed to return a valid storage key");
|
|
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
|
+
E && (await Z(t, "SELECT id FROM users WHERE id = ?", [E])).length === 0 && (E = null);
|
|
7913
|
+
let D = new V(e.env);
|
|
7914
|
+
if (s) {
|
|
7915
|
+
let r = await Z(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
7916
|
+
if (r.length > 0) {
|
|
7917
|
+
let a = r[0];
|
|
7918
|
+
if (await Q(t, "UPDATE assets SET filename = ?, mimeType = ?, sizeBytes = ?, storageKeyPrivate = ?, cdnUrl = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
7919
|
+
i.name,
|
|
7920
|
+
C,
|
|
7921
|
+
w,
|
|
7922
|
+
y,
|
|
7923
|
+
S,
|
|
7924
|
+
s
|
|
7925
|
+
]), a.storageKeyPrivate) try {
|
|
7926
|
+
await n.delete(a.storageKeyPrivate);
|
|
7927
|
+
} catch (e) {
|
|
7928
|
+
console.warn("Failed to cleanup old asset", e);
|
|
7929
|
+
}
|
|
7930
|
+
D.purgeAsset(e, t, s);
|
|
7931
|
+
let o = `${S}?v=${Date.now()}`;
|
|
7932
|
+
return e.json({
|
|
7933
|
+
id: s,
|
|
7934
|
+
url: o,
|
|
7935
|
+
originalUrl: o,
|
|
7936
|
+
parentAssetId: a.parentAssetId,
|
|
7937
|
+
cropCoordinates: p,
|
|
7938
|
+
filename: i.name,
|
|
7939
|
+
mimeType: C,
|
|
7940
|
+
usageCount: 0,
|
|
7941
|
+
isSystemVariant: !!a.isSystemVariant,
|
|
7942
|
+
replaced: !0
|
|
7943
|
+
}, 200);
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
let O = `ast_${m}`, k = +!!g;
|
|
7862
7947
|
await Q(t, "INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
7863
|
-
|
|
7948
|
+
O,
|
|
7864
7949
|
i.name,
|
|
7865
|
-
S,
|
|
7866
7950
|
C,
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7951
|
+
w,
|
|
7952
|
+
y,
|
|
7953
|
+
S,
|
|
7870
7954
|
E,
|
|
7871
|
-
|
|
7872
|
-
u
|
|
7955
|
+
k,
|
|
7956
|
+
u,
|
|
7957
|
+
f
|
|
7873
7958
|
]);
|
|
7874
|
-
let
|
|
7875
|
-
if (
|
|
7876
|
-
let n = await Z(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [
|
|
7877
|
-
n.length > 0 && (
|
|
7959
|
+
let A = S;
|
|
7960
|
+
if (u) {
|
|
7961
|
+
let n = await Z(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [u]);
|
|
7962
|
+
n.length > 0 && (A = Re(n[0].cdnUrl, n[0].storageKeyPrivate, b)), D.purgeAsset(e, t, u);
|
|
7878
7963
|
}
|
|
7879
7964
|
return e.json({
|
|
7880
|
-
id:
|
|
7881
|
-
url:
|
|
7882
|
-
originalUrl:
|
|
7883
|
-
parentAssetId:
|
|
7884
|
-
cropCoordinates:
|
|
7965
|
+
id: O,
|
|
7966
|
+
url: S,
|
|
7967
|
+
originalUrl: A,
|
|
7968
|
+
parentAssetId: u,
|
|
7969
|
+
cropCoordinates: p,
|
|
7885
7970
|
filename: i.name,
|
|
7886
|
-
mimeType:
|
|
7971
|
+
mimeType: C,
|
|
7887
7972
|
usageCount: 0,
|
|
7888
|
-
isSystemVariant: !!
|
|
7973
|
+
isSystemVariant: !!k
|
|
7889
7974
|
}, 201);
|
|
7890
7975
|
} catch (t) {
|
|
7891
7976
|
return console.error("❌ [Asset Upload Crash Details]:", t), e.json({
|
|
@@ -7897,26 +7982,18 @@ X.get("/", async (e) => {
|
|
|
7897
7982
|
try {
|
|
7898
7983
|
let t = l(e), n = e.req.param("id"), r = await Z(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
7899
7984
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
7900
|
-
let i = r[0], a =
|
|
7901
|
-
n,
|
|
7902
|
-
`crop_%${a}%`,
|
|
7903
|
-
`%${n}%`
|
|
7904
|
-
]), s = await Z(t, "SELECT id, filename, mimeType, sizeBytes, cdnUrl, storageKeyPrivate, parentAssetId, cropCoordinatesJson, createdAt FROM assets WHERE isSystemVariant = 1 AND (parentAssetId = ? OR filename LIKE ? OR filename LIKE ?) ORDER BY createdAt DESC", [
|
|
7905
|
-
n,
|
|
7906
|
-
`crop_%${a}%`,
|
|
7907
|
-
`%${n}%`
|
|
7908
|
-
]), c = {
|
|
7985
|
+
let i = r[0], a = await Z(t, "\n SELECT DISTINCT cn.id, cn.title, cn.contentType, cn.slug, na.fieldKey, na.assetId \n FROM node_assets na \n INNER JOIN content_nodes cn ON na.nodeId = cn.id \n LEFT JOIN assets crop ON na.assetId = crop.id \n WHERE na.assetId = ? OR (crop.isSystemVariant = 1 AND crop.parentAssetId = ?)\n ", [n, n]), o = await Z(t, "\n SELECT id, filename, mimeType, sizeBytes, cdnUrl, storageKeyPrivate, parentAssetId, cropCoordinatesJson, createdAt, updatedAt \n FROM assets \n WHERE isSystemVariant = 1 AND parentAssetId = ? \n ORDER BY createdAt DESC\n ", [n]), s = {
|
|
7909
7986
|
title: "",
|
|
7910
7987
|
alt: "",
|
|
7911
7988
|
description: ""
|
|
7912
7989
|
};
|
|
7913
7990
|
try {
|
|
7914
|
-
|
|
7915
|
-
...
|
|
7991
|
+
s = {
|
|
7992
|
+
...s,
|
|
7916
7993
|
...JSON.parse(i.dataJson || "{}")
|
|
7917
7994
|
};
|
|
7918
7995
|
} catch {}
|
|
7919
|
-
let u = Re(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)
|
|
7996
|
+
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), u = `${Re(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)}?v=${c}`;
|
|
7920
7997
|
return e.json({
|
|
7921
7998
|
id: i.id,
|
|
7922
7999
|
filename: i.filename,
|
|
@@ -7924,17 +8001,18 @@ X.get("/", async (e) => {
|
|
|
7924
8001
|
sizeBytes: i.sizeBytes,
|
|
7925
8002
|
createdAt: i.createdAt,
|
|
7926
8003
|
updatedAt: i.updatedAt,
|
|
7927
|
-
title:
|
|
7928
|
-
alt:
|
|
7929
|
-
description:
|
|
8004
|
+
title: s.title || "",
|
|
8005
|
+
alt: s.alt || "",
|
|
8006
|
+
description: s.description || "",
|
|
7930
8007
|
url: u,
|
|
7931
8008
|
originalUrl: u,
|
|
7932
|
-
connectedNodes:
|
|
7933
|
-
variants:
|
|
8009
|
+
connectedNodes: a,
|
|
8010
|
+
variants: o.map((t) => {
|
|
7934
8011
|
let n = null;
|
|
7935
8012
|
if (t.cropCoordinatesJson) try {
|
|
7936
8013
|
n = JSON.parse(t.cropCoordinatesJson);
|
|
7937
8014
|
} catch {}
|
|
8015
|
+
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a = Re(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
7938
8016
|
return {
|
|
7939
8017
|
id: t.id,
|
|
7940
8018
|
filename: t.filename,
|
|
@@ -7943,7 +8021,7 @@ X.get("/", async (e) => {
|
|
|
7943
8021
|
createdAt: t.createdAt,
|
|
7944
8022
|
parentAssetId: t.parentAssetId || i.id,
|
|
7945
8023
|
cropCoordinates: n,
|
|
7946
|
-
url:
|
|
8024
|
+
url: `${a}?v=${r}`,
|
|
7947
8025
|
originalUrl: u
|
|
7948
8026
|
};
|
|
7949
8027
|
})
|
|
@@ -7970,12 +8048,7 @@ X.get("/", async (e) => {
|
|
|
7970
8048
|
}), X.delete("/:id", async (e) => {
|
|
7971
8049
|
try {
|
|
7972
8050
|
let t = l(e), n = e.req.param("id"), r = (await Z(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
7973
|
-
return r ? (new V(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
|
|
7974
|
-
n,
|
|
7975
|
-
n,
|
|
7976
|
-
`crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
7977
|
-
`%${n}%`
|
|
7978
|
-
]), e.json({
|
|
8051
|
+
return r ? (new V(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({
|
|
7979
8052
|
success: !0,
|
|
7980
8053
|
id: n,
|
|
7981
8054
|
trashed: !0
|
|
@@ -7989,18 +8062,11 @@ X.get("/", async (e) => {
|
|
|
7989
8062
|
}), X.post("/restore", async (e) => {
|
|
7990
8063
|
try {
|
|
7991
8064
|
let t = l(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
7992
|
-
|
|
7993
|
-
let i = (await Z(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
|
|
7994
|
-
return i ? (await Q(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
7995
|
-
r,
|
|
7996
|
-
r,
|
|
7997
|
-
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
7998
|
-
`%${r}%`
|
|
7999
|
-
]), new V(e.env).purgeAsset(e, t, r), e.json({
|
|
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 V(e.env).purgeAsset(e, t, r), e.json({
|
|
8000
8066
|
success: !0,
|
|
8001
8067
|
id: r,
|
|
8002
8068
|
restored: !0
|
|
8003
|
-
})) : e.json({ error: "Asset not found" }, 404);
|
|
8069
|
+
})) : e.json({ error: "Asset not found" }, 404) : e.json({ error: "Asset ID required" }, 400);
|
|
8004
8070
|
} catch (t) {
|
|
8005
8071
|
return e.json({
|
|
8006
8072
|
error: "Failed to restore asset",
|
|
@@ -8013,11 +8079,7 @@ X.get("/", async (e) => {
|
|
|
8013
8079
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
8014
8080
|
new V(e.env).purgeAsset(e, t, r);
|
|
8015
8081
|
let a = [i];
|
|
8016
|
-
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE
|
|
8017
|
-
r,
|
|
8018
|
-
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
8019
|
-
`%${r}%`
|
|
8020
|
-
])]);
|
|
8082
|
+
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
8021
8083
|
let o = a.map((e) => e.id);
|
|
8022
8084
|
if (typeof n.delete == "function") {
|
|
8023
8085
|
for (let e of a) if (e.storageKeyPrivate) try {
|
|
@@ -8100,47 +8162,47 @@ async function Ue(e, t, n, r) {
|
|
|
8100
8162
|
}
|
|
8101
8163
|
}));
|
|
8102
8164
|
}
|
|
8103
|
-
async function We(e, t, n, r, i = !1,
|
|
8165
|
+
async function We(e, t, n, r, i, a = !1, o) {
|
|
8104
8166
|
if (!t) return { blocks: [] };
|
|
8105
|
-
let
|
|
8106
|
-
if (!
|
|
8107
|
-
let
|
|
8108
|
-
if (
|
|
8109
|
-
let
|
|
8110
|
-
|
|
8167
|
+
let s = await e.prepare("\n WITH RECURSIVE ancestor_path(contentId, title, slug, parentId, level) AS (\n SELECT t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT * FROM ancestor_path ORDER BY level ASC\n ").all(t, n, n), c = Array.isArray(s) ? s : s?.results || [];
|
|
8168
|
+
if (!c || c.length === 0) return { blocks: [] };
|
|
8169
|
+
let l = c.map((e) => e.contentId).filter((e) => e != null);
|
|
8170
|
+
if (l.length === 0) return { blocks: [] };
|
|
8171
|
+
let u = l.map(() => "?").join(","), d = +!!a, f = await e.prepare(`SELECT * FROM content_blocks WHERE contentId IN (${u}) AND isDraft = ? ORDER BY contentId ASC, sortOrder ASC`).all(...l, d), p = Array.isArray(f) ? f : f?.results || [], m = /* @__PURE__ */ new Map();
|
|
8172
|
+
p.forEach((e) => {
|
|
8111
8173
|
let t = String(e.contentId);
|
|
8112
|
-
|
|
8174
|
+
m.has(t) || m.set(t, []), m.get(t).push(e);
|
|
8113
8175
|
});
|
|
8114
|
-
for (let t of
|
|
8115
|
-
let
|
|
8116
|
-
if (
|
|
8117
|
-
let o = /* @__PURE__ */ new Set([
|
|
8176
|
+
for (let t of c) {
|
|
8177
|
+
let n = m.get(String(t.contentId)) || [];
|
|
8178
|
+
if (n.filter((e) => e.region === r).length === 0) continue;
|
|
8179
|
+
let o = /* @__PURE__ */ new Set([r]), s = !0;
|
|
8118
8180
|
for (; s;) {
|
|
8119
8181
|
s = !1;
|
|
8120
|
-
for (let e of
|
|
8182
|
+
for (let e of n) {
|
|
8121
8183
|
if (!o.has(e.region)) continue;
|
|
8122
8184
|
let t = {};
|
|
8123
8185
|
try {
|
|
8124
8186
|
t = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
8125
8187
|
} catch {}
|
|
8126
|
-
let
|
|
8127
|
-
for (let e of
|
|
8188
|
+
let r = String(e.id), i = String(t.blockId || t._instanceId || t.id || e.blockId);
|
|
8189
|
+
for (let e of n) {
|
|
8128
8190
|
if (!e.region || o.has(e.region)) continue;
|
|
8129
8191
|
let t = e.region;
|
|
8130
|
-
(t.startsWith(`${
|
|
8192
|
+
(t.startsWith(`${r}-`) || t.startsWith(`${r}_`) || i && i !== "undefined" && i !== "null" && (t.startsWith(`${i}-`) || t.startsWith(`${i}_`) || t.startsWith(i))) && (o.add(t), s = !0);
|
|
8131
8193
|
}
|
|
8132
8194
|
}
|
|
8133
8195
|
}
|
|
8134
|
-
let c = await Promise.all(
|
|
8135
|
-
let
|
|
8196
|
+
let c = await Promise.all(n.filter((e) => o.has(e.region)).map(async (t) => {
|
|
8197
|
+
let n = {};
|
|
8136
8198
|
try {
|
|
8137
|
-
|
|
8199
|
+
n = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
|
|
8138
8200
|
} catch {}
|
|
8139
|
-
let o =
|
|
8140
|
-
if (!
|
|
8141
|
-
let c = t.elementType || t.componentId || "text-block", l =
|
|
8201
|
+
let o = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = He(n.startShowingAt, n.stopShowingAt);
|
|
8202
|
+
if (!a && (o || !s)) return null;
|
|
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);
|
|
8142
8204
|
return d = await B(e, d), d = Ke(d), d.blockId = u, {
|
|
8143
|
-
region: t.region ||
|
|
8205
|
+
region: t.region || r,
|
|
8144
8206
|
block: {
|
|
8145
8207
|
instanceId: t.id,
|
|
8146
8208
|
blockId: u,
|
|
@@ -8150,8 +8212,8 @@ async function We(e, t, n, r, i = !1, a) {
|
|
|
8150
8212
|
};
|
|
8151
8213
|
})), l = {};
|
|
8152
8214
|
for (let e of c) e && (l[e.region] || (l[e.region] = []), l[e.region].push(e.block));
|
|
8153
|
-
if (l[
|
|
8154
|
-
blocks: l[
|
|
8215
|
+
if (l[r] && l[r].length > 0) return {
|
|
8216
|
+
blocks: l[r],
|
|
8155
8217
|
subRegions: l,
|
|
8156
8218
|
inheritedFromId: String(t.contentId),
|
|
8157
8219
|
inheritedFromTitle: t.title || t.slug
|
|
@@ -8267,7 +8329,7 @@ async function Je(e, t, n) {
|
|
|
8267
8329
|
async function Ye(e, t, n, r) {
|
|
8268
8330
|
let i = Ve(t, n), a = r.treeEdges.get(i);
|
|
8269
8331
|
if (a) return a;
|
|
8270
|
-
let o = e.prepare("SELECT
|
|
8332
|
+
let o = e.prepare("SELECT contentId as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
|
|
8271
8333
|
return r.treeEdges.set(i, Promise.resolve(o)), o;
|
|
8272
8334
|
}
|
|
8273
8335
|
async function Xe(e, t, n) {
|
|
@@ -8327,7 +8389,7 @@ async function $e(e, t, n, r) {
|
|
|
8327
8389
|
if (e) return e;
|
|
8328
8390
|
}
|
|
8329
8391
|
let a = (async () => {
|
|
8330
|
-
let r = await e.prepare("\n WITH RECURSIVE ancestor_path(
|
|
8392
|
+
let r = await e.prepare("\n WITH RECURSIVE ancestor_path(contentId, parentId, slug, level) AS (\n SELECT t.contentId, t.parentId, c.slug, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId, t.parentId, c.slug, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT slug FROM ancestor_path ORDER BY level DESC\n ").all(t, n, n), i = Array.isArray(r) ? r : r?.results || [], a = [];
|
|
8331
8393
|
for (let e of i) {
|
|
8332
8394
|
let t = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
8333
8395
|
t === "home" || t === "homee" ? i.length === 1 && (a.length = 0) : t && a.push(t);
|
|
@@ -8339,7 +8401,7 @@ async function $e(e, t, n, r) {
|
|
|
8339
8401
|
async function et(e, t, n, r, i) {
|
|
8340
8402
|
let a = {}, o = null;
|
|
8341
8403
|
if (t) {
|
|
8342
|
-
let
|
|
8404
|
+
let i = await e.prepare("\n WITH RECURSIVE ancestor_path(contentId, title, slug, parentId, level) AS (\n SELECT t.contentId, c.title, c.slug, t.parentId, 0 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id WHERE t.contentId = ? AND t.treeId = ?\n UNION ALL\n SELECT t.contentId, c.title, c.slug, t.parentId, ap.level + 1 FROM tree_nodes t INNER JOIN content_nodes c ON t.contentId = c.id INNER JOIN ancestor_path ap ON t.contentId = ap.parentId AND t.treeId = ?\n )\n SELECT c.dataJson, c.draftDataJson FROM ancestor_path ap INNER JOIN content_nodes c ON ap.contentId = c.id ORDER BY ap.level ASC\n ").all(t, n, n), s = Array.isArray(i) ? i : i?.results || [], c = /* @__PURE__ */ new Set([
|
|
8343
8405
|
"subpageLayoutId",
|
|
8344
8406
|
"layoutId",
|
|
8345
8407
|
"slug",
|
|
@@ -8353,12 +8415,12 @@ async function et(e, t, n, r, i) {
|
|
|
8353
8415
|
"hidden",
|
|
8354
8416
|
"status"
|
|
8355
8417
|
]);
|
|
8356
|
-
for (let e of
|
|
8418
|
+
for (let e of s) {
|
|
8357
8419
|
let t = r && e.draftDataJson || e.dataJson;
|
|
8358
8420
|
if (t) try {
|
|
8359
8421
|
let e = typeof t == "string" ? JSON.parse(t) : t;
|
|
8360
8422
|
!o && e.subpageLayoutId && e.subpageLayoutId !== "inherit" && (o = e.subpageLayoutId);
|
|
8361
|
-
for (let [t, n] of Object.entries(e)) n != null && n !== "" && n !== "inherit" && !
|
|
8423
|
+
for (let [t, n] of Object.entries(e)) n != null && n !== "" && n !== "inherit" && !c.has(t) && !t.startsWith("_") && a[t] === void 0 && (a[t] = n);
|
|
8362
8424
|
} catch {}
|
|
8363
8425
|
}
|
|
8364
8426
|
}
|
|
@@ -8392,7 +8454,7 @@ ze.get("/*", async (e) => {
|
|
|
8392
8454
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
8393
8455
|
if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
|
|
8394
8456
|
let u = c.id, d = c.key || a, f = I(e), p = se(e.env?.BUNDLED_DEFINITIONS), m = /^\d+$/.test(i), h = null, g = null, _ = e.req.query("treeId"), v = i.split("/"), y = v[v.length - 1], b = "/" + i.replace(/^\/+|\/+$/g, ""), x = `
|
|
8395
|
-
SELECT cn.*, tn.
|
|
8457
|
+
SELECT cn.*, tn.contentId as treeNodeId, tn.parentId, tn.treeId FROM content_nodes cn
|
|
8396
8458
|
INNER JOIN tree_nodes tn ON cn.id = tn.contentId
|
|
8397
8459
|
${u === null ? "" : "INNER JOIN node_channels nc ON cn.id = nc.nodeId"}
|
|
8398
8460
|
WHERE cn.slug = ? ${u === null ? "" : "AND nc.channelId = ?"}
|
|
@@ -8413,7 +8475,7 @@ ze.get("/*", async (e) => {
|
|
|
8413
8475
|
if (!h && v.length === 1 && (h = u === null ? await t.prepare("SELECT * FROM content_nodes WHERE slug = ?").get(y) : 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(y, u)), !h && m && (h = u === 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), u)), !h) return e.json({ error: `Node '${i}' not found for Channel '${a}'` }, 404);
|
|
8414
8476
|
if (!g) {
|
|
8415
8477
|
let e = _ ? [h.id, _] : [h.id];
|
|
8416
|
-
g = await t.prepare(`SELECT
|
|
8478
|
+
g = await t.prepare(`SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${_ ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
|
|
8417
8479
|
}
|
|
8418
8480
|
let T = g?.treeId || _ || "main-nav", E = null;
|
|
8419
8481
|
if (T) {
|
|
@@ -8464,7 +8526,7 @@ ze.get("/*", async (e) => {
|
|
|
8464
8526
|
if (!s && (de || fe || pe && !me)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
8465
8527
|
let he = [];
|
|
8466
8528
|
if (g?.treeNodeId) {
|
|
8467
|
-
let e = await t.prepare("\n SELECT t.
|
|
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(g.treeNodeId, T), n = Array.isArray(e) ? e : e?.results || [], r = P.path === "/" ? "" : P.path;
|
|
8468
8530
|
he = n.map((e) => {
|
|
8469
8531
|
let t = {}, n = s && e.draftDataJson || e.dataJson;
|
|
8470
8532
|
if (!n) return null;
|
|
@@ -8517,7 +8579,7 @@ ze.get("/*", async (e) => {
|
|
|
8517
8579
|
for (let [e, r] of Object.entries(K)) {
|
|
8518
8580
|
let i = G[e] && G[e].length > 0, a = !!ne[e];
|
|
8519
8581
|
if (G[e] || (G[e] = [], ve[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && N) {
|
|
8520
|
-
let r = await We(t, N, e, p, s, n);
|
|
8582
|
+
let r = await We(t, N, String(T), e, p, s, n);
|
|
8521
8583
|
if (r.blocks.length > 0 && (G[e] = r.blocks, ve[e] = {
|
|
8522
8584
|
isInherited: !0,
|
|
8523
8585
|
inheritedFromId: r.inheritedFromId,
|
|
@@ -8603,7 +8665,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8603
8665
|
}
|
|
8604
8666
|
let g = [];
|
|
8605
8667
|
if (m !== null) {
|
|
8606
|
-
let e = await t.prepare("\n SELECT \n t.
|
|
8668
|
+
let e = await t.prepare("\n SELECT \n t.contentId as treeNodeId,\n t.treeId,\n t.contentId as id,\n t.parentId,\n t.sortOrder,\n c.title,\n c.slug,\n c.language,\n c.contentType as nodeType,\n c.isHidden,\n c.status,\n c.dataJson,\n c.draftDataJson\n FROM tree_nodes t\n INNER JOIN content_nodes c ON t.contentId = c.id\n WHERE t.treeId = ? AND (c.deletedAt IS NULL OR c.deletedAt = '')\n ORDER BY t.sortOrder ASC\n ").all(m);
|
|
8607
8669
|
g = Array.isArray(e) ? e : e?.results || [];
|
|
8608
8670
|
}
|
|
8609
8671
|
if ((!g || g.length === 0) && !c) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
@@ -8614,7 +8676,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8614
8676
|
}
|
|
8615
8677
|
let v = /* @__PURE__ */ new Map();
|
|
8616
8678
|
for (let e of g) {
|
|
8617
|
-
let t = String(e.
|
|
8679
|
+
let t = String(e.id), n = a && e.draftDataJson ? e.draftDataJson : e.dataJson;
|
|
8618
8680
|
if (!n) {
|
|
8619
8681
|
v.set(t, {});
|
|
8620
8682
|
continue;
|
|
@@ -8629,11 +8691,11 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8629
8691
|
function y(e = null, t = "") {
|
|
8630
8692
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e);
|
|
8631
8693
|
return (_.get(n) || []).map((e) => {
|
|
8632
|
-
let n = v.get(String(e.
|
|
8694
|
+
let n = v.get(String(e.id)) || {}, r = {};
|
|
8633
8695
|
for (let [e, t] of Object.entries(n)) e !== "_isTreeDraft" && e !== "_draftParentId" && e !== "isNew" && e !== "hidden" && e !== "is_hidden" && e !== "isHidden" && e !== "status" && (r[e] = t);
|
|
8634
8696
|
let i = !a && (e.status === "draft" || e.status === "new"), o = Number(e.isHidden) === 1 || i || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = it(n.startShowingAt, n.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = (!e.parentId || e.parentId === "null" || e.parentId === "") && (c === "home" || c === "homee") ? "/" : `${t}/${c}`.replace(/\/+/g, "/"), d = e.language && String(e.language).trim() !== "" ? e.language.trim() : u, f = {
|
|
8635
8697
|
id: e.id,
|
|
8636
|
-
treeNodeId: e.
|
|
8698
|
+
treeNodeId: e.id,
|
|
8637
8699
|
parentId: e.parentId || null,
|
|
8638
8700
|
title: e.title,
|
|
8639
8701
|
slug: c,
|
|
@@ -8645,7 +8707,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8645
8707
|
};
|
|
8646
8708
|
e.nodeType === "external-link" && (r.url && (f.url = r.url), r.target && (f.target = r.target));
|
|
8647
8709
|
let p = l === "/" ? "" : l;
|
|
8648
|
-
return f.children = y(e.
|
|
8710
|
+
return f.children = y(e.id, p), f;
|
|
8649
8711
|
}).filter((e) => a || !e.hidden);
|
|
8650
8712
|
}
|
|
8651
8713
|
let b = {
|