@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
|
@@ -4785,7 +4785,7 @@ var u = /* @__PURE__ */ o({
|
|
|
4785
4785
|
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 ",
|
|
4786
4786
|
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 ",
|
|
4787
4787
|
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 ",
|
|
4788
|
-
tree_nodes: "\n
|
|
4788
|
+
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 ",
|
|
4789
4789
|
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 ",
|
|
4790
4790
|
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 ",
|
|
4791
4791
|
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 ",
|
|
@@ -4830,6 +4830,14 @@ async function _(e, t) {
|
|
|
4830
4830
|
await e.prepare("ALTER TABLE \"assets\" ADD COLUMN cropCoordinatesJson TEXT;").run();
|
|
4831
4831
|
} catch {}
|
|
4832
4832
|
}
|
|
4833
|
+
if (t === "tree_nodes" && n.has("id")) {
|
|
4834
|
+
console.log("[Schema Sync] Migrating tree_nodes to Content-to-Content hierarchy...");
|
|
4835
|
+
try {
|
|
4836
|
+
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.");
|
|
4837
|
+
} catch (e) {
|
|
4838
|
+
console.error("[Schema Sync] Failed to migrate tree_nodes schema:", e);
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4833
4841
|
}
|
|
4834
4842
|
}
|
|
4835
4843
|
for (let t of m) try {
|
|
@@ -5844,6 +5852,7 @@ async function B(e, t) {
|
|
|
5844
5852
|
let t = z(e.parentAssetId);
|
|
5845
5853
|
t && n.add(t);
|
|
5846
5854
|
}
|
|
5855
|
+
typeof e == "object" && e.variants && Object.values(e.variants).forEach(r);
|
|
5847
5856
|
} else Array.isArray(e) ? e.forEach(r) : typeof e == "object" && Object.values(e).forEach(r);
|
|
5848
5857
|
};
|
|
5849
5858
|
if (r(t), n.size === 0) return t;
|
|
@@ -5857,14 +5866,16 @@ async function B(e, t) {
|
|
|
5857
5866
|
a.parentAssetId,
|
|
5858
5867
|
a.cropCoordinatesJson,
|
|
5859
5868
|
a.dataJson,
|
|
5869
|
+
a.updatedAt,
|
|
5860
5870
|
p.cdnUrl AS parentCdnUrl,
|
|
5861
5871
|
p.storageKeyPrivate AS parentStorageKeyPrivate,
|
|
5862
|
-
p.dataJson AS parentDataJson
|
|
5872
|
+
p.dataJson AS parentDataJson,
|
|
5873
|
+
p.updatedAt AS parentUpdatedAt
|
|
5863
5874
|
FROM assets a
|
|
5864
5875
|
LEFT JOIN assets p ON a.parentAssetId = p.id
|
|
5865
5876
|
WHERE a.id IN (${i})
|
|
5866
5877
|
`).all(...Array.from(n)), o = Array.isArray(a) ? a : a?.results || [], s = await e.prepare(`
|
|
5867
|
-
SELECT id, cdnUrl, storageKeyPrivate, filename, parentAssetId, cropCoordinatesJson, dataJson
|
|
5878
|
+
SELECT id, cdnUrl, storageKeyPrivate, filename, parentAssetId, cropCoordinatesJson, dataJson, updatedAt
|
|
5868
5879
|
FROM assets
|
|
5869
5880
|
WHERE isSystemVariant = 1
|
|
5870
5881
|
AND (parentAssetId IN (${i}) OR ${Array.from(n).map(() => "filename LIKE ?").join(" OR ")})
|
|
@@ -5876,62 +5887,66 @@ async function B(e, t) {
|
|
|
5876
5887
|
if (e.cropCoordinatesJson) try {
|
|
5877
5888
|
a = typeof e.cropCoordinatesJson == "string" ? JSON.parse(e.cropCoordinatesJson) : e.cropCoordinatesJson;
|
|
5878
5889
|
} catch {}
|
|
5879
|
-
let o = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : "");
|
|
5890
|
+
let o = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""), s = e.updatedAt ? new Date(e.updatedAt).getTime() : Date.now(), c = o ? `${o}?v=${s}` : "";
|
|
5880
5891
|
l.has(t) || l.set(t, {}), l.get(t)[i] = {
|
|
5881
5892
|
id: e.id,
|
|
5882
|
-
url:
|
|
5893
|
+
url: c,
|
|
5883
5894
|
cropCoordinates: a
|
|
5884
5895
|
};
|
|
5885
5896
|
}
|
|
5886
5897
|
let u = /* @__PURE__ */ new Map();
|
|
5887
5898
|
for (let e of o) {
|
|
5888
|
-
let t = e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""), n =
|
|
5889
|
-
e.parentAssetId && (e.parentCdnUrl || e.parentStorageKeyPrivate)
|
|
5890
|
-
|
|
5899
|
+
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;
|
|
5900
|
+
if (e.parentAssetId && (e.parentCdnUrl || e.parentStorageKeyPrivate)) {
|
|
5901
|
+
let n = e.parentUpdatedAt ? new Date(e.parentUpdatedAt).getTime() : t;
|
|
5902
|
+
i = `${e.parentCdnUrl || `/media/${e.parentStorageKeyPrivate}`}?v=${n}`;
|
|
5903
|
+
}
|
|
5904
|
+
let a = null;
|
|
5891
5905
|
if (e.cropCoordinatesJson) try {
|
|
5892
|
-
|
|
5906
|
+
a = typeof e.cropCoordinatesJson == "string" ? JSON.parse(e.cropCoordinatesJson) : e.cropCoordinatesJson;
|
|
5893
5907
|
} catch {}
|
|
5894
|
-
let
|
|
5908
|
+
let o = l.get(e.id), s = {};
|
|
5895
5909
|
try {
|
|
5896
|
-
|
|
5910
|
+
s = JSON.parse(e.dataJson || "{}");
|
|
5897
5911
|
} catch {}
|
|
5898
5912
|
if (e.parentAssetId && e.parentDataJson) try {
|
|
5899
|
-
|
|
5913
|
+
s = {
|
|
5900
5914
|
...JSON.parse(e.parentDataJson),
|
|
5901
|
-
...
|
|
5915
|
+
...s
|
|
5902
5916
|
};
|
|
5903
5917
|
} catch {}
|
|
5904
5918
|
u.set(e.id, {
|
|
5905
5919
|
id: e.id,
|
|
5906
|
-
url:
|
|
5907
|
-
originalUrl:
|
|
5920
|
+
url: r,
|
|
5921
|
+
originalUrl: i,
|
|
5908
5922
|
parentAssetId: z(e.parentAssetId) || null,
|
|
5909
|
-
cropCoordinates:
|
|
5910
|
-
variants:
|
|
5923
|
+
cropCoordinates: a,
|
|
5924
|
+
variants: o && Object.keys(o).length > 0 ? o : void 0,
|
|
5911
5925
|
filename: e.filename,
|
|
5912
5926
|
mimeType: e.mimeType,
|
|
5913
|
-
title:
|
|
5914
|
-
alt:
|
|
5915
|
-
description:
|
|
5927
|
+
title: s.title || "",
|
|
5928
|
+
alt: s.alt || "",
|
|
5929
|
+
description: s.description || ""
|
|
5916
5930
|
});
|
|
5917
5931
|
}
|
|
5918
5932
|
let d = (e) => {
|
|
5919
5933
|
if (!e) return e;
|
|
5920
5934
|
let t = z(e);
|
|
5921
5935
|
if (t) {
|
|
5922
|
-
let n = u.get(t) ||
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
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
|
+
if (r || n?.variants) {
|
|
5938
|
+
c = {};
|
|
5939
|
+
let e = r || n?.variants;
|
|
5940
|
+
for (let [t, n] of Object.entries(e)) c[t] = d(n);
|
|
5941
|
+
}
|
|
5927
5942
|
return {
|
|
5928
|
-
...n,
|
|
5943
|
+
...n || {},
|
|
5929
5944
|
id: t,
|
|
5930
|
-
parentAssetId: n
|
|
5931
|
-
url:
|
|
5932
|
-
originalUrl:
|
|
5933
|
-
cropCoordinates: i || n
|
|
5934
|
-
variants:
|
|
5945
|
+
parentAssetId: n?.parentAssetId ? z(n.parentAssetId) : null,
|
|
5946
|
+
url: o,
|
|
5947
|
+
originalUrl: s,
|
|
5948
|
+
cropCoordinates: i || n?.cropCoordinates || null,
|
|
5949
|
+
variants: c,
|
|
5935
5950
|
metadataOverrides: a
|
|
5936
5951
|
};
|
|
5937
5952
|
}
|
|
@@ -6258,8 +6273,8 @@ async function he(e, t, n) {
|
|
|
6258
6273
|
async function ge(e, t, n) {
|
|
6259
6274
|
let r = {}, i = null;
|
|
6260
6275
|
if (t) {
|
|
6261
|
-
let
|
|
6262
|
-
for (let e of
|
|
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 || [];
|
|
6277
|
+
for (let e of o) {
|
|
6263
6278
|
let t = e.draftDataJson || e.dataJson;
|
|
6264
6279
|
if (t) try {
|
|
6265
6280
|
let e = typeof t == "string" ? JSON.parse(t) : t;
|
|
@@ -6271,7 +6286,7 @@ async function ge(e, t, n) {
|
|
|
6271
6286
|
if (!i) {
|
|
6272
6287
|
let t = await e.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(n) || -1, String(n));
|
|
6273
6288
|
if (t && t.dataJson) try {
|
|
6274
|
-
let e = typeof t.dataJson == "string" ? JSON.parse(t.dataJson) :
|
|
6289
|
+
let e = typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : e.dataJson;
|
|
6275
6290
|
e.subpageLayoutId && e.subpageLayoutId !== "inherit" && (i = e.subpageLayoutId);
|
|
6276
6291
|
} catch {}
|
|
6277
6292
|
}
|
|
@@ -6305,7 +6320,7 @@ H.get("/", async (e) => {
|
|
|
6305
6320
|
updatedAt: i.updatedAt
|
|
6306
6321
|
}, s = i.draftDataJson || i.dataJson;
|
|
6307
6322
|
if (s) try {
|
|
6308
|
-
let n = typeof s == "string" ? JSON.parse(s) : s, a = await t.prepare("SELECT
|
|
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 = se(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, l = n.layoutId || null;
|
|
6309
6324
|
if (a) {
|
|
6310
6325
|
let { resolvedLayoutId: e, inheritedFields: r } = await ge(t, a.parentId, a.treeId);
|
|
6311
6326
|
(l === "inherit" || !l) && (l = e);
|
|
@@ -6455,8 +6470,8 @@ H.get("/", async (e) => {
|
|
|
6455
6470
|
}
|
|
6456
6471
|
}
|
|
6457
6472
|
C && E && C === E && (C = null);
|
|
6458
|
-
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = s === void 0 ? null : U(s);
|
|
6459
|
-
if (
|
|
6473
|
+
let D = a, O = /* @__PURE__ */ new Set(), k = !1, A = "draft", j = 0, M = s === void 0 ? null : U(s);
|
|
6474
|
+
if (M) {
|
|
6460
6475
|
let n = [];
|
|
6461
6476
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
6462
6477
|
treeId: Number(e.treeId),
|
|
@@ -6470,26 +6485,26 @@ H.get("/", async (e) => {
|
|
|
6470
6485
|
});
|
|
6471
6486
|
}
|
|
6472
6487
|
for (let r of n) {
|
|
6473
|
-
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId,
|
|
6488
|
+
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId, M] : [
|
|
6474
6489
|
r.treeId,
|
|
6475
6490
|
r.parentId,
|
|
6476
|
-
|
|
6491
|
+
M
|
|
6477
6492
|
], o = `
|
|
6478
6493
|
SELECT cn.id FROM tree_nodes tn
|
|
6479
6494
|
INNER JOIN content_nodes cn ON tn.contentId = cn.id
|
|
6480
6495
|
WHERE tn.treeId = ? AND ${n} AND cn.slug = ? AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
6481
6496
|
`;
|
|
6482
6497
|
if (a && (o += " AND cn.id != ?", i.push(a)), o += " LIMIT 1", await t.prepare(o).get(...i)) return e.json({
|
|
6483
|
-
error: `The slug '${
|
|
6498
|
+
error: `The slug '${M}' is already in use by another page in this section.`,
|
|
6484
6499
|
field: "slug"
|
|
6485
6500
|
}, 409);
|
|
6486
6501
|
}
|
|
6487
6502
|
}
|
|
6488
6503
|
if (a) {
|
|
6489
|
-
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status FROM content_nodes WHERE id = ?").get(a);
|
|
6504
|
+
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
6490
6505
|
k = me(e, {
|
|
6491
6506
|
title: o,
|
|
6492
|
-
slug:
|
|
6507
|
+
slug: M,
|
|
6493
6508
|
isHidden: b,
|
|
6494
6509
|
sanitizedFields: v
|
|
6495
6510
|
});
|
|
@@ -6497,26 +6512,43 @@ H.get("/", async (e) => {
|
|
|
6497
6512
|
try {
|
|
6498
6513
|
pe(typeof n == "string" ? JSON.parse(n) : n, O);
|
|
6499
6514
|
} catch {}
|
|
6500
|
-
|
|
6501
|
-
let e = await t.prepare("SELECT dataJson FROM content_blocks WHERE contentId = ? AND isDraft = 1").all(a);
|
|
6502
|
-
(Array.isArray(e) ? e : e?.results || []).forEach((e) => {
|
|
6503
|
-
try {
|
|
6504
|
-
pe(typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson, O);
|
|
6505
|
-
} catch {}
|
|
6506
|
-
});
|
|
6507
|
-
}
|
|
6508
|
-
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 = {};
|
|
6515
|
+
let r = {};
|
|
6509
6516
|
try {
|
|
6510
|
-
|
|
6517
|
+
r = JSON.parse(n);
|
|
6511
6518
|
} catch {}
|
|
6512
|
-
let
|
|
6513
|
-
...
|
|
6519
|
+
let i = JSON.stringify({
|
|
6520
|
+
...r,
|
|
6514
6521
|
...v
|
|
6515
|
-
}),
|
|
6516
|
-
|
|
6522
|
+
}), l = !1;
|
|
6523
|
+
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) {
|
|
6524
|
+
for (let e of Object.keys(v)) if (JSON.stringify(v[e]) !== JSON.stringify(r[e])) {
|
|
6525
|
+
l = !0;
|
|
6526
|
+
break;
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
6529
|
+
if (!l && m !== void 0) {
|
|
6530
|
+
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 || [];
|
|
6531
|
+
if (m.length !== n.length) l = !0;
|
|
6532
|
+
else for (let e = 0; e < m.length; e++) {
|
|
6533
|
+
let t = m[e], r = n[e], i = t.componentId || t.elementType || "text-block", a = t.region || "content", o = { ...t.data || {} };
|
|
6534
|
+
delete o._instanceId, delete o.blockId;
|
|
6535
|
+
let s = {};
|
|
6536
|
+
try {
|
|
6537
|
+
s = JSON.parse(r.dataJson);
|
|
6538
|
+
} catch {}
|
|
6539
|
+
if (delete s._instanceId, delete s.blockId, i !== r.elementType || a !== r.region || JSON.stringify(o) !== JSON.stringify(s)) {
|
|
6540
|
+
l = !0;
|
|
6541
|
+
break;
|
|
6542
|
+
}
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
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;
|
|
6546
|
+
A = e?.status === "published" || e?.publishedAt ? "published" : "draft";
|
|
6547
|
+
let h = e?.hasUnpublishedChanges === 1 || e?.hasUnpublishedChanges === !0;
|
|
6548
|
+
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);
|
|
6517
6549
|
} else {
|
|
6518
6550
|
k = !0;
|
|
6519
|
-
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",
|
|
6551
|
+
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);
|
|
6520
6552
|
D = Number(e.lastInsertRowid);
|
|
6521
6553
|
}
|
|
6522
6554
|
if (h !== void 0 && Array.isArray(h) && D) {
|
|
@@ -6529,10 +6561,10 @@ H.get("/", async (e) => {
|
|
|
6529
6561
|
}
|
|
6530
6562
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
6531
6563
|
if (!e || !e.treeId) continue;
|
|
6532
|
-
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
|
|
6533
|
-
a ? ((a.parentId !== r || a.sortOrder !== i) && (k = !0), await t.prepare("UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE
|
|
6564
|
+
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);
|
|
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));
|
|
6534
6566
|
}
|
|
6535
|
-
let
|
|
6567
|
+
let N = [];
|
|
6536
6568
|
if (m !== void 0 && Array.isArray(m) && D) {
|
|
6537
6569
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
6538
6570
|
let e = [], n = [];
|
|
@@ -6542,7 +6574,7 @@ H.get("/", async (e) => {
|
|
|
6542
6574
|
blockId: o,
|
|
6543
6575
|
_instanceId: o
|
|
6544
6576
|
});
|
|
6545
|
-
c.forEach((e) =>
|
|
6577
|
+
c.forEach((e) => N.push({
|
|
6546
6578
|
...e,
|
|
6547
6579
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
6548
6580
|
}));
|
|
@@ -6552,7 +6584,7 @@ H.get("/", async (e) => {
|
|
|
6552
6584
|
e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
6553
6585
|
}
|
|
6554
6586
|
if (D) {
|
|
6555
|
-
let n = [...y, ...
|
|
6587
|
+
let n = [...y, ...N];
|
|
6556
6588
|
await oe(t, D, n);
|
|
6557
6589
|
let r = new Set(n.map((e) => e.assetId)), i = new Set([...O].filter((e) => !r.has(e)));
|
|
6558
6590
|
if (i.size > 0) {
|
|
@@ -6563,7 +6595,8 @@ H.get("/", async (e) => {
|
|
|
6563
6595
|
return await I(e).clear(), e.json({
|
|
6564
6596
|
success: !0,
|
|
6565
6597
|
id: D,
|
|
6566
|
-
status:
|
|
6598
|
+
status: A,
|
|
6599
|
+
hasUnpublishedChanges: j === 1 || A === "draft",
|
|
6567
6600
|
isStructuralChange: k
|
|
6568
6601
|
});
|
|
6569
6602
|
}), H.post("/publish", async (e) => {
|
|
@@ -6681,7 +6714,7 @@ function _e(e, t = null) {
|
|
|
6681
6714
|
for (let r = 0; r < e.length; r++) {
|
|
6682
6715
|
let i = e[r];
|
|
6683
6716
|
if (!i) continue;
|
|
6684
|
-
let a = i.
|
|
6717
|
+
let a = i.id || i.contentId;
|
|
6685
6718
|
if (!a || typeof a == "string" && a.startsWith("draft-")) continue;
|
|
6686
6719
|
let o = Number(a);
|
|
6687
6720
|
isNaN(o) || (n.push({
|
|
@@ -6711,7 +6744,7 @@ W.get("/tree.json", async (e) => {
|
|
|
6711
6744
|
e && e.id && (i = Number(e.id));
|
|
6712
6745
|
}
|
|
6713
6746
|
} else i = Number(n);
|
|
6714
|
-
let a = await t.prepare("\n SELECT \n t.
|
|
6747
|
+
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();
|
|
6715
6748
|
for (let e of o) {
|
|
6716
6749
|
let t = e.contentId;
|
|
6717
6750
|
c.has(t) || (c.add(t), s.push(e));
|
|
@@ -6733,16 +6766,19 @@ W.get("/tree.json", async (e) => {
|
|
|
6733
6766
|
return {
|
|
6734
6767
|
...o,
|
|
6735
6768
|
id: e.contentId,
|
|
6736
|
-
treeNodeId: e.
|
|
6769
|
+
treeNodeId: e.contentId,
|
|
6737
6770
|
parentId: e.parentId || null,
|
|
6738
6771
|
language: e.language?.trim() || null,
|
|
6739
6772
|
hidden: +!!s,
|
|
6740
6773
|
isHidden: s,
|
|
6741
6774
|
status: e.status || "draft",
|
|
6775
|
+
isDraft: e.status === "draft",
|
|
6742
6776
|
publishedAt: e.publishedAt || null,
|
|
6743
6777
|
hasUnpublishedChanges: c,
|
|
6744
6778
|
assetCount: e.assetCount || 0,
|
|
6745
|
-
|
|
6779
|
+
dataJson: e.dataJson ? typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson : null,
|
|
6780
|
+
draftDataJson: e.draftDataJson ? typeof e.draftDataJson == "string" ? JSON.parse(e.draftDataJson) : e.draftDataJson : null,
|
|
6781
|
+
children: l(e.contentId)
|
|
6746
6782
|
};
|
|
6747
6783
|
}).filter((e) => r || !e.hidden);
|
|
6748
6784
|
}
|
|
@@ -6765,11 +6801,11 @@ W.get("/tree.json", async (e) => {
|
|
|
6765
6801
|
let r = _e(n.tree, null);
|
|
6766
6802
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
6767
6803
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
6768
|
-
s += "parentId = CASE
|
|
6804
|
+
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
6769
6805
|
s += "WHEN ? THEN ? \n";
|
|
6770
|
-
}), s += "ELSE parentId END, \n", s += "sortOrder = CASE
|
|
6806
|
+
}), s += "ELSE parentId END, \n", s += "sortOrder = CASE contentId \n", n.forEach(() => {
|
|
6771
6807
|
s += "WHEN ? THEN ? \n";
|
|
6772
|
-
}), s += "ELSE sortOrder END \n", s += `WHERE
|
|
6808
|
+
}), s += "ELSE sortOrder END \n", s += `WHERE contentId IN (${a}) AND treeId = ?`;
|
|
6773
6809
|
let c = [];
|
|
6774
6810
|
n.forEach((e) => {
|
|
6775
6811
|
c.push(e.id, e.parentId);
|
|
@@ -6830,18 +6866,21 @@ W.get("/tree.json", async (e) => {
|
|
|
6830
6866
|
SELECT COALESCE(MAX(sortOrder), -1) + 1 as nextSort
|
|
6831
6867
|
FROM tree_nodes
|
|
6832
6868
|
WHERE treeId = ? AND ${p}
|
|
6833
|
-
`).get(...v))?.nextSort ?? 0
|
|
6834
|
-
|
|
6835
|
-
let
|
|
6836
|
-
|
|
6837
|
-
|
|
6869
|
+
`).get(...v))?.nextSort ?? 0;
|
|
6870
|
+
await t.prepare("\n INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(o, f, g, y);
|
|
6871
|
+
let b = [];
|
|
6872
|
+
n.channels && Array.isArray(n.channels) ? b = n.channels : n.channelId && n.channelId !== "all" && (b = [n.channelId]);
|
|
6873
|
+
let x = [...new Set(b)].filter((e) => e && e !== "all").map((e) => Number(e));
|
|
6874
|
+
if (x.length > 0) {
|
|
6875
|
+
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [f, e]);
|
|
6838
6876
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
6839
6877
|
}
|
|
6840
6878
|
return await i.clear(), e.json({
|
|
6841
6879
|
success: !0,
|
|
6842
6880
|
id: f,
|
|
6843
|
-
treeNodeId:
|
|
6844
|
-
status: "draft"
|
|
6881
|
+
treeNodeId: f,
|
|
6882
|
+
status: "draft",
|
|
6883
|
+
isDraft: !0
|
|
6845
6884
|
}, 201);
|
|
6846
6885
|
}
|
|
6847
6886
|
if (s === "attach") {
|
|
@@ -6873,16 +6912,14 @@ W.get("/tree.json", async (e) => {
|
|
|
6873
6912
|
field: "slug"
|
|
6874
6913
|
}, 409);
|
|
6875
6914
|
}
|
|
6876
|
-
await t.prepare("DELETE FROM tree_nodes WHERE treeId = ? AND contentId = ?").run(o, d)
|
|
6877
|
-
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);
|
|
6878
|
-
return await i.clear(), a.purgeNode(e, t, d, !0), e.json({
|
|
6915
|
+
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({
|
|
6879
6916
|
success: !0,
|
|
6880
|
-
treeNodeId:
|
|
6917
|
+
treeNodeId: d
|
|
6881
6918
|
});
|
|
6882
6919
|
}
|
|
6883
6920
|
if (s === "detach") {
|
|
6884
|
-
let r = n.
|
|
6885
|
-
return r ? (await t.prepare("\n UPDATE tree_nodes \n SET parentId = (SELECT parentId FROM tree_nodes WHERE
|
|
6921
|
+
let r = n.contentId || n.id || n.treeNodeId;
|
|
6922
|
+
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);
|
|
6886
6923
|
}
|
|
6887
6924
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
6888
6925
|
} catch (t) {
|
|
@@ -7759,7 +7796,7 @@ X.get("/", async (e) => {
|
|
|
7759
7796
|
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)]);
|
|
7760
7797
|
if (e.length === 0) v.push("1 = 0");
|
|
7761
7798
|
else {
|
|
7762
|
-
let t = e.map((e) => e.isSystemVariant ? `(a.id = '${e.id}' OR
|
|
7799
|
+
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 ");
|
|
7763
7800
|
v.push(`(${t})`);
|
|
7764
7801
|
}
|
|
7765
7802
|
}
|
|
@@ -7770,9 +7807,24 @@ X.get("/", async (e) => {
|
|
|
7770
7807
|
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/%")));
|
|
7771
7808
|
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 ?`;
|
|
7772
7809
|
_.push(p, m);
|
|
7773
|
-
let b = await Z(t, y, _), x = b.map((e) => e.id), S = /* @__PURE__ */ new Map();
|
|
7774
|
-
x.length > 0
|
|
7775
|
-
|
|
7810
|
+
let b = await Z(t, y, _), x = b.map((e) => e.id), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map();
|
|
7811
|
+
if (x.length > 0) {
|
|
7812
|
+
let e = x.map(() => "?").join(",");
|
|
7813
|
+
(await Z(t, `
|
|
7814
|
+
SELECT master.id AS assetId, COUNT(DISTINCT na.nodeId) AS count
|
|
7815
|
+
FROM assets master
|
|
7816
|
+
INNER JOIN node_assets na ON (
|
|
7817
|
+
na.assetId = master.id OR
|
|
7818
|
+
EXISTS (SELECT 1 FROM assets crop WHERE crop.id = na.assetId AND crop.isSystemVariant = 1 AND crop.parentAssetId = master.id)
|
|
7819
|
+
)
|
|
7820
|
+
WHERE master.id IN (${e})
|
|
7821
|
+
GROUP BY master.id`, x)).forEach((e) => S.set(String(e.assetId), e.count || 0)), (await Z(t, `
|
|
7822
|
+
SELECT parentAssetId, COUNT(id) AS count
|
|
7823
|
+
FROM assets
|
|
7824
|
+
WHERE isSystemVariant = 1 AND parentAssetId IN (${e})
|
|
7825
|
+
GROUP BY parentAssetId`, x)).forEach((e) => C.set(String(e.parentAssetId), e.count || 0));
|
|
7826
|
+
}
|
|
7827
|
+
let w = b.map((t) => {
|
|
7776
7828
|
let n = {
|
|
7777
7829
|
title: "",
|
|
7778
7830
|
alt: "",
|
|
@@ -7797,11 +7849,12 @@ X.get("/", async (e) => {
|
|
|
7797
7849
|
updatedAt: t.updatedAt,
|
|
7798
7850
|
deletedAt: t.deletedAt || null,
|
|
7799
7851
|
usageCount: S.get(String(t.id)) || 0,
|
|
7852
|
+
variantCount: C.get(String(t.id)) || 0,
|
|
7800
7853
|
url: r,
|
|
7801
7854
|
originalUrl: r
|
|
7802
7855
|
};
|
|
7803
7856
|
});
|
|
7804
|
-
return e.json(
|
|
7857
|
+
return e.json(w);
|
|
7805
7858
|
} catch (t) {
|
|
7806
7859
|
return e.json({
|
|
7807
7860
|
error: "Failed to fetch assets",
|
|
@@ -7810,50 +7863,82 @@ X.get("/", async (e) => {
|
|
|
7810
7863
|
}
|
|
7811
7864
|
}), X.post("/upload", async (e) => {
|
|
7812
7865
|
try {
|
|
7813
|
-
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,
|
|
7814
|
-
|
|
7815
|
-
let
|
|
7816
|
-
if (
|
|
7817
|
-
if (typeof
|
|
7818
|
-
|
|
7866
|
+
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;
|
|
7867
|
+
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
7868
|
+
let d = r.cropCoordinates, f = null, p = null;
|
|
7869
|
+
if (d) {
|
|
7870
|
+
if (typeof d == "string") {
|
|
7871
|
+
f = d;
|
|
7819
7872
|
try {
|
|
7820
|
-
|
|
7873
|
+
p = JSON.parse(d);
|
|
7821
7874
|
} catch {}
|
|
7822
|
-
} else
|
|
7875
|
+
} else f = JSON.stringify(d), p = d;
|
|
7823
7876
|
}
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7877
|
+
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}`;
|
|
7878
|
+
if (!y) throw Error("Storage provider failed to return a valid storage key");
|
|
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
|
+
E && (await Z(t, "SELECT id FROM users WHERE id = ?", [E])).length === 0 && (E = null);
|
|
7881
|
+
let D = new V(e.env);
|
|
7882
|
+
if (s) {
|
|
7883
|
+
let r = await Z(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
7884
|
+
if (r.length > 0) {
|
|
7885
|
+
let a = r[0];
|
|
7886
|
+
if (await Q(t, "UPDATE assets SET filename = ?, mimeType = ?, sizeBytes = ?, storageKeyPrivate = ?, cdnUrl = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
7887
|
+
i.name,
|
|
7888
|
+
C,
|
|
7889
|
+
w,
|
|
7890
|
+
y,
|
|
7891
|
+
S,
|
|
7892
|
+
s
|
|
7893
|
+
]), a.storageKeyPrivate) try {
|
|
7894
|
+
await n.delete(a.storageKeyPrivate);
|
|
7895
|
+
} catch (e) {
|
|
7896
|
+
console.warn("Failed to cleanup old asset", e);
|
|
7897
|
+
}
|
|
7898
|
+
D.purgeAsset(e, t, s);
|
|
7899
|
+
let o = `${S}?v=${Date.now()}`;
|
|
7900
|
+
return e.json({
|
|
7901
|
+
id: s,
|
|
7902
|
+
url: o,
|
|
7903
|
+
originalUrl: o,
|
|
7904
|
+
parentAssetId: a.parentAssetId,
|
|
7905
|
+
cropCoordinates: p,
|
|
7906
|
+
filename: i.name,
|
|
7907
|
+
mimeType: C,
|
|
7908
|
+
usageCount: 0,
|
|
7909
|
+
isSystemVariant: !!a.isSystemVariant,
|
|
7910
|
+
replaced: !0
|
|
7911
|
+
}, 200);
|
|
7912
|
+
}
|
|
7913
|
+
}
|
|
7914
|
+
let O = `ast_${m}`, k = +!!g;
|
|
7830
7915
|
await Q(t, "INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
7831
|
-
|
|
7916
|
+
O,
|
|
7832
7917
|
i.name,
|
|
7833
|
-
S,
|
|
7834
7918
|
C,
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7919
|
+
w,
|
|
7920
|
+
y,
|
|
7921
|
+
S,
|
|
7838
7922
|
E,
|
|
7839
|
-
|
|
7840
|
-
u
|
|
7923
|
+
k,
|
|
7924
|
+
u,
|
|
7925
|
+
f
|
|
7841
7926
|
]);
|
|
7842
|
-
let
|
|
7843
|
-
if (
|
|
7844
|
-
let n = await Z(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [
|
|
7845
|
-
n.length > 0 && (
|
|
7927
|
+
let A = S;
|
|
7928
|
+
if (u) {
|
|
7929
|
+
let n = await Z(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [u]);
|
|
7930
|
+
n.length > 0 && (A = Re(n[0].cdnUrl, n[0].storageKeyPrivate, b)), D.purgeAsset(e, t, u);
|
|
7846
7931
|
}
|
|
7847
7932
|
return e.json({
|
|
7848
|
-
id:
|
|
7849
|
-
url:
|
|
7850
|
-
originalUrl:
|
|
7851
|
-
parentAssetId:
|
|
7852
|
-
cropCoordinates:
|
|
7933
|
+
id: O,
|
|
7934
|
+
url: S,
|
|
7935
|
+
originalUrl: A,
|
|
7936
|
+
parentAssetId: u,
|
|
7937
|
+
cropCoordinates: p,
|
|
7853
7938
|
filename: i.name,
|
|
7854
|
-
mimeType:
|
|
7939
|
+
mimeType: C,
|
|
7855
7940
|
usageCount: 0,
|
|
7856
|
-
isSystemVariant: !!
|
|
7941
|
+
isSystemVariant: !!k
|
|
7857
7942
|
}, 201);
|
|
7858
7943
|
} catch (t) {
|
|
7859
7944
|
return console.error("❌ [Asset Upload Crash Details]:", t), e.json({
|
|
@@ -7865,26 +7950,18 @@ X.get("/", async (e) => {
|
|
|
7865
7950
|
try {
|
|
7866
7951
|
let t = l(e), n = e.req.param("id"), r = await Z(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
7867
7952
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
7868
|
-
let i = r[0], a =
|
|
7869
|
-
n,
|
|
7870
|
-
`crop_%${a}%`,
|
|
7871
|
-
`%${n}%`
|
|
7872
|
-
]), 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", [
|
|
7873
|
-
n,
|
|
7874
|
-
`crop_%${a}%`,
|
|
7875
|
-
`%${n}%`
|
|
7876
|
-
]), c = {
|
|
7953
|
+
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 = {
|
|
7877
7954
|
title: "",
|
|
7878
7955
|
alt: "",
|
|
7879
7956
|
description: ""
|
|
7880
7957
|
};
|
|
7881
7958
|
try {
|
|
7882
|
-
|
|
7883
|
-
...
|
|
7959
|
+
s = {
|
|
7960
|
+
...s,
|
|
7884
7961
|
...JSON.parse(i.dataJson || "{}")
|
|
7885
7962
|
};
|
|
7886
7963
|
} catch {}
|
|
7887
|
-
let u = Re(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)
|
|
7964
|
+
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), u = `${Re(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)}?v=${c}`;
|
|
7888
7965
|
return e.json({
|
|
7889
7966
|
id: i.id,
|
|
7890
7967
|
filename: i.filename,
|
|
@@ -7892,17 +7969,18 @@ X.get("/", async (e) => {
|
|
|
7892
7969
|
sizeBytes: i.sizeBytes,
|
|
7893
7970
|
createdAt: i.createdAt,
|
|
7894
7971
|
updatedAt: i.updatedAt,
|
|
7895
|
-
title:
|
|
7896
|
-
alt:
|
|
7897
|
-
description:
|
|
7972
|
+
title: s.title || "",
|
|
7973
|
+
alt: s.alt || "",
|
|
7974
|
+
description: s.description || "",
|
|
7898
7975
|
url: u,
|
|
7899
7976
|
originalUrl: u,
|
|
7900
|
-
connectedNodes:
|
|
7901
|
-
variants:
|
|
7977
|
+
connectedNodes: a,
|
|
7978
|
+
variants: o.map((t) => {
|
|
7902
7979
|
let n = null;
|
|
7903
7980
|
if (t.cropCoordinatesJson) try {
|
|
7904
7981
|
n = JSON.parse(t.cropCoordinatesJson);
|
|
7905
7982
|
} catch {}
|
|
7983
|
+
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a = Re(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
7906
7984
|
return {
|
|
7907
7985
|
id: t.id,
|
|
7908
7986
|
filename: t.filename,
|
|
@@ -7911,7 +7989,7 @@ X.get("/", async (e) => {
|
|
|
7911
7989
|
createdAt: t.createdAt,
|
|
7912
7990
|
parentAssetId: t.parentAssetId || i.id,
|
|
7913
7991
|
cropCoordinates: n,
|
|
7914
|
-
url:
|
|
7992
|
+
url: `${a}?v=${r}`,
|
|
7915
7993
|
originalUrl: u
|
|
7916
7994
|
};
|
|
7917
7995
|
})
|
|
@@ -7938,12 +8016,7 @@ X.get("/", async (e) => {
|
|
|
7938
8016
|
}), X.delete("/:id", async (e) => {
|
|
7939
8017
|
try {
|
|
7940
8018
|
let t = l(e), n = e.req.param("id"), r = (await Z(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
7941
|
-
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
|
|
7942
|
-
n,
|
|
7943
|
-
n,
|
|
7944
|
-
`crop_%${r.filename ? r.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
7945
|
-
`%${n}%`
|
|
7946
|
-
]), e.json({
|
|
8019
|
+
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({
|
|
7947
8020
|
success: !0,
|
|
7948
8021
|
id: n,
|
|
7949
8022
|
trashed: !0
|
|
@@ -7957,18 +8030,11 @@ X.get("/", async (e) => {
|
|
|
7957
8030
|
}), X.post("/restore", async (e) => {
|
|
7958
8031
|
try {
|
|
7959
8032
|
let t = l(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
7960
|
-
|
|
7961
|
-
let i = (await Z(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0];
|
|
7962
|
-
return i ? (await Q(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR parentAssetId = ? OR (isSystemVariant = 1 AND (filename LIKE ? OR filename LIKE ?))", [
|
|
7963
|
-
r,
|
|
7964
|
-
r,
|
|
7965
|
-
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
7966
|
-
`%${r}%`
|
|
7967
|
-
]), new V(e.env).purgeAsset(e, t, r), e.json({
|
|
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 V(e.env).purgeAsset(e, t, r), e.json({
|
|
7968
8034
|
success: !0,
|
|
7969
8035
|
id: r,
|
|
7970
8036
|
restored: !0
|
|
7971
|
-
})) : e.json({ error: "Asset not found" }, 404);
|
|
8037
|
+
})) : e.json({ error: "Asset not found" }, 404) : e.json({ error: "Asset ID required" }, 400);
|
|
7972
8038
|
} catch (t) {
|
|
7973
8039
|
return e.json({
|
|
7974
8040
|
error: "Failed to restore asset",
|
|
@@ -7981,11 +8047,7 @@ X.get("/", async (e) => {
|
|
|
7981
8047
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
7982
8048
|
new V(e.env).purgeAsset(e, t, r);
|
|
7983
8049
|
let a = [i];
|
|
7984
|
-
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE
|
|
7985
|
-
r,
|
|
7986
|
-
`crop_%${i.filename ? i.filename.replace(/\.[^/.]+$/, "") : ""}%`,
|
|
7987
|
-
`%${r}%`
|
|
7988
|
-
])]);
|
|
8050
|
+
i.isSystemVariant || (a = [i, ...await Z(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
7989
8051
|
let o = a.map((e) => e.id);
|
|
7990
8052
|
if (typeof n.delete == "function") {
|
|
7991
8053
|
for (let e of a) if (e.storageKeyPrivate) try {
|
|
@@ -8066,47 +8128,47 @@ async function Ue(e, t, n, r) {
|
|
|
8066
8128
|
}
|
|
8067
8129
|
}));
|
|
8068
8130
|
}
|
|
8069
|
-
async function We(e, t, n, r, i = !1,
|
|
8131
|
+
async function We(e, t, n, r, i, a = !1, o) {
|
|
8070
8132
|
if (!t) return { blocks: [] };
|
|
8071
|
-
let
|
|
8072
|
-
if (!
|
|
8073
|
-
let
|
|
8074
|
-
if (
|
|
8075
|
-
let
|
|
8076
|
-
|
|
8133
|
+
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 || [];
|
|
8134
|
+
if (!c || c.length === 0) return { blocks: [] };
|
|
8135
|
+
let l = c.map((e) => e.contentId).filter((e) => e != null);
|
|
8136
|
+
if (l.length === 0) return { blocks: [] };
|
|
8137
|
+
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();
|
|
8138
|
+
p.forEach((e) => {
|
|
8077
8139
|
let t = String(e.contentId);
|
|
8078
|
-
|
|
8140
|
+
m.has(t) || m.set(t, []), m.get(t).push(e);
|
|
8079
8141
|
});
|
|
8080
|
-
for (let t of
|
|
8081
|
-
let
|
|
8082
|
-
if (
|
|
8083
|
-
let o = /* @__PURE__ */ new Set([
|
|
8142
|
+
for (let t of c) {
|
|
8143
|
+
let n = m.get(String(t.contentId)) || [];
|
|
8144
|
+
if (n.filter((e) => e.region === r).length === 0) continue;
|
|
8145
|
+
let o = /* @__PURE__ */ new Set([r]), s = !0;
|
|
8084
8146
|
for (; s;) {
|
|
8085
8147
|
s = !1;
|
|
8086
|
-
for (let e of
|
|
8148
|
+
for (let e of n) {
|
|
8087
8149
|
if (!o.has(e.region)) continue;
|
|
8088
8150
|
let t = {};
|
|
8089
8151
|
try {
|
|
8090
8152
|
t = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
8091
8153
|
} catch {}
|
|
8092
|
-
let
|
|
8093
|
-
for (let e of
|
|
8154
|
+
let r = String(e.id), i = String(t.blockId || t._instanceId || t.id || e.blockId);
|
|
8155
|
+
for (let e of n) {
|
|
8094
8156
|
if (!e.region || o.has(e.region)) continue;
|
|
8095
8157
|
let t = e.region;
|
|
8096
|
-
(t.startsWith(`${
|
|
8158
|
+
(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);
|
|
8097
8159
|
}
|
|
8098
8160
|
}
|
|
8099
8161
|
}
|
|
8100
|
-
let c = await Promise.all(
|
|
8101
|
-
let
|
|
8162
|
+
let c = await Promise.all(n.filter((e) => o.has(e.region)).map(async (t) => {
|
|
8163
|
+
let n = {};
|
|
8102
8164
|
try {
|
|
8103
|
-
|
|
8165
|
+
n = (typeof t.dataJson == "string" ? JSON.parse(t.dataJson) : t.dataJson) || {};
|
|
8104
8166
|
} catch {}
|
|
8105
|
-
let o =
|
|
8106
|
-
if (!
|
|
8107
|
-
let c = t.elementType || t.componentId || "text-block", l =
|
|
8167
|
+
let o = n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = He(n.startShowingAt, n.stopShowingAt);
|
|
8168
|
+
if (!a && (o || !s)) return null;
|
|
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);
|
|
8108
8170
|
return d = await B(e, d), d = Ke(d), d.blockId = u, {
|
|
8109
|
-
region: t.region ||
|
|
8171
|
+
region: t.region || r,
|
|
8110
8172
|
block: {
|
|
8111
8173
|
instanceId: t.id,
|
|
8112
8174
|
blockId: u,
|
|
@@ -8116,8 +8178,8 @@ async function We(e, t, n, r, i = !1, a) {
|
|
|
8116
8178
|
};
|
|
8117
8179
|
})), l = {};
|
|
8118
8180
|
for (let e of c) e && (l[e.region] || (l[e.region] = []), l[e.region].push(e.block));
|
|
8119
|
-
if (l[
|
|
8120
|
-
blocks: l[
|
|
8181
|
+
if (l[r] && l[r].length > 0) return {
|
|
8182
|
+
blocks: l[r],
|
|
8121
8183
|
subRegions: l,
|
|
8122
8184
|
inheritedFromId: String(t.contentId),
|
|
8123
8185
|
inheritedFromTitle: t.title || t.slug
|
|
@@ -8233,7 +8295,7 @@ async function Je(e, t, n) {
|
|
|
8233
8295
|
async function Ye(e, t, n, r) {
|
|
8234
8296
|
let i = Ve(t, n), a = r.treeEdges.get(i);
|
|
8235
8297
|
if (a) return a;
|
|
8236
|
-
let o = e.prepare("SELECT
|
|
8298
|
+
let o = e.prepare("SELECT contentId as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
|
|
8237
8299
|
return r.treeEdges.set(i, Promise.resolve(o)), o;
|
|
8238
8300
|
}
|
|
8239
8301
|
async function Xe(e, t, n) {
|
|
@@ -8293,7 +8355,7 @@ async function $e(e, t, n, r) {
|
|
|
8293
8355
|
if (e) return e;
|
|
8294
8356
|
}
|
|
8295
8357
|
let a = (async () => {
|
|
8296
|
-
let r = await e.prepare("\n WITH RECURSIVE ancestor_path(
|
|
8358
|
+
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 = [];
|
|
8297
8359
|
for (let e of i) {
|
|
8298
8360
|
let t = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
8299
8361
|
t === "home" || t === "homee" ? i.length === 1 && (a.length = 0) : t && a.push(t);
|
|
@@ -8305,7 +8367,7 @@ async function $e(e, t, n, r) {
|
|
|
8305
8367
|
async function et(e, t, n, r, i) {
|
|
8306
8368
|
let a = {}, o = null;
|
|
8307
8369
|
if (t) {
|
|
8308
|
-
let
|
|
8370
|
+
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([
|
|
8309
8371
|
"subpageLayoutId",
|
|
8310
8372
|
"layoutId",
|
|
8311
8373
|
"slug",
|
|
@@ -8319,12 +8381,12 @@ async function et(e, t, n, r, i) {
|
|
|
8319
8381
|
"hidden",
|
|
8320
8382
|
"status"
|
|
8321
8383
|
]);
|
|
8322
|
-
for (let e of
|
|
8384
|
+
for (let e of s) {
|
|
8323
8385
|
let t = r && e.draftDataJson || e.dataJson;
|
|
8324
8386
|
if (t) try {
|
|
8325
8387
|
let e = typeof t == "string" ? JSON.parse(t) : t;
|
|
8326
8388
|
!o && e.subpageLayoutId && e.subpageLayoutId !== "inherit" && (o = e.subpageLayoutId);
|
|
8327
|
-
for (let [t, n] of Object.entries(e)) n != null && n !== "" && n !== "inherit" && !
|
|
8389
|
+
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);
|
|
8328
8390
|
} catch {}
|
|
8329
8391
|
}
|
|
8330
8392
|
}
|
|
@@ -8358,7 +8420,7 @@ ze.get("/*", async (e) => {
|
|
|
8358
8420
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
8359
8421
|
if (!s && l) return e.json({ error: `Channel '${c.key || a}' is currently inactive` }, 404);
|
|
8360
8422
|
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 = `
|
|
8361
|
-
SELECT cn.*, tn.
|
|
8423
|
+
SELECT cn.*, tn.contentId as treeNodeId, tn.parentId, tn.treeId FROM content_nodes cn
|
|
8362
8424
|
INNER JOIN tree_nodes tn ON cn.id = tn.contentId
|
|
8363
8425
|
${u === null ? "" : "INNER JOIN node_channels nc ON cn.id = nc.nodeId"}
|
|
8364
8426
|
WHERE cn.slug = ? ${u === null ? "" : "AND nc.channelId = ?"}
|
|
@@ -8379,7 +8441,7 @@ ze.get("/*", async (e) => {
|
|
|
8379
8441
|
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);
|
|
8380
8442
|
if (!g) {
|
|
8381
8443
|
let e = _ ? [h.id, _] : [h.id];
|
|
8382
|
-
g = await t.prepare(`SELECT
|
|
8444
|
+
g = await t.prepare(`SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${_ ? "AND treeId = ?" : ""} LIMIT 1`).get(...e);
|
|
8383
8445
|
}
|
|
8384
8446
|
let T = g?.treeId || _ || "main-nav", E = null;
|
|
8385
8447
|
if (T) {
|
|
@@ -8430,7 +8492,7 @@ ze.get("/*", async (e) => {
|
|
|
8430
8492
|
if (!s && (de || fe || pe && !me)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
8431
8493
|
let he = [];
|
|
8432
8494
|
if (g?.treeNodeId) {
|
|
8433
|
-
let e = await t.prepare("\n SELECT t.
|
|
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(g.treeNodeId, T), n = Array.isArray(e) ? e : e?.results || [], r = P.path === "/" ? "" : P.path;
|
|
8434
8496
|
he = n.map((e) => {
|
|
8435
8497
|
let t = {}, n = s && e.draftDataJson || e.dataJson;
|
|
8436
8498
|
if (!n) return null;
|
|
@@ -8483,7 +8545,7 @@ ze.get("/*", async (e) => {
|
|
|
8483
8545
|
for (let [e, r] of Object.entries(K)) {
|
|
8484
8546
|
let i = G[e] && G[e].length > 0, a = !!ne[e];
|
|
8485
8547
|
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) {
|
|
8486
|
-
let r = await We(t, N, e, p, s, n);
|
|
8548
|
+
let r = await We(t, N, String(T), e, p, s, n);
|
|
8487
8549
|
if (r.blocks.length > 0 && (G[e] = r.blocks, ve[e] = {
|
|
8488
8550
|
isInherited: !0,
|
|
8489
8551
|
inheritedFromId: r.inheritedFromId,
|
|
@@ -8567,7 +8629,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8567
8629
|
}
|
|
8568
8630
|
let g = [];
|
|
8569
8631
|
if (m !== null) {
|
|
8570
|
-
let e = await t.prepare("\n SELECT \n t.
|
|
8632
|
+
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);
|
|
8571
8633
|
g = Array.isArray(e) ? e : e?.results || [];
|
|
8572
8634
|
}
|
|
8573
8635
|
if ((!g || g.length === 0) && !c) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
@@ -8578,7 +8640,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8578
8640
|
}
|
|
8579
8641
|
let v = /* @__PURE__ */ new Map();
|
|
8580
8642
|
for (let e of g) {
|
|
8581
|
-
let t = String(e.
|
|
8643
|
+
let t = String(e.id), n = a && e.draftDataJson ? e.draftDataJson : e.dataJson;
|
|
8582
8644
|
if (!n) {
|
|
8583
8645
|
v.set(t, {});
|
|
8584
8646
|
continue;
|
|
@@ -8593,11 +8655,11 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8593
8655
|
function y(e = null, t = "") {
|
|
8594
8656
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e);
|
|
8595
8657
|
return (_.get(n) || []).map((e) => {
|
|
8596
|
-
let n = v.get(String(e.
|
|
8658
|
+
let n = v.get(String(e.id)) || {}, r = {};
|
|
8597
8659
|
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);
|
|
8598
8660
|
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 = {
|
|
8599
8661
|
id: e.id,
|
|
8600
|
-
treeNodeId: e.
|
|
8662
|
+
treeNodeId: e.id,
|
|
8601
8663
|
parentId: e.parentId || null,
|
|
8602
8664
|
title: e.title,
|
|
8603
8665
|
slug: c,
|
|
@@ -8609,7 +8671,7 @@ rt.get("/:treeParam", async (e) => {
|
|
|
8609
8671
|
};
|
|
8610
8672
|
e.nodeType === "external-link" && (r.url && (f.url = r.url), r.target && (f.target = r.target));
|
|
8611
8673
|
let p = l === "/" ? "" : l;
|
|
8612
|
-
return f.children = y(e.
|
|
8674
|
+
return f.children = y(e.id, p), f;
|
|
8613
8675
|
}).filter((e) => a || !e.hidden);
|
|
8614
8676
|
}
|
|
8615
8677
|
let b = {
|