@brightsideoy/kama 1.0.0-alpha.2 → 1.0.0-alpha.3
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/bin/cli.js +263 -145
- package/content/definitions/field-sets/channel-base.yaml +7 -0
- package/dist/assets/index-C3LzwJjY.css +1 -0
- package/dist/assets/index-DhguVxzs.js +164 -0
- package/dist/{dist-Dy7-HUEG.js → dist-cK3xGnBZ.js} +940 -785
- package/dist/index.html +2 -2
- package/dist/index.js +982 -823
- package/dist/schema-compiler.js +5 -5
- package/package.json +2 -1
- package/schema.sql +19 -1
- package/templates/astro-starter/src/components/global/Breadcrumb.astro +50 -9
- package/templates/astro-starter/src/components/global/Footer.astro +7 -46
- package/templates/astro-starter/src/components/global/Header.astro +10 -16
- package/templates/astro-starter/src/components/global/NavigationMenu.astro +57 -46
- package/templates/astro-starter/src/layouts/StandardLayout.astro +5 -5
- package/templates/astro-starter/src/lib/cms.ts +22 -2
- package/templates/astro-starter/src/middleware.ts +7 -50
- package/templates/astro-starter/src/pages/[...slug].astro +30 -24
- package/templates/kama-worker/index.js +3 -3
- package/templates/kama-worker/server.js +11 -5
- package/dist/assets/index-F2rfUymo.css +0 -1
- package/dist/assets/index-lXxH3VFK.js +0 -164
|
@@ -278,7 +278,7 @@ function D(e, t) {
|
|
|
278
278
|
}
|
|
279
279
|
function te(e) {
|
|
280
280
|
e.ZodType.prototype.openapi === void 0 && (e.ZodType.prototype.openapi = function(...e) {
|
|
281
|
-
let { refId: t, metadata: n, options: r } =
|
|
281
|
+
let { refId: t, metadata: n, options: r } = ne(...e), i = n ?? {}, { param: a } = i, o = s(i, ["param"]), c = E.getMetadataFromRegistry(this) ?? {}, { _internal: u } = c, d = s(c, ["_internal"]), f = Object.assign(Object.assign(Object.assign({}, u), r), t ? { refId: t } : void 0), p = Object.assign(Object.assign(Object.assign({}, d), o), d?.param || a ? { param: Object.assign(Object.assign({}, d?.param), a) } : void 0), m = new this.constructor(this._def);
|
|
282
282
|
function h(e) {
|
|
283
283
|
E.setMetadataInRegistry(e, Object.assign(Object.assign({}, Object.keys(f).length > 0 ? { _internal: f } : void 0), p));
|
|
284
284
|
}
|
|
@@ -304,7 +304,7 @@ function te(e) {
|
|
|
304
304
|
}, m;
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function ne(e, t, n) {
|
|
308
308
|
return typeof e == "string" ? {
|
|
309
309
|
refId: e,
|
|
310
310
|
metadata: t,
|
|
@@ -315,10 +315,10 @@ function O(e, t, n) {
|
|
|
315
315
|
options: t
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function O(e) {
|
|
319
319
|
return b(E.getOpenApiMetadata(e) ?? {}, _);
|
|
320
320
|
}
|
|
321
|
-
var
|
|
321
|
+
var k = class {
|
|
322
322
|
constructor(e) {
|
|
323
323
|
this.parents = e, this._definitions = [];
|
|
324
324
|
}
|
|
@@ -365,31 +365,31 @@ var A = class {
|
|
|
365
365
|
schemaWithRefId(e, t) {
|
|
366
366
|
return t.openapi(e);
|
|
367
367
|
}
|
|
368
|
-
},
|
|
368
|
+
}, A = class {
|
|
369
369
|
constructor(e) {
|
|
370
370
|
this.message = e;
|
|
371
371
|
}
|
|
372
|
-
},
|
|
372
|
+
}, re = class extends A {
|
|
373
373
|
constructor(e, t) {
|
|
374
374
|
super(e), this.data = t;
|
|
375
375
|
}
|
|
376
|
-
},
|
|
376
|
+
}, ie = class extends A {
|
|
377
377
|
constructor(e) {
|
|
378
378
|
super(`Missing parameter data, please specify \`${e.missingField}\` and other OpenAPI parameter props using the \`param\` field of \`schema.openapi\``), this.data = e;
|
|
379
379
|
}
|
|
380
380
|
};
|
|
381
|
-
function
|
|
381
|
+
function ae(e, t) {
|
|
382
382
|
try {
|
|
383
383
|
return e();
|
|
384
384
|
} catch (e) {
|
|
385
|
-
throw e instanceof
|
|
385
|
+
throw e instanceof ie ? new ie(Object.assign(Object.assign({}, e.data), t)) : e;
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
-
var
|
|
388
|
+
var oe = class extends A {
|
|
389
389
|
constructor(e) {
|
|
390
390
|
super("Unknown zod object type, please specify `type` and other OpenAPI props using `schema.openapi`."), this.data = e;
|
|
391
391
|
}
|
|
392
|
-
},
|
|
392
|
+
}, se = class {
|
|
393
393
|
transform(e, t, n) {
|
|
394
394
|
let r = e.def.element, i = (e.def.checks?.find((e) => e._zod.def.check === "min_length"))?._zod.def.minimum, a = (e.def.checks?.find((e) => e._zod.def.check === "max_length"))?._zod.def.maximum;
|
|
395
395
|
return Object.assign(Object.assign({}, t("array")), {
|
|
@@ -398,11 +398,11 @@ var ae = class extends j {
|
|
|
398
398
|
maxItems: a
|
|
399
399
|
});
|
|
400
400
|
}
|
|
401
|
-
},
|
|
401
|
+
}, ce = class {
|
|
402
402
|
transform(e) {
|
|
403
403
|
return Object.assign(Object.assign({}, e("string")), { pattern: "^\\d+$" });
|
|
404
404
|
}
|
|
405
|
-
},
|
|
405
|
+
}, le = class {
|
|
406
406
|
transform(e, t, n, r, i) {
|
|
407
407
|
let a = e.def.options.filter(u), o = a.map(r);
|
|
408
408
|
if (t) return { oneOf: n(o, t) };
|
|
@@ -436,7 +436,7 @@ var ae = class extends j {
|
|
|
436
436
|
return [];
|
|
437
437
|
}
|
|
438
438
|
};
|
|
439
|
-
function
|
|
439
|
+
function j(e) {
|
|
440
440
|
let t = Object.keys(e).filter((t) => typeof e[e[t]] != "number").map((t) => e[t]), n = t.filter((e) => typeof e == "number").length;
|
|
441
441
|
return {
|
|
442
442
|
values: t,
|
|
@@ -445,8 +445,8 @@ function le(e) {
|
|
|
445
445
|
}
|
|
446
446
|
var ue = class {
|
|
447
447
|
transform(e, t, n) {
|
|
448
|
-
let { type: r, values: i } =
|
|
449
|
-
if (r === "mixed") throw new
|
|
448
|
+
let { type: r, values: i } = j(e._zod.def.entries);
|
|
449
|
+
if (r === "mixed") throw new A("Enum has mixed string and number values, please specify the OpenAPI type manually");
|
|
450
450
|
return Object.assign(Object.assign({}, n(r === "numeric" ? "integer" : "string")), { enum: t ? [...i, null] : i });
|
|
451
451
|
}
|
|
452
452
|
}, de = class {
|
|
@@ -461,7 +461,7 @@ var ue = class {
|
|
|
461
461
|
}
|
|
462
462
|
}, fe = class {
|
|
463
463
|
constructor() {
|
|
464
|
-
this.bigIntTransformer = new
|
|
464
|
+
this.bigIntTransformer = new ce();
|
|
465
465
|
}
|
|
466
466
|
transform(e, t) {
|
|
467
467
|
let n = typeof e.def.values[0];
|
|
@@ -588,7 +588,7 @@ var ve = class {
|
|
|
588
588
|
if (l(e, "ZodNumber")) return "[+-]?\\d+(\\.\\d+)?";
|
|
589
589
|
if (l(e, "ZodBoolean")) return "(true|false)";
|
|
590
590
|
if (l(e, "ZodEnum")) {
|
|
591
|
-
let { values: t } =
|
|
591
|
+
let { values: t } = j(e.def.entries);
|
|
592
592
|
return `(${t.map((e) => this.escapeRegex(String(e))).join("|")})`;
|
|
593
593
|
}
|
|
594
594
|
return ".*";
|
|
@@ -598,7 +598,7 @@ var ve = class {
|
|
|
598
598
|
}
|
|
599
599
|
}, we = class {
|
|
600
600
|
constructor(e, t) {
|
|
601
|
-
this.versionSpecifics = e, this.objectTransformer = new me(), this.stringTransformer = new ve(), this.numberTransformer = new pe(), this.bigIntTransformer = new
|
|
601
|
+
this.versionSpecifics = e, this.objectTransformer = new me(), this.stringTransformer = new ve(), this.numberTransformer = new pe(), this.bigIntTransformer = new ce(), this.dateTransformer = new xe(), this.lazyTransformer = new Se(), this.literalTransformer = new fe(), this.templateLiteralTransformer = new Ce(), this.enumTransformer = new ue(), this.arrayTransformer = new se(), this.discriminatedUnionTransformer = new le(), this.intersectionTransformer = new de(), this.recordTransformer = new he(), this.tupleTransformer = new ye(e), this.unionTransformer = new be(t);
|
|
602
602
|
}
|
|
603
603
|
transform(e, t, n, r, i) {
|
|
604
604
|
if (l(e, "ZodNull")) return this.versionSpecifics.nullType;
|
|
@@ -625,7 +625,7 @@ var ve = class {
|
|
|
625
625
|
if (l(e, "ZodRecord")) return this.recordTransformer.transform(e, (e) => this.versionSpecifics.mapNullableType(e, t), n);
|
|
626
626
|
if (l(e, "ZodDate")) return this.dateTransformer.transform((e) => this.versionSpecifics.mapNullableType(e, t));
|
|
627
627
|
let i = E.getRefId(e);
|
|
628
|
-
throw new
|
|
628
|
+
throw new oe({
|
|
629
629
|
currentSchema: e.def,
|
|
630
630
|
schemaName: i
|
|
631
631
|
});
|
|
@@ -698,7 +698,7 @@ var ve = class {
|
|
|
698
698
|
getParameterRef(e, t) {
|
|
699
699
|
let n = E.getOpenApiMetadata(e), r = E.getInternalMetadata(e), i = n?.param, a = r?.refId ? this.paramRefs[r.refId] : void 0;
|
|
700
700
|
if (!(!r?.refId || !a)) {
|
|
701
|
-
if (i && a.in !== i.in || t?.in && a.in !== t.in) throw new
|
|
701
|
+
if (i && a.in !== i.in || t?.in && a.in !== t.in) throw new re(`Conflicting location for parameter ${a.name}`, {
|
|
702
702
|
key: "in",
|
|
703
703
|
values: x([
|
|
704
704
|
a.in,
|
|
@@ -706,7 +706,7 @@ var ve = class {
|
|
|
706
706
|
i?.in
|
|
707
707
|
])
|
|
708
708
|
});
|
|
709
|
-
if (i && a.name !== i.name || t?.name && a.name !== t?.name) throw new
|
|
709
|
+
if (i && a.name !== i.name || t?.name && a.name !== t?.name) throw new re("Conflicting names for parameter", {
|
|
710
710
|
key: "name",
|
|
711
711
|
values: x([
|
|
712
712
|
a.name,
|
|
@@ -729,11 +729,11 @@ var ve = class {
|
|
|
729
729
|
});
|
|
730
730
|
if (i) return i;
|
|
731
731
|
let a = r?.param;
|
|
732
|
-
if (a?.name && a.name !== e) throw new
|
|
732
|
+
if (a?.name && a.name !== e) throw new re("Conflicting names for parameter", {
|
|
733
733
|
key: "name",
|
|
734
734
|
values: [e, a.name]
|
|
735
735
|
});
|
|
736
|
-
if (a?.in && a.in !== t) throw new
|
|
736
|
+
if (a?.in && a.in !== t) throw new re(`Conflicting location for parameter ${a.name ?? e}`, {
|
|
737
737
|
key: "in",
|
|
738
738
|
values: [t, a.in]
|
|
739
739
|
});
|
|
@@ -743,7 +743,7 @@ var ve = class {
|
|
|
743
743
|
});
|
|
744
744
|
});
|
|
745
745
|
}
|
|
746
|
-
if (n?.in && n.in !== t) throw new
|
|
746
|
+
if (n?.in && n.in !== t) throw new re(`Conflicting location for parameter ${n.name}`, {
|
|
747
747
|
key: "in",
|
|
748
748
|
values: [t, n.in]
|
|
749
749
|
});
|
|
@@ -758,8 +758,8 @@ var ve = class {
|
|
|
758
758
|
}
|
|
759
759
|
generateParameter(e, t) {
|
|
760
760
|
let n = E.getOpenApiMetadata(e)?.param, r = t?.name ?? n?.name, i = t?.in ?? n?.in;
|
|
761
|
-
if (!r) throw new
|
|
762
|
-
if (!i) throw new
|
|
761
|
+
if (!r) throw new ie({ missingField: "name" });
|
|
762
|
+
if (!i) throw new ie({
|
|
763
763
|
missingField: "in",
|
|
764
764
|
paramName: r
|
|
765
765
|
});
|
|
@@ -815,7 +815,7 @@ var ve = class {
|
|
|
815
815
|
}
|
|
816
816
|
getParameters(e) {
|
|
817
817
|
if (!e) return [];
|
|
818
|
-
let { headers: t } = e, n = this.cleanParameter(e.query), r = this.cleanParameter(e.params), i = this.cleanParameter(e.cookies), a =
|
|
818
|
+
let { headers: t } = e, n = this.cleanParameter(e.query), r = this.cleanParameter(e.params), i = this.cleanParameter(e.cookies), a = ae(() => n ? this.generateInlineParameters(n, "query") : [], { location: "query" }), o = ae(() => r ? this.generateInlineParameters(r, "path") : [], { location: "path" }), s = ae(() => i ? this.generateInlineParameters(i, "cookie") : [], { location: "cookie" }), c = ae(() => {
|
|
819
819
|
if (Array.isArray(t)) return t.flatMap((e) => this.generateInlineParameters(e, "header"));
|
|
820
820
|
let e = this.cleanParameter(t);
|
|
821
821
|
return e ? this.generateInlineParameters(e, "header") : [];
|
|
@@ -842,7 +842,7 @@ var ve = class {
|
|
|
842
842
|
"path",
|
|
843
843
|
"request",
|
|
844
844
|
"responses"
|
|
845
|
-
]), o = v(i, (e) => this.getResponse(e)), c =
|
|
845
|
+
]), o = v(i, (e) => this.getResponse(e)), c = ae(() => this.getParameters(r), { route: `${t} ${n}` }), l = this.getRequestBody(r?.body);
|
|
846
846
|
return { [t]: Object.assign(Object.assign(Object.assign(Object.assign({}, a), c.length > 0 ? { parameters: [...a.parameters || [], ...c] } : {}), l ? { requestBody: l } : {}), { responses: o }) };
|
|
847
847
|
}
|
|
848
848
|
generateSingleRoute(e) {
|
|
@@ -16403,7 +16403,7 @@ var $y = class t extends e {
|
|
|
16403
16403
|
defaultHook;
|
|
16404
16404
|
#e;
|
|
16405
16405
|
constructor(e) {
|
|
16406
|
-
super(e), this.openAPIRegistry = new
|
|
16406
|
+
super(e), this.openAPIRegistry = new k(), this.defaultHook = e?.defaultHook;
|
|
16407
16407
|
}
|
|
16408
16408
|
#t() {
|
|
16409
16409
|
if (this.defaultHook) return this.defaultHook;
|
|
@@ -16518,8 +16518,8 @@ var $y = class t extends e {
|
|
|
16518
16518
|
path: Me(r, n._basePath.replaceAll(/:([^\/]+)/g, "{$1}"), e.webhook.path)
|
|
16519
16519
|
});
|
|
16520
16520
|
return;
|
|
16521
|
-
case "schema": return this.openAPIRegistry.register(
|
|
16522
|
-
case "parameter": return this.openAPIRegistry.registerParameter(
|
|
16521
|
+
case "schema": return this.openAPIRegistry.register(O(e.schema)._internal?.refId, e.schema);
|
|
16522
|
+
case "parameter": return this.openAPIRegistry.registerParameter(O(e.schema)._internal?.refId, e.schema);
|
|
16523
16523
|
default: throw Error(`Unknown registry type: ${e}`);
|
|
16524
16524
|
}
|
|
16525
16525
|
}), this) : this;
|
|
@@ -19862,6 +19862,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
19862
19862
|
public: !0,
|
|
19863
19863
|
rules: {}
|
|
19864
19864
|
},
|
|
19865
|
+
channelRoot: {
|
|
19866
|
+
label: "Channel Root",
|
|
19867
|
+
type: "link",
|
|
19868
|
+
public: !0,
|
|
19869
|
+
allowedLinkTypes: ["node"],
|
|
19870
|
+
rules: {}
|
|
19871
|
+
},
|
|
19865
19872
|
currency: {
|
|
19866
19873
|
label: "Default Currency",
|
|
19867
19874
|
type: "select",
|
|
@@ -19991,6 +19998,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
19991
19998
|
public: !0,
|
|
19992
19999
|
rules: {}
|
|
19993
20000
|
},
|
|
20001
|
+
channelRoot: {
|
|
20002
|
+
label: "Channel Root",
|
|
20003
|
+
type: "link",
|
|
20004
|
+
public: !0,
|
|
20005
|
+
allowedLinkTypes: ["node"],
|
|
20006
|
+
rules: {}
|
|
20007
|
+
},
|
|
19994
20008
|
currency: {
|
|
19995
20009
|
label: "Default Currency",
|
|
19996
20010
|
type: "select",
|
|
@@ -20114,6 +20128,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20114
20128
|
dbType: "json",
|
|
20115
20129
|
public: !0,
|
|
20116
20130
|
rules: {}
|
|
20131
|
+
},
|
|
20132
|
+
channelRoot: {
|
|
20133
|
+
label: "Channel Root",
|
|
20134
|
+
type: "link",
|
|
20135
|
+
public: !0,
|
|
20136
|
+
allowedLinkTypes: ["node"],
|
|
20137
|
+
rules: {}
|
|
20117
20138
|
}
|
|
20118
20139
|
}
|
|
20119
20140
|
},
|
|
@@ -20256,6 +20277,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20256
20277
|
public: !0,
|
|
20257
20278
|
rules: {}
|
|
20258
20279
|
},
|
|
20280
|
+
channelRoot: {
|
|
20281
|
+
label: "Channel Root",
|
|
20282
|
+
type: "link",
|
|
20283
|
+
public: !0,
|
|
20284
|
+
allowedLinkTypes: ["node"],
|
|
20285
|
+
rules: {}
|
|
20286
|
+
},
|
|
20259
20287
|
favicon: {
|
|
20260
20288
|
label: "Favicon",
|
|
20261
20289
|
type: "image",
|
|
@@ -21162,6 +21190,12 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21162
21190
|
multiple: !0,
|
|
21163
21191
|
dbType: "json",
|
|
21164
21192
|
public: !0
|
|
21193
|
+
},
|
|
21194
|
+
channelRoot: {
|
|
21195
|
+
label: "Channel Root",
|
|
21196
|
+
type: "link",
|
|
21197
|
+
public: !0,
|
|
21198
|
+
allowedLinkTypes: ["node"]
|
|
21165
21199
|
}
|
|
21166
21200
|
}
|
|
21167
21201
|
},
|
|
@@ -21607,7 +21641,7 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21607
21641
|
userTemplate: null
|
|
21608
21642
|
}, Db = Eb, Ob = {
|
|
21609
21643
|
content_schemas: "\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n type TEXT UNIQUE NOT NULL,\n schemaJson TEXT NOT NULL,\n isSystem INTEGER DEFAULT 1,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP\n ",
|
|
21610
|
-
users: "\n id TEXT PRIMARY KEY,\n email
|
|
21644
|
+
users: "\n id TEXT PRIMARY KEY,\n email UNIQUE NOT NULL,\n name TEXT NOT NULL,\n globalRole TEXT DEFAULT 'editor',\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP\n ",
|
|
21611
21645
|
user_accounts: "\n id TEXT PRIMARY KEY,\n userId TEXT NOT NULL,\n provider TEXT NOT NULL,\n providerAccountId TEXT NOT NULL,\n passwordHash TEXT NOT NULL,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (userId) REFERENCES users(id) ON DELETE CASCADE,\n UNIQUE(provider, providerAccountId)\n ",
|
|
21612
21646
|
sessions: "\n id TEXT PRIMARY KEY,\n userId TEXT NOT NULL,\n expiresAt TEXT NOT NULL,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (userId) REFERENCES users(id) ON DELETE CASCADE\n ",
|
|
21613
21647
|
channels: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n key TEXT UNIQUE NOT NULL,\n label TEXT NOT NULL,\n channelType TEXT,\n domain TEXT,\n baseUrl TEXT,\n defaultLanguage TEXT,\n isHidden INTEGER NOT NULL DEFAULT 0,\n dataJson TEXT,\n createdById TEXT,\n updatedById TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (createdById) REFERENCES users(id) ON DELETE SET NULL,\n FOREIGN KEY (updatedById) REFERENCES users(id) ON DELETE SET NULL\n ",
|
|
@@ -21621,8 +21655,9 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21621
21655
|
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 ",
|
|
21622
21656
|
node_assets: "\n nodeId INTEGER NOT NULL,\n assetId TEXT NOT NULL,\n fieldKey TEXT NOT NULL,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (nodeId, assetId, fieldKey),\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (assetId) REFERENCES assets(id) ON DELETE CASCADE\n ",
|
|
21623
21657
|
taxonomy_terms: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n taxonomy TEXT NOT NULL,\n key TEXT NOT NULL,\n label TEXT NOT NULL,\n parentId INTEGER,\n sortOrder INTEGER DEFAULT 0,\n dataJson TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (parentId) REFERENCES taxonomy_terms(id) ON DELETE CASCADE,\n UNIQUE(taxonomy, key)\n ",
|
|
21624
|
-
node_terms: "\n nodeId INTEGER NOT NULL,\n termId INTEGER NOT NULL,\n fieldKey TEXT NOT NULL,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (nodeId, termId, fieldKey),\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (termId) REFERENCES taxonomy_terms(id) ON DELETE CASCADE\n "
|
|
21625
|
-
|
|
21658
|
+
node_terms: "\n nodeId INTEGER NOT NULL,\n termId INTEGER NOT NULL,\n fieldKey TEXT NOT NULL,\n sortOrder INTEGER DEFAULT 0,\n PRIMARY KEY (nodeId, termId, fieldKey),\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (termId) REFERENCES taxonomy_terms(id) ON DELETE CASCADE\n ",
|
|
21659
|
+
node_routes: "\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n path TEXT NOT NULL,\n channelId INTEGER NOT NULL,\n nodeId INTEGER,\n treeId INTEGER,\n isCanonical INTEGER DEFAULT 1,\n redirectUrl TEXT,\n createdAt TEXT DEFAULT CURRENT_TIMESTAMP,\n updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (channelId) REFERENCES channels(id) ON DELETE CASCADE,\n FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,\n FOREIGN KEY (treeId) REFERENCES trees(id) ON DELETE CASCADE,\n UNIQUE(path, channelId)\n "
|
|
21660
|
+
}, kb = /* @__PURE__ */ "CREATE INDEX IF NOT EXISTS idx_tree_nodes_tree_parent ON tree_nodes(treeId, parentId);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_contentId ON tree_nodes(contentId);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug_status ON content_nodes(slug, status);.CREATE INDEX IF NOT EXISTS idx_content_blocks_node ON content_blocks(contentId, isDraft);.CREATE INDEX IF NOT EXISTS idx_node_assets_nodeId ON node_assets(nodeId);.CREATE INDEX IF NOT EXISTS idx_node_assets_assetId ON node_assets(assetId);.CREATE INDEX IF NOT EXISTS idx_content_schemas_type ON content_schemas(type);.CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(userId);.CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expiresAt);.CREATE INDEX IF NOT EXISTS idx_channels_visibility ON channels(isHidden);.CREATE INDEX IF NOT EXISTS idx_trees_visibility ON trees(isHidden);.CREATE INDEX IF NOT EXISTS idx_content_nodes_visibility ON content_nodes(isHidden, status);.CREATE INDEX IF NOT EXISTS idx_content_nodes_slug ON content_nodes(slug);.CREATE INDEX IF NOT EXISTS idx_content_nodes_type ON content_nodes(contentType);.CREATE INDEX IF NOT EXISTS idx_content_nodes_deleted_updated ON content_nodes(deletedAt, updatedAt DESC);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_hierarchy ON tree_nodes(treeId, parentId, sortOrder);.CREATE INDEX IF NOT EXISTS idx_tree_nodes_content ON tree_nodes(contentId, treeId);.CREATE INDEX IF NOT EXISTS idx_content_blocks_content ON content_blocks(contentId, isDraft, region, sortOrder);.CREATE INDEX IF NOT EXISTS idx_node_channels_channel ON node_channels(channelId, nodeId);.CREATE INDEX IF NOT EXISTS idx_node_channels_node ON node_channels(nodeId, channelId);.CREATE INDEX IF NOT EXISTS idx_node_assets_node_asset ON node_assets(nodeId, assetId);.CREATE INDEX IF NOT EXISTS idx_node_assets_asset_node ON node_assets(assetId, nodeId);.CREATE UNIQUE INDEX IF NOT EXISTS idx_node_revisions_version ON node_revisions(nodeId, version);.CREATE INDEX IF NOT EXISTS idx_assets_system_created ON assets(isSystemVariant, createdAt DESC);.CREATE INDEX IF NOT EXISTS idx_assets_system_mime ON assets(isSystemVariant, mimeType);.CREATE INDEX IF NOT EXISTS idx_assets_deleted ON assets(deletedAt);.CREATE INDEX IF NOT EXISTS idx_assets_parent ON assets(parentAssetId);.CREATE INDEX IF NOT EXISTS idx_taxonomy_terms_tax ON taxonomy_terms(taxonomy);.CREATE INDEX IF NOT EXISTS idx_node_terms_node ON node_terms(nodeId);.CREATE INDEX IF NOT EXISTS idx_node_terms_term ON node_terms(termId);.CREATE INDEX IF NOT EXISTS idx_node_terms_node_term ON node_terms(nodeId, termId);.CREATE INDEX IF NOT EXISTS idx_node_terms_term_node ON node_terms(termId, nodeId);.CREATE UNIQUE INDEX IF NOT EXISTS idx_node_routes_lookup ON node_routes(path, channelId);.CREATE INDEX IF NOT EXISTS idx_node_routes_node ON node_routes(nodeId);".split(".");
|
|
21626
21661
|
function Ab(e) {
|
|
21627
21662
|
let t = /* @__PURE__ */ new Set();
|
|
21628
21663
|
function n(e) {
|
|
@@ -22604,7 +22639,7 @@ function ax(e) {
|
|
|
22604
22639
|
assetRefs: [],
|
|
22605
22640
|
termRefs: []
|
|
22606
22641
|
};
|
|
22607
|
-
let t = [], n = [], r = (e) => e ? typeof e == "string" && e.startsWith("ast_") ? e : typeof e == "object" && typeof e.id == "string" && e.id.startsWith("ast_") ? e.id : null : null, i = (e) => {
|
|
22642
|
+
let t = [], n = [], r = (e) => e ? typeof e == "string" && e.startsWith("ast_") && !e.includes(" ") ? e : typeof e == "object" && typeof e.id == "string" && e.id.startsWith("ast_") ? e.id : null : null, i = (e) => {
|
|
22608
22643
|
if (!e) return null;
|
|
22609
22644
|
if (typeof e == "string" && e.startsWith("trm_")) {
|
|
22610
22645
|
let t = Number(e.replace("trm_", ""));
|
|
@@ -22619,17 +22654,29 @@ function ax(e) {
|
|
|
22619
22654
|
if (!e || typeof e != "object") return e;
|
|
22620
22655
|
if (Array.isArray(e)) return e.map((e, s) => {
|
|
22621
22656
|
let c = r(e);
|
|
22622
|
-
if (c
|
|
22623
|
-
|
|
22624
|
-
|
|
22625
|
-
|
|
22626
|
-
}), typeof e == "object" && e && e.variants && typeof e.variants == "object")) for (let [n, i] of Object.entries(e.variants)) {
|
|
22627
|
-
let e = r(i);
|
|
22628
|
-
e && t.push({
|
|
22629
|
-
assetId: e,
|
|
22630
|
-
fieldKey: `${o}[${s}].variants.${n}`,
|
|
22657
|
+
if (c) {
|
|
22658
|
+
if (t.push({
|
|
22659
|
+
assetId: c,
|
|
22660
|
+
fieldKey: o,
|
|
22631
22661
|
sortOrder: s
|
|
22632
|
-
})
|
|
22662
|
+
}), typeof e == "object" && e && e.variants && typeof e.variants == "object") for (let [n, i] of Object.entries(e.variants)) {
|
|
22663
|
+
let e = r(i);
|
|
22664
|
+
e && t.push({
|
|
22665
|
+
assetId: e,
|
|
22666
|
+
fieldKey: `${o}[${s}].variants.${n}`,
|
|
22667
|
+
sortOrder: s
|
|
22668
|
+
});
|
|
22669
|
+
}
|
|
22670
|
+
} else if (typeof e == "string") {
|
|
22671
|
+
let n = e.match(/ast_[a-zA-Z0-9-]+/g);
|
|
22672
|
+
if (n) {
|
|
22673
|
+
let e = Array.from(new Set(n));
|
|
22674
|
+
for (let n of e) n !== c && t.push({
|
|
22675
|
+
assetId: n,
|
|
22676
|
+
fieldKey: o,
|
|
22677
|
+
sortOrder: s
|
|
22678
|
+
});
|
|
22679
|
+
}
|
|
22633
22680
|
}
|
|
22634
22681
|
let l = i(e);
|
|
22635
22682
|
return l ? (n.push({
|
|
@@ -22665,11 +22712,39 @@ function ax(e) {
|
|
|
22665
22712
|
filename: l.filename || void 0,
|
|
22666
22713
|
mimeType: l.mimeType || void 0
|
|
22667
22714
|
} : d;
|
|
22668
|
-
} else f
|
|
22715
|
+
} else if (f) n.push({
|
|
22669
22716
|
termId: f,
|
|
22670
22717
|
fieldKey: u,
|
|
22671
22718
|
sortOrder: 0
|
|
22672
|
-
}), s[c] = `trm_${f}
|
|
22719
|
+
}), s[c] = `trm_${f}`;
|
|
22720
|
+
else if (Array.isArray(l)) s[c] = a(l, u);
|
|
22721
|
+
else if (l && typeof l == "object") s[c] = a(l, u);
|
|
22722
|
+
else {
|
|
22723
|
+
if (typeof l == "string") {
|
|
22724
|
+
let e = l.match(/ast_[a-zA-Z0-9-]+/g);
|
|
22725
|
+
if (e) {
|
|
22726
|
+
let n = Array.from(new Set(e));
|
|
22727
|
+
for (let e of n) t.push({
|
|
22728
|
+
assetId: e,
|
|
22729
|
+
fieldKey: u,
|
|
22730
|
+
sortOrder: 0
|
|
22731
|
+
});
|
|
22732
|
+
}
|
|
22733
|
+
let r = l.match(/trm_\d+/g);
|
|
22734
|
+
if (r) {
|
|
22735
|
+
let e = Array.from(new Set(r));
|
|
22736
|
+
for (let t of e) {
|
|
22737
|
+
let e = Number(t.replace("trm_", ""));
|
|
22738
|
+
isNaN(e) || n.push({
|
|
22739
|
+
termId: e,
|
|
22740
|
+
fieldKey: u,
|
|
22741
|
+
sortOrder: 0
|
|
22742
|
+
});
|
|
22743
|
+
}
|
|
22744
|
+
}
|
|
22745
|
+
}
|
|
22746
|
+
s[c] = l;
|
|
22747
|
+
}
|
|
22673
22748
|
}
|
|
22674
22749
|
return s;
|
|
22675
22750
|
};
|
|
@@ -22681,18 +22756,20 @@ function ax(e) {
|
|
|
22681
22756
|
}
|
|
22682
22757
|
async function ox(e, t, n) {
|
|
22683
22758
|
if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
22684
|
-
let r = /* @__PURE__ */ new Set();
|
|
22685
|
-
for (let
|
|
22686
|
-
|
|
22687
|
-
|
|
22759
|
+
let r = [...new Set(n.map((e) => e.assetId))], i = r.map(() => "?").join(","), a = await e.prepare(`SELECT id FROM assets WHERE id IN (${i})`).all(...r), o = Array.isArray(a) ? a : a?.results || [], s = new Set(o.map((e) => e.id)), c = /* @__PURE__ */ new Set();
|
|
22760
|
+
for (let r of n) {
|
|
22761
|
+
if (!s.has(r.assetId)) continue;
|
|
22762
|
+
let n = `${t}:${r.assetId}:${r.fieldKey}`;
|
|
22763
|
+
c.has(n) || (c.add(n), await e.prepare("\n INSERT OR IGNORE INTO node_assets (nodeId, assetId, fieldKey, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(t, r.assetId, r.fieldKey, r.sortOrder));
|
|
22688
22764
|
}
|
|
22689
22765
|
}
|
|
22690
22766
|
async function sx(e, t, n) {
|
|
22691
22767
|
if (await e.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
22692
|
-
let r = /* @__PURE__ */ new Set();
|
|
22693
|
-
for (let
|
|
22694
|
-
|
|
22695
|
-
|
|
22768
|
+
let r = [...new Set(n.map((e) => e.termId))], i = r.map(() => "?").join(","), a = await e.prepare(`SELECT id FROM taxonomy_terms WHERE id IN (${i})`).all(...r), o = Array.isArray(a) ? a : a?.results || [], s = new Set(o.map((e) => e.id)), c = /* @__PURE__ */ new Set();
|
|
22769
|
+
for (let r of n) {
|
|
22770
|
+
if (!s.has(r.termId)) continue;
|
|
22771
|
+
let n = `${t}:${r.termId}:${r.fieldKey}`;
|
|
22772
|
+
c.has(n) || (c.add(n), await e.prepare("\n INSERT OR IGNORE INTO node_terms (nodeId, termId, fieldKey, sortOrder)\n VALUES (?, ?, ?, ?)\n ").run(t, r.termId, r.fieldKey, r.sortOrder));
|
|
22696
22773
|
}
|
|
22697
22774
|
}
|
|
22698
22775
|
function cx(e) {
|
|
@@ -23077,8 +23154,118 @@ var fx = class {
|
|
|
23077
23154
|
console.warn("⚠️ [CacheWarmer] Tree-wide warming failed:", e);
|
|
23078
23155
|
}
|
|
23079
23156
|
}
|
|
23080
|
-
}
|
|
23081
|
-
async function
|
|
23157
|
+
};
|
|
23158
|
+
async function px(e) {
|
|
23159
|
+
try {
|
|
23160
|
+
console.log("[Route Generator] Rebuilding enterprise routing table...");
|
|
23161
|
+
let t = await e.prepare("SELECT id, key, dataJson FROM channels").all(), n = Array.isArray(t) ? t : t?.results || [], r = /* @__PURE__ */ new Map();
|
|
23162
|
+
for (let e of n) if (e.dataJson) try {
|
|
23163
|
+
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
23164
|
+
typeof t == "string" && (t = JSON.parse(t));
|
|
23165
|
+
let n = t?.channelRoot;
|
|
23166
|
+
if (typeof n == "string") try {
|
|
23167
|
+
n = JSON.parse(n);
|
|
23168
|
+
} catch {}
|
|
23169
|
+
let i = n?.nodeId ?? n?.id ?? t?.channelRootNodeId ?? t?.homeNodeId;
|
|
23170
|
+
i != null && !isNaN(Number(i)) && r.set(Number(e.id), Number(i));
|
|
23171
|
+
} catch (t) {
|
|
23172
|
+
console.error(`[Route Generator] Failed to parse channel ${e.id} dataJson:`, t);
|
|
23173
|
+
}
|
|
23174
|
+
let i = await e.prepare("SELECT id, slug FROM content_nodes WHERE (deletedAt IS NULL OR deletedAt = '')").all(), a = Array.isArray(i) ? i : i?.results || [], o = /* @__PURE__ */ new Map();
|
|
23175
|
+
for (let e of a) e.slug && o.set(Number(e.id), String(e.slug).replace(/^\/+|\/+$/g, ""));
|
|
23176
|
+
let s = await e.prepare("SELECT channelId, treeId FROM channel_trees").all(), c = Array.isArray(s) ? s : s?.results || [], l = await e.prepare("SELECT treeId, contentId, parentId, sortOrder FROM tree_nodes ORDER BY sortOrder ASC").all(), u = Array.isArray(l) ? l : l?.results || [], d = await e.prepare("SELECT nodeId, channelId FROM node_channels").all(), f = Array.isArray(d) ? d : d?.results || [], p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set();
|
|
23177
|
+
for (let e of n) {
|
|
23178
|
+
let t = Number(e.id), n = r.get(t), i = c.filter((e) => Number(e.channelId) === t).map((e) => Number(e.treeId)), a = f.filter((e) => Number(e.channelId) === t).map((e) => Number(e.nodeId));
|
|
23179
|
+
if (n && o.has(n)) {
|
|
23180
|
+
p.set(`/:${t}`, {
|
|
23181
|
+
path: "/",
|
|
23182
|
+
channelId: t,
|
|
23183
|
+
nodeId: n,
|
|
23184
|
+
treeId: null,
|
|
23185
|
+
isCanonical: 1,
|
|
23186
|
+
redirectUrl: null
|
|
23187
|
+
}), m.add(`${t}:${n}`);
|
|
23188
|
+
let e = o.get(n);
|
|
23189
|
+
e && e !== "index" && p.set(`/${e}:${t}`, {
|
|
23190
|
+
path: `/${e}`,
|
|
23191
|
+
channelId: t,
|
|
23192
|
+
nodeId: n,
|
|
23193
|
+
treeId: null,
|
|
23194
|
+
isCanonical: 0,
|
|
23195
|
+
redirectUrl: "/"
|
|
23196
|
+
});
|
|
23197
|
+
}
|
|
23198
|
+
for (let e of i) {
|
|
23199
|
+
let r = u.filter((t) => Number(t.treeId) === e), i = /* @__PURE__ */ new Map();
|
|
23200
|
+
for (let e of r) {
|
|
23201
|
+
let t = e.parentId ? Number(e.parentId) : null;
|
|
23202
|
+
i.has(t) || i.set(t, []), i.get(t).push(e);
|
|
23203
|
+
}
|
|
23204
|
+
let a = (r, s) => {
|
|
23205
|
+
let c = i.get(r) || [];
|
|
23206
|
+
for (let r of c) {
|
|
23207
|
+
let i = Number(r.contentId), c = o.get(i);
|
|
23208
|
+
if (!c) continue;
|
|
23209
|
+
let l = n !== void 0 && i === n, u = [...s];
|
|
23210
|
+
!l && c !== "index" && u.push(c);
|
|
23211
|
+
let d = l || u.length === 0 ? "/" : "/" + u.join("/"), f = `${d}:${t}`;
|
|
23212
|
+
if (!p.has(f) || l) {
|
|
23213
|
+
let n = `${t}:${i}`, r = l ? 1 : +!m.has(n);
|
|
23214
|
+
r && m.add(n), p.set(f, {
|
|
23215
|
+
path: d,
|
|
23216
|
+
channelId: t,
|
|
23217
|
+
nodeId: i,
|
|
23218
|
+
treeId: e,
|
|
23219
|
+
isCanonical: r,
|
|
23220
|
+
redirectUrl: null
|
|
23221
|
+
});
|
|
23222
|
+
}
|
|
23223
|
+
a(i, l ? [] : u);
|
|
23224
|
+
}
|
|
23225
|
+
};
|
|
23226
|
+
a(null, []);
|
|
23227
|
+
}
|
|
23228
|
+
for (let e of a) {
|
|
23229
|
+
let r = o.get(e);
|
|
23230
|
+
if (!r) continue;
|
|
23231
|
+
let i = `${t}:${e}`;
|
|
23232
|
+
if (!m.has(i)) {
|
|
23233
|
+
let a = n !== void 0 && e === n ? "/" : `/${r}`, o = `${a}:${t}`;
|
|
23234
|
+
p.has(o) || (p.set(o, {
|
|
23235
|
+
path: a,
|
|
23236
|
+
channelId: t,
|
|
23237
|
+
nodeId: e,
|
|
23238
|
+
treeId: null,
|
|
23239
|
+
isCanonical: 1,
|
|
23240
|
+
redirectUrl: null
|
|
23241
|
+
}), m.add(i));
|
|
23242
|
+
}
|
|
23243
|
+
}
|
|
23244
|
+
}
|
|
23245
|
+
await e.prepare("DELETE FROM node_routes").run();
|
|
23246
|
+
let h = Array.from(p.values());
|
|
23247
|
+
if (h.length === 0) return;
|
|
23248
|
+
for (let t = 0; t < h.length; t += 50) {
|
|
23249
|
+
let n = h.slice(t, t + 50), r = n.map(() => "(?, ?, ?, ?, ?, ?)").join(","), i = n.flatMap((e) => [
|
|
23250
|
+
e.path,
|
|
23251
|
+
e.channelId,
|
|
23252
|
+
e.nodeId,
|
|
23253
|
+
e.treeId,
|
|
23254
|
+
e.isCanonical,
|
|
23255
|
+
e.redirectUrl ?? null
|
|
23256
|
+
]);
|
|
23257
|
+
await e.prepare(`
|
|
23258
|
+
INSERT INTO node_routes (path, channelId, nodeId, treeId, isCanonical, redirectUrl)
|
|
23259
|
+
VALUES ${r}
|
|
23260
|
+
`).run(...i);
|
|
23261
|
+
}
|
|
23262
|
+
console.log(`[Route Generator] Successfully built ${h.length} enterprise routes.`);
|
|
23263
|
+
} catch (e) {
|
|
23264
|
+
console.error("[Route Generator] Fatal error rebuilding routes:", e);
|
|
23265
|
+
}
|
|
23266
|
+
}
|
|
23267
|
+
var mx = new e();
|
|
23268
|
+
async function hx(e, t, n = []) {
|
|
23082
23269
|
let r = e.prepare(t);
|
|
23083
23270
|
if (typeof r.bind == "function") {
|
|
23084
23271
|
let e = await r.bind(...n).all();
|
|
@@ -23090,23 +23277,23 @@ async function mx(e, t, n = []) {
|
|
|
23090
23277
|
}
|
|
23091
23278
|
return [];
|
|
23092
23279
|
}
|
|
23093
|
-
async function
|
|
23280
|
+
async function gx(e, t, n = []) {
|
|
23094
23281
|
let r = e.prepare(t);
|
|
23095
23282
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
23096
23283
|
if (typeof r.run == "function") return r.run(...n);
|
|
23097
23284
|
}
|
|
23098
|
-
function
|
|
23285
|
+
function _x(e) {
|
|
23099
23286
|
return !e || !e.trim() ? null : e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
23100
23287
|
}
|
|
23101
|
-
function
|
|
23288
|
+
function vx(e) {
|
|
23102
23289
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
23103
23290
|
}
|
|
23104
|
-
function
|
|
23291
|
+
function yx(e) {
|
|
23105
23292
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
23106
23293
|
let t = Number(e);
|
|
23107
23294
|
return isNaN(t) ? null : t;
|
|
23108
23295
|
}
|
|
23109
|
-
function
|
|
23296
|
+
function bx(e) {
|
|
23110
23297
|
let t = { ...e };
|
|
23111
23298
|
delete t.language, delete t.defaultLanguage;
|
|
23112
23299
|
for (let e of [
|
|
@@ -23119,6 +23306,8 @@ function yx(e) {
|
|
|
23119
23306
|
"contentType",
|
|
23120
23307
|
"title",
|
|
23121
23308
|
"slug",
|
|
23309
|
+
"path",
|
|
23310
|
+
"routePath",
|
|
23122
23311
|
"hidden",
|
|
23123
23312
|
"is_hidden",
|
|
23124
23313
|
"isHidden",
|
|
@@ -23135,34 +23324,28 @@ function yx(e) {
|
|
|
23135
23324
|
]) delete t[e];
|
|
23136
23325
|
return t;
|
|
23137
23326
|
}
|
|
23138
|
-
function
|
|
23139
|
-
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) =>
|
|
23327
|
+
function xx(e, t = /* @__PURE__ */ new Set()) {
|
|
23328
|
+
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) => xx(e, t)), t) : (typeof e == "object" && Object.values(e).forEach((e) => xx(e, t)), t) : t;
|
|
23140
23329
|
}
|
|
23141
|
-
function
|
|
23330
|
+
function Sx(e, t) {
|
|
23142
23331
|
if (!e) return !0;
|
|
23143
|
-
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 &&
|
|
23332
|
+
let n = t.title !== void 0 && t.title?.trim() !== e.title?.trim(), r = t.slug !== void 0 && t.slug !== e.slug, i = t.isHidden !== void 0 && vx(t.isHidden) !== vx(e.isHidden), a = t.status !== void 0 && t.status !== e.status, o = typeof e.draftDataJson == "string" ? JSON.parse(e.draftDataJson || "{}") : e.draftDataJson || {}, s = t.sanitizedFields || {}, c = s.menuTitle !== void 0 && s.menuTitle !== o.menuTitle;
|
|
23144
23333
|
return n || r || i || a || c;
|
|
23145
23334
|
}
|
|
23146
|
-
async function
|
|
23335
|
+
async function Cx(e, t, n) {
|
|
23147
23336
|
for (let r of n) {
|
|
23148
|
-
let n = (await
|
|
23149
|
-
if (
|
|
23150
|
-
|
|
23151
|
-
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
for (let e of i) if (e.storageKeyPrivate) try {
|
|
23157
|
-
await t.delete(e.storageKeyPrivate);
|
|
23158
|
-
} catch (t) {
|
|
23159
|
-
console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
|
|
23337
|
+
let n = (await hx(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
|
|
23338
|
+
if (n && n.isSystemVariant && !((await hx(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0)) {
|
|
23339
|
+
if (n.storageKeyPrivate) try {
|
|
23340
|
+
await t.delete(n.storageKeyPrivate);
|
|
23341
|
+
} catch (e) {
|
|
23342
|
+
console.warn(`[Asset Cleanup] Failed to delete crop ${n.storageKeyPrivate}:`, e);
|
|
23343
|
+
}
|
|
23344
|
+
await gx(e, "DELETE FROM node_assets WHERE assetId = ?", [n.id]), await gx(e, "DELETE FROM assets WHERE id = ?", [n.id]);
|
|
23160
23345
|
}
|
|
23161
|
-
let a = i.map((e) => e.id), o = a.map(() => "?").join(",");
|
|
23162
|
-
await hx(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await hx(e, `DELETE FROM assets WHERE id IN (${o})`, a);
|
|
23163
23346
|
}
|
|
23164
23347
|
}
|
|
23165
|
-
async function
|
|
23348
|
+
async function wx(e, t, n) {
|
|
23166
23349
|
let r = {}, i = null;
|
|
23167
23350
|
if (t) {
|
|
23168
23351
|
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 || [];
|
|
@@ -23187,56 +23370,65 @@ async function Cx(e, t, n) {
|
|
|
23187
23370
|
inheritedFields: r
|
|
23188
23371
|
};
|
|
23189
23372
|
}
|
|
23190
|
-
|
|
23373
|
+
mx.get("/", async (e) => {
|
|
23191
23374
|
let t = e.get("db"), n = e.req.query("id"), r = e.req.query("type"), i = e.req.query("q") || e.req.query("search"), a = e.req.query("channelId"), o = e.req.query("trashed") === "true", s = e.req.query("assetId"), c = e.req.query("sort") || "updatedAt", l = (e.req.query("order") || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC", u = e.req.query("limit"), d = e.req.query("offset"), f = Math.max(1, Math.min(100, parseInt(u || "50", 10))), p = Math.max(0, parseInt(d || "0", 10));
|
|
23192
23375
|
if (n) {
|
|
23193
23376
|
let r = Number(n);
|
|
23194
23377
|
if (isNaN(r)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
23195
23378
|
let i = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(r);
|
|
23196
23379
|
if (!i) return e.json({ error: "Node not found" }, 404);
|
|
23197
|
-
let
|
|
23380
|
+
let o = null;
|
|
23381
|
+
if (a && a !== "all") {
|
|
23382
|
+
let e = await t.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND channelId = ? AND isCanonical = 1 LIMIT 1").get(r, Number(a));
|
|
23383
|
+
e && (o = e.path);
|
|
23384
|
+
} else {
|
|
23385
|
+
let e = await t.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND isCanonical = 1 LIMIT 1").get(r);
|
|
23386
|
+
e && (o = e.path);
|
|
23387
|
+
}
|
|
23388
|
+
let s = i.status === "draft" || !!i.hasUnpublishedChanges, c = {
|
|
23198
23389
|
id: i.id,
|
|
23199
23390
|
title: i.title,
|
|
23200
23391
|
slug: i.slug,
|
|
23392
|
+
path: o,
|
|
23201
23393
|
language: i.language || null,
|
|
23202
23394
|
nodeType: i.contentType,
|
|
23203
23395
|
contentType: i.contentType,
|
|
23204
23396
|
isHidden: !!i.isHidden,
|
|
23205
23397
|
status: i.status || "draft",
|
|
23206
23398
|
publishedAt: i.publishedAt || null,
|
|
23207
|
-
hasUnpublishedChanges:
|
|
23399
|
+
hasUnpublishedChanges: s,
|
|
23208
23400
|
deletedAt: i.deletedAt || null,
|
|
23209
23401
|
createdById: i.createdById || null,
|
|
23210
23402
|
updatedById: i.updatedById || null,
|
|
23211
23403
|
createdAt: i.createdAt,
|
|
23212
23404
|
updatedAt: i.updatedAt
|
|
23213
|
-
},
|
|
23214
|
-
if (
|
|
23215
|
-
let n = typeof
|
|
23405
|
+
}, l = i.draftDataJson || i.dataJson;
|
|
23406
|
+
if (l) try {
|
|
23407
|
+
let n = typeof l == "string" ? JSON.parse(l) : l, a = await t.prepare("SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? LIMIT 1").get(r), o = dx(e.env?.BUNDLED_DEFINITIONS).nodes?.[i.contentType] || {}, s = n.layoutId || null;
|
|
23216
23408
|
if (a) {
|
|
23217
|
-
let { resolvedLayoutId: e, inheritedFields: r } = await
|
|
23218
|
-
(
|
|
23409
|
+
let { resolvedLayoutId: e, inheritedFields: r } = await wx(t, a.parentId, a.treeId);
|
|
23410
|
+
(s === "inherit" || !s) && (s = e);
|
|
23219
23411
|
for (let [e, t] of Object.entries(r)) e !== "layoutId" && e !== "subpageLayoutId" && (n[e] === void 0 || n[e] === null || n[e] === "") && t !== void 0 && (n[e] = t);
|
|
23220
23412
|
}
|
|
23221
|
-
|
|
23222
|
-
if (!
|
|
23413
|
+
s && s !== "inherit" && !((e) => {
|
|
23414
|
+
if (!o || Object.keys(o).length === 0 || e === o.defaultLayout) return !0;
|
|
23223
23415
|
let t = null, n = (e) => {
|
|
23224
23416
|
e && (Array.isArray(e) ? e.forEach((e) => {
|
|
23225
23417
|
e.layoutId && (t = e.layoutId);
|
|
23226
23418
|
}) : e.layoutId && (t = e.layoutId));
|
|
23227
23419
|
};
|
|
23228
|
-
if (n(
|
|
23420
|
+
if (n(o.fields), !t && o.tabs && Object.values(o.tabs).forEach((e) => n(e.fields)), !t) return !1;
|
|
23229
23421
|
let r = t.allowedLayouts;
|
|
23230
23422
|
return r ? typeof r == "string" ? r === e : !Array.isArray(r) || r.length === 0 || r.includes(e) : !0;
|
|
23231
|
-
})(
|
|
23232
|
-
let u = await ux(t,
|
|
23233
|
-
Object.assign(
|
|
23423
|
+
})(s) && (s = null), (s === "inherit" || !s) && (s = o.defaultLayout || null);
|
|
23424
|
+
let u = await ux(t, bx(n));
|
|
23425
|
+
Object.assign(c, u), c.resolvedLayoutId = s;
|
|
23234
23426
|
} catch {}
|
|
23235
|
-
let
|
|
23236
|
-
|
|
23237
|
-
let
|
|
23238
|
-
|
|
23239
|
-
let
|
|
23427
|
+
let u = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
|
|
23428
|
+
c.channels = (Array.isArray(u) ? u : u?.results || []).map((e) => e.channelId);
|
|
23429
|
+
let d = await t.prepare("SELECT treeId, parentId, sortOrder FROM tree_nodes WHERE contentId = ?").all(r);
|
|
23430
|
+
c.trees = Array.isArray(d) ? d : d?.results || [];
|
|
23431
|
+
let f = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = 1 ORDER BY sortOrder ASC").all(r), p = Array.isArray(f) ? f : f?.results || [], m = await Promise.all(p.map(async (e) => {
|
|
23240
23432
|
let n = {};
|
|
23241
23433
|
try {
|
|
23242
23434
|
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await ux(t, n));
|
|
@@ -23253,8 +23445,8 @@ px.get("/", async (e) => {
|
|
|
23253
23445
|
};
|
|
23254
23446
|
}));
|
|
23255
23447
|
return e.json({
|
|
23256
|
-
node:
|
|
23257
|
-
blocks:
|
|
23448
|
+
node: c,
|
|
23449
|
+
blocks: m
|
|
23258
23450
|
});
|
|
23259
23451
|
}
|
|
23260
23452
|
let m = [], h = [o ? "(cn.deletedAt IS NOT NULL AND cn.deletedAt != '')" : "(cn.deletedAt IS NULL OR cn.deletedAt = '')"];
|
|
@@ -23282,9 +23474,16 @@ px.get("/", async (e) => {
|
|
|
23282
23474
|
WITH filtered_nodes AS (
|
|
23283
23475
|
SELECT cn.* FROM content_nodes cn ${g} ORDER BY ${y} ${l} LIMIT ? OFFSET ?
|
|
23284
23476
|
)
|
|
23285
|
-
SELECT fn.*,
|
|
23477
|
+
SELECT fn.*,
|
|
23478
|
+
COUNT(DISTINCT CASE WHEN a.mimeType LIKE 'image/%' THEN COALESCE(a.parentAssetId, a.id) END) as imageCount,
|
|
23479
|
+
COUNT(DISTINCT CASE WHEN a.mimeType LIKE 'video/%' OR a.mimeType LIKE 'audio/%' THEN COALESCE(a.parentAssetId, a.id) END) as videoCount,
|
|
23480
|
+
COUNT(DISTINCT CASE WHEN a.mimeType LIKE 'application/pdf%' OR a.mimeType LIKE 'application/msword%' OR a.mimeType LIKE 'application/vnd%' OR a.mimeType LIKE 'text/%' THEN COALESCE(a.parentAssetId, a.id) END) as documentCount,
|
|
23481
|
+
COUNT(DISTINCT CASE WHEN a.id IS NOT NULL AND a.mimeType NOT LIKE 'image/%' AND a.mimeType NOT LIKE 'video/%' AND a.mimeType NOT LIKE 'audio/%' AND a.mimeType NOT LIKE 'application/pdf%' AND a.mimeType NOT LIKE 'application/msword%' AND a.mimeType NOT LIKE 'application/vnd%' AND a.mimeType NOT LIKE 'text/%' THEN COALESCE(a.parentAssetId, a.id) END) as otherCount,
|
|
23482
|
+
COUNT(DISTINCT COALESCE(a.parentAssetId, a.id)) as assetCount,
|
|
23483
|
+
(SELECT path FROM node_routes nr WHERE nr.nodeId = fn.id AND isCanonical = 1 LIMIT 1) as routePath
|
|
23286
23484
|
FROM filtered_nodes fn
|
|
23287
23485
|
LEFT JOIN node_assets na ON fn.id = na.nodeId
|
|
23486
|
+
LEFT JOIN assets a ON na.assetId = a.id
|
|
23288
23487
|
GROUP BY fn.id ORDER BY ${y.replace("cn.", "fn.")} ${l}
|
|
23289
23488
|
`, S = [
|
|
23290
23489
|
...m,
|
|
@@ -23310,6 +23509,7 @@ px.get("/", async (e) => {
|
|
|
23310
23509
|
id: e.id,
|
|
23311
23510
|
title: e.title,
|
|
23312
23511
|
slug: e.slug,
|
|
23512
|
+
path: e.routePath || null,
|
|
23313
23513
|
language: e.language || null,
|
|
23314
23514
|
contentType: e.contentType,
|
|
23315
23515
|
nodeType: e.contentType,
|
|
@@ -23324,10 +23524,14 @@ px.get("/", async (e) => {
|
|
|
23324
23524
|
updatedAt: e.updatedAt,
|
|
23325
23525
|
channelNames: T[e.id] || [],
|
|
23326
23526
|
treeNames: E[e.id] || [],
|
|
23327
|
-
assetCount: e.assetCount || 0
|
|
23527
|
+
assetCount: e.assetCount || 0,
|
|
23528
|
+
imageCount: e.imageCount || 0,
|
|
23529
|
+
videoCount: e.videoCount || 0,
|
|
23530
|
+
documentCount: e.documentCount || 0,
|
|
23531
|
+
otherCount: e.otherCount || 0
|
|
23328
23532
|
}, i = e.draftDataJson || e.dataJson;
|
|
23329
23533
|
if (i) try {
|
|
23330
|
-
let e = typeof i == "string" ? JSON.parse(i) : i, n = await ux(t,
|
|
23534
|
+
let e = typeof i == "string" ? JSON.parse(i) : i, n = await ux(t, bx(e));
|
|
23331
23535
|
Object.assign(r, n);
|
|
23332
23536
|
} catch {}
|
|
23333
23537
|
return r;
|
|
@@ -23339,8 +23543,8 @@ px.get("/", async (e) => {
|
|
|
23339
23543
|
offset: p,
|
|
23340
23544
|
limit: f
|
|
23341
23545
|
});
|
|
23342
|
-
}),
|
|
23343
|
-
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, ..._ } = r, { cleanedData: v, assetRefs: y, termRefs: b } = ax(
|
|
23546
|
+
}), mx.post("/", async (e) => {
|
|
23547
|
+
let t = e.get("db"), n = await e.req.json(), r = n.node || n.activeNode || n, i = r.id || n.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { title: o, slug: s, language: c, nodeType: l, contentType: u, isHidden: d, hidden: f, is_hidden: p, blocks: m, channels: h, trees: g, ..._ } = r, { cleanedData: v, assetRefs: y, termRefs: b } = ax(bx(_)), x = vx(d === void 0 ? f === void 0 ? p : f : d), S = l || u || "page", C = e.get("user")?.id || null, ee = typeof c == "string" && c.trim() !== "" ? c.trim() : null, w = g && Array.isArray(g) && g.length > 0 ? g[0] : null, T = w ? w.treeId || w.id : null, E = null;
|
|
23344
23548
|
if (T) {
|
|
23345
23549
|
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(T) || -1, String(T));
|
|
23346
23550
|
if (e?.dataJson) try {
|
|
@@ -23362,12 +23566,12 @@ px.get("/", async (e) => {
|
|
|
23362
23566
|
}
|
|
23363
23567
|
}
|
|
23364
23568
|
ee && E && ee === E && (ee = null);
|
|
23365
|
-
let D = a, te = /* @__PURE__ */ new Set(),
|
|
23366
|
-
if (
|
|
23569
|
+
let D = a, te = /* @__PURE__ */ new Set(), ne = !1, O = "draft", k = 0, A = s === void 0 ? null : _x(s);
|
|
23570
|
+
if (A) {
|
|
23367
23571
|
let n = [];
|
|
23368
23572
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
23369
23573
|
treeId: Number(e.treeId),
|
|
23370
|
-
parentId:
|
|
23574
|
+
parentId: yx(e.parentId ?? e._draftParentId ?? null)
|
|
23371
23575
|
});
|
|
23372
23576
|
else if (a) {
|
|
23373
23577
|
let e = await t.prepare("SELECT treeId, parentId FROM tree_nodes WHERE contentId = ?").all(a), r = Array.isArray(e) ? e : e?.results || [];
|
|
@@ -23377,32 +23581,32 @@ px.get("/", async (e) => {
|
|
|
23377
23581
|
});
|
|
23378
23582
|
}
|
|
23379
23583
|
for (let r of n) {
|
|
23380
|
-
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId,
|
|
23584
|
+
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId, A] : [
|
|
23381
23585
|
r.treeId,
|
|
23382
23586
|
r.parentId,
|
|
23383
|
-
|
|
23587
|
+
A
|
|
23384
23588
|
], o = `
|
|
23385
23589
|
SELECT cn.id FROM tree_nodes tn
|
|
23386
23590
|
INNER JOIN content_nodes cn ON tn.contentId = cn.id
|
|
23387
23591
|
WHERE tn.treeId = ? AND ${n} AND cn.slug = ? AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
23388
23592
|
`;
|
|
23389
23593
|
if (a && (o += " AND cn.id != ?", i.push(a)), o += " LIMIT 1", await t.prepare(o).get(...i)) return e.json({
|
|
23390
|
-
error: `The slug '${
|
|
23594
|
+
error: `The slug '${A}' is already in use by another page in this section.`,
|
|
23391
23595
|
field: "slug"
|
|
23392
23596
|
}, 409);
|
|
23393
23597
|
}
|
|
23394
23598
|
}
|
|
23395
23599
|
if (a) {
|
|
23396
23600
|
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
23397
|
-
|
|
23601
|
+
ne = Sx(e, {
|
|
23398
23602
|
title: o,
|
|
23399
|
-
slug:
|
|
23603
|
+
slug: A,
|
|
23400
23604
|
isHidden: x,
|
|
23401
23605
|
sanitizedFields: v
|
|
23402
23606
|
});
|
|
23403
23607
|
let n = e?.draftDataJson || e?.dataJson || "{}";
|
|
23404
23608
|
try {
|
|
23405
|
-
|
|
23609
|
+
xx(typeof n == "string" ? JSON.parse(n) : n, te);
|
|
23406
23610
|
} catch {}
|
|
23407
23611
|
let r = {};
|
|
23408
23612
|
try {
|
|
@@ -23412,7 +23616,7 @@ px.get("/", async (e) => {
|
|
|
23412
23616
|
...r,
|
|
23413
23617
|
...v
|
|
23414
23618
|
}), l = !1;
|
|
23415
|
-
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (l = !0), s !== void 0 &&
|
|
23619
|
+
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (l = !0), s !== void 0 && A !== e?.slug && (l = !0), c !== void 0 && ee !== e?.language && (l = !0), !l && Object.keys(v).length > 0) {
|
|
23416
23620
|
for (let e of Object.keys(v)) if (JSON.stringify(v[e]) !== JSON.stringify(r[e])) {
|
|
23417
23621
|
l = !0;
|
|
23418
23622
|
break;
|
|
@@ -23434,13 +23638,13 @@ px.get("/", async (e) => {
|
|
|
23434
23638
|
}
|
|
23435
23639
|
}
|
|
23436
23640
|
}
|
|
23437
|
-
let u = o === void 0 ? e?.title || "Untitled" : o, d =
|
|
23438
|
-
|
|
23641
|
+
let u = o === void 0 ? e?.title || "Untitled" : o, d = A ?? e?.slug ?? null, f = S || e?.contentType || "page", p = c === void 0 ? e?.language : ee;
|
|
23642
|
+
O = e?.status === "published" || e?.publishedAt ? "published" : "draft";
|
|
23439
23643
|
let h = e?.hasUnpublishedChanges === 1 || e?.hasUnpublishedChanges === !0;
|
|
23440
|
-
|
|
23644
|
+
k = 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, x, O, i, k, C, a);
|
|
23441
23645
|
} else {
|
|
23442
|
-
|
|
23443
|
-
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(S, o || "Untitled",
|
|
23646
|
+
ne = !0;
|
|
23647
|
+
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(S, o || "Untitled", A, ee, x, JSON.stringify(v), C, C);
|
|
23444
23648
|
D = Number(e.lastInsertRowid);
|
|
23445
23649
|
}
|
|
23446
23650
|
if (h !== void 0 && Array.isArray(h) && D) {
|
|
@@ -23453,10 +23657,10 @@ px.get("/", async (e) => {
|
|
|
23453
23657
|
}
|
|
23454
23658
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
23455
23659
|
if (!e || !e.treeId) continue;
|
|
23456
|
-
let n = Number(e.treeId) || e.treeId, r =
|
|
23457
|
-
a ? ((a.parentId !== r || a.sortOrder !== i) && (
|
|
23660
|
+
let n = Number(e.treeId) || e.treeId, r = yx(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);
|
|
23661
|
+
a ? ((a.parentId !== r || a.sortOrder !== i) && (ne = !0), await t.prepare("UPDATE tree_nodes SET parentId = ?, sortOrder = ? WHERE treeId = ? AND contentId = ?").run(r, i, n, D)) : (ne = !0, await t.prepare("INSERT INTO tree_nodes (treeId, contentId, parentId, sortOrder) VALUES (?, ?, ?, ?)").run(n, D, r, i));
|
|
23458
23662
|
}
|
|
23459
|
-
let
|
|
23663
|
+
let re = [], ie = [];
|
|
23460
23664
|
if (m !== void 0 && Array.isArray(m) && D) {
|
|
23461
23665
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
23462
23666
|
let e = [], n = [];
|
|
@@ -23466,10 +23670,10 @@ px.get("/", async (e) => {
|
|
|
23466
23670
|
blockId: o,
|
|
23467
23671
|
_instanceId: o
|
|
23468
23672
|
});
|
|
23469
|
-
c.forEach((e) =>
|
|
23673
|
+
c.forEach((e) => re.push({
|
|
23470
23674
|
...e,
|
|
23471
23675
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
23472
|
-
})), l.forEach((e) =>
|
|
23676
|
+
})), l.forEach((e) => ie.push({
|
|
23473
23677
|
...e,
|
|
23474
23678
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
23475
23679
|
}));
|
|
@@ -23479,22 +23683,22 @@ px.get("/", async (e) => {
|
|
|
23479
23683
|
e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
23480
23684
|
}
|
|
23481
23685
|
if (D) {
|
|
23482
|
-
let n = [...y, ...
|
|
23686
|
+
let n = [...y, ...re], r = [...b, ...ie];
|
|
23483
23687
|
await ox(t, D, n), await sx(t, D, r);
|
|
23484
23688
|
let i = new Set(n.map((e) => e.assetId)), a = new Set([...te].filter((e) => !i.has(e)));
|
|
23485
23689
|
if (a.size > 0) {
|
|
23486
23690
|
let { storage: n } = ix(e.env);
|
|
23487
|
-
await
|
|
23691
|
+
await Cx(t, n, a);
|
|
23488
23692
|
}
|
|
23489
23693
|
}
|
|
23490
|
-
return await $b(e).clear(), e.json({
|
|
23694
|
+
return await $b(e).clear(), ne && await px(t), e.json({
|
|
23491
23695
|
success: !0,
|
|
23492
23696
|
id: D,
|
|
23493
|
-
status:
|
|
23494
|
-
hasUnpublishedChanges:
|
|
23495
|
-
isStructuralChange:
|
|
23697
|
+
status: O,
|
|
23698
|
+
hasUnpublishedChanges: k === 1 || O === "draft",
|
|
23699
|
+
isStructuralChange: ne
|
|
23496
23700
|
});
|
|
23497
|
-
}),
|
|
23701
|
+
}), mx.post("/publish", async (e) => {
|
|
23498
23702
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
23499
23703
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
23500
23704
|
let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
|
|
@@ -23527,7 +23731,7 @@ px.get("/", async (e) => {
|
|
|
23527
23731
|
},
|
|
23528
23732
|
blocks: v
|
|
23529
23733
|
};
|
|
23530
|
-
return await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, y, JSON.stringify(b), a), await $b(e).clear(), new fx(e.env).purgeNode(e, t, i, h), e.json({
|
|
23734
|
+
return await t.prepare("INSERT INTO node_revisions (nodeId, version, snapshotJson, createdById) VALUES (?, ?, ?, ?)").run(i, y, JSON.stringify(b), a), await $b(e).clear(), new fx(e.env).purgeNode(e, t, i, h), h && await px(t), e.json({
|
|
23531
23735
|
success: !0,
|
|
23532
23736
|
id: i,
|
|
23533
23737
|
status: "published",
|
|
@@ -23536,29 +23740,29 @@ px.get("/", async (e) => {
|
|
|
23536
23740
|
hasUnpublishedChanges: !1,
|
|
23537
23741
|
isStructuralChange: h
|
|
23538
23742
|
});
|
|
23539
|
-
}),
|
|
23743
|
+
}), mx.delete("/", async (e) => {
|
|
23540
23744
|
let t = e.get("db"), n = e.req.query("id");
|
|
23541
23745
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
23542
23746
|
let r = Number(n);
|
|
23543
|
-
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await $b(e).clear(), new fx(e.env).purgeNode(e, t, r, !0), e.json({
|
|
23747
|
+
return await t.prepare("UPDATE content_nodes SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?").run(r), await $b(e).clear(), new fx(e.env).purgeNode(e, t, r, !0), await px(t), e.json({
|
|
23544
23748
|
success: !0,
|
|
23545
23749
|
deletedNodeId: r
|
|
23546
23750
|
});
|
|
23547
|
-
}),
|
|
23751
|
+
}), mx.post("/restore", async (e) => {
|
|
23548
23752
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
23549
|
-
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await $b(e).clear(), new fx(e.env).purgeNode(e, t, r, !0), e.json({
|
|
23753
|
+
return r ? await t.prepare("SELECT id FROM content_nodes WHERE id = ?").get(r) ? (await t.prepare("UPDATE content_nodes SET deletedAt = NULL WHERE id = ?").run(r), await $b(e).clear(), new fx(e.env).purgeNode(e, t, r, !0), await px(t), e.json({
|
|
23550
23754
|
success: !0,
|
|
23551
23755
|
restoredNodeId: r
|
|
23552
23756
|
})) : e.json({ error: "Node not found" }, 404) : e.json({ error: "Node ID required" }, 400);
|
|
23553
|
-
}),
|
|
23757
|
+
}), mx.delete("/purge", async (e) => {
|
|
23554
23758
|
let t = e.get("db"), n = e.req.query("id");
|
|
23555
23759
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
23556
23760
|
let r = Number(n);
|
|
23557
|
-
return new fx(e.env).purgeNode(e, t, r, !0), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await $b(e).clear(), e.json({
|
|
23761
|
+
return new fx(e.env).purgeNode(e, t, r, !0), await t.prepare("DELETE FROM node_channels WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE contentId = ?").run(r), await t.prepare("DELETE FROM content_blocks WHERE contentId = ?").run(r), await t.prepare("DELETE FROM node_revisions WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(r), await t.prepare("DELETE FROM content_nodes WHERE id = ?").run(r), await $b(e).clear(), await px(t), e.json({
|
|
23558
23762
|
success: !0,
|
|
23559
23763
|
purgedNodeId: r
|
|
23560
23764
|
});
|
|
23561
|
-
}),
|
|
23765
|
+
}), mx.get("/:id/revisions", async (e) => {
|
|
23562
23766
|
let t = e.get("db"), n = Number(e.req.param("id"));
|
|
23563
23767
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
23564
23768
|
let r = await t.prepare("\n SELECT version, createdById, snapshotJson \n FROM node_revisions \n WHERE nodeId = ? \n ORDER BY version DESC\n ").all(n), i = (Array.isArray(r) ? r : r?.results || []).map((e) => {
|
|
@@ -23574,7 +23778,7 @@ px.get("/", async (e) => {
|
|
|
23574
23778
|
};
|
|
23575
23779
|
});
|
|
23576
23780
|
return e.json({ revisions: i });
|
|
23577
|
-
}),
|
|
23781
|
+
}), mx.get("/:id/revisions/:version", async (e) => {
|
|
23578
23782
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
23579
23783
|
if (!i) return e.json({ error: "Snapshot not found" }, 404);
|
|
23580
23784
|
let a = {};
|
|
@@ -23584,7 +23788,7 @@ px.get("/", async (e) => {
|
|
|
23584
23788
|
return e.json({ error: "Corrupt snapshot data" }, 500);
|
|
23585
23789
|
}
|
|
23586
23790
|
return e.json({ snapshot: a });
|
|
23587
|
-
}),
|
|
23791
|
+
}), mx.post("/:id/revisions/:version/restore", async (e) => {
|
|
23588
23792
|
let t = e.get("db"), n = Number(e.req.param("id")), r = Number(e.req.param("version")), i = e.get("user")?.id || null, a = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(n, r);
|
|
23589
23793
|
if (!a) return e.json({ error: "Snapshot not found" }, 404);
|
|
23590
23794
|
let o = {};
|
|
@@ -23598,13 +23802,13 @@ px.get("/", async (e) => {
|
|
|
23598
23802
|
for (let t of o.blocks) e.push("(?, ?, ?, ?, ?, 1)"), r.push(n, t.sortOrder, t.elementType, t.dataJson, t.region || "content");
|
|
23599
23803
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...r);
|
|
23600
23804
|
}
|
|
23601
|
-
return await $b(e).clear(), e.json({
|
|
23805
|
+
return await $b(e).clear(), await px(t), e.json({
|
|
23602
23806
|
success: !0,
|
|
23603
23807
|
restoredVersion: r
|
|
23604
23808
|
});
|
|
23605
23809
|
});
|
|
23606
|
-
var
|
|
23607
|
-
function
|
|
23810
|
+
var Tx = new e();
|
|
23811
|
+
function Ex(e, t = null) {
|
|
23608
23812
|
let n = [];
|
|
23609
23813
|
for (let r = 0; r < e.length; r++) {
|
|
23610
23814
|
let i = e[r];
|
|
@@ -23616,19 +23820,19 @@ function Tx(e, t = null) {
|
|
|
23616
23820
|
id: o,
|
|
23617
23821
|
parentId: t,
|
|
23618
23822
|
sortOrder: r
|
|
23619
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
23823
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Ex(i.children, o)));
|
|
23620
23824
|
}
|
|
23621
23825
|
return n;
|
|
23622
23826
|
}
|
|
23623
|
-
function
|
|
23827
|
+
function Dx(e) {
|
|
23624
23828
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
23625
23829
|
let t = Number(e);
|
|
23626
23830
|
return isNaN(t) ? null : t;
|
|
23627
23831
|
}
|
|
23628
|
-
function
|
|
23832
|
+
function Ox(e) {
|
|
23629
23833
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
23630
23834
|
}
|
|
23631
|
-
|
|
23835
|
+
Tx.get("/tree.json", async (e) => {
|
|
23632
23836
|
try {
|
|
23633
23837
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
23634
23838
|
if (isNaN(Number(n))) {
|
|
@@ -23681,7 +23885,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23681
23885
|
} catch (t) {
|
|
23682
23886
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
23683
23887
|
}
|
|
23684
|
-
}),
|
|
23888
|
+
}), Tx.post("/tree.json", async (e) => {
|
|
23685
23889
|
try {
|
|
23686
23890
|
let t = e.get("db"), n = await e.req.json(), r = n.treeId ? String(n.treeId).trim() : "main-nav", i = $b(e), a = new fx(e.env), o = 1;
|
|
23687
23891
|
if (isNaN(Number(r))) {
|
|
@@ -23693,7 +23897,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23693
23897
|
}
|
|
23694
23898
|
} else o = Number(r);
|
|
23695
23899
|
if (n.tree && Array.isArray(n.tree)) {
|
|
23696
|
-
let r =
|
|
23900
|
+
let r = Ex(n.tree, null);
|
|
23697
23901
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
23698
23902
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
23699
23903
|
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
@@ -23708,14 +23912,14 @@ wx.get("/tree.json", async (e) => {
|
|
|
23708
23912
|
c.push(e.id, e.sortOrder);
|
|
23709
23913
|
}), c.push(...i), c.push(o), await t.prepare(s).run(...c);
|
|
23710
23914
|
}
|
|
23711
|
-
return await i.clear(), r.length > 0 && a.purgeNode(e, t, r[0].id, !0), e.json({
|
|
23915
|
+
return await i.clear(), r.length > 0 && a.purgeNode(e, t, r[0].id, !0), await px(t), e.json({
|
|
23712
23916
|
success: !0,
|
|
23713
23917
|
reorderedCount: r.length
|
|
23714
23918
|
});
|
|
23715
23919
|
}
|
|
23716
|
-
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h =
|
|
23920
|
+
let { action: s, title: c, nodeType: l, parentId: u, contentId: d, nodeData: f = {}, pageData: p = {} } = n, m = Object.keys(f).length > 0 ? { ...f } : { ...p }, h = Ox(n.isHidden === void 0 ? m.isHidden === void 0 ? m.hidden : m.isHidden : n.isHidden);
|
|
23717
23921
|
delete m._isTreeDraft, delete m._draftParentId, delete m.isNew, delete m.nodeType, delete m.contentType, delete m.title, delete m.slug, delete m.hidden, delete m.is_hidden, delete m.isHidden, delete m.status;
|
|
23718
|
-
let g =
|
|
23922
|
+
let g = Dx(u), _ = e.get("user")?.id || null;
|
|
23719
23923
|
if (s === "create") {
|
|
23720
23924
|
let r = m.slug || n.slug || c, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
23721
23925
|
if (a) {
|
|
@@ -23770,7 +23974,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23770
23974
|
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [f, e]);
|
|
23771
23975
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
23772
23976
|
}
|
|
23773
|
-
return await i.clear(), e.json({
|
|
23977
|
+
return await i.clear(), await px(t), e.json({
|
|
23774
23978
|
success: !0,
|
|
23775
23979
|
id: f,
|
|
23776
23980
|
treeNodeId: f,
|
|
@@ -23807,14 +24011,14 @@ wx.get("/tree.json", async (e) => {
|
|
|
23807
24011
|
field: "slug"
|
|
23808
24012
|
}, 409);
|
|
23809
24013
|
}
|
|
23810
|
-
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({
|
|
24014
|
+
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), await px(t), e.json({
|
|
23811
24015
|
success: !0,
|
|
23812
24016
|
treeNodeId: d
|
|
23813
24017
|
});
|
|
23814
24018
|
}
|
|
23815
24019
|
if (s === "detach") {
|
|
23816
24020
|
let r = n.contentId || n.id || n.treeNodeId;
|
|
23817
|
-
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);
|
|
24021
|
+
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), await px(t), e.json({ success: !0 })) : e.json({ error: "contentId required for detach" }, 400);
|
|
23818
24022
|
}
|
|
23819
24023
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
23820
24024
|
} catch (t) {
|
|
@@ -23823,7 +24027,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23823
24027
|
details: t.message
|
|
23824
24028
|
}, 500);
|
|
23825
24029
|
}
|
|
23826
|
-
}),
|
|
24030
|
+
}), Tx.get("/trees.json", async (e) => {
|
|
23827
24031
|
try {
|
|
23828
24032
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM trees ORDER BY LOWER(label) ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId FROM channel_trees").all(), a = (Array.isArray(i) ? i : i?.results || []).reduce((e, t) => {
|
|
23829
24033
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -23853,7 +24057,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23853
24057
|
} catch {
|
|
23854
24058
|
return e.json([]);
|
|
23855
24059
|
}
|
|
23856
|
-
}),
|
|
24060
|
+
}), Tx.post("/trees.json", async (e) => {
|
|
23857
24061
|
try {
|
|
23858
24062
|
let t = e.get("db"), n = await e.req.json(), r = n.id, i = r != null && r !== "" && !isNaN(Number(r)) ? Number(r) : null, a = `tree-${Date.now().toString(36)}`, o = (n.key || n.slug || a).toLowerCase().replace(/[^a-z0-9_-]/g, "-"), s = n.label?.trim() || o, c = n.treeType !== void 0 && n.treeType !== null ? n.treeType : n.type ?? "site", l = n.channelId !== void 0 && n.channelId !== null && Number(n.channelId) || null, u = +(n.isHidden === !0 || n.isHidden === 1 || n.isHidden === "true"), d = e.get("user")?.id || null, f = { ...n };
|
|
23859
24063
|
if (delete f.id, delete f.key, delete f.label, delete f.treeType, delete f.type, delete f.channelId, delete f.channels, delete f.isHidden, delete f.createdById, delete f.updatedById, delete f.createdAt, delete f.updatedAt, await t.prepare("SELECT id FROM trees WHERE key = ? AND id != ? LIMIT 1").get(o, i ?? -1)) return e.json({
|
|
@@ -23878,7 +24082,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23878
24082
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
23879
24083
|
}
|
|
23880
24084
|
}
|
|
23881
|
-
return await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), e.json({
|
|
24085
|
+
return await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), await px(t), e.json({
|
|
23882
24086
|
success: !0,
|
|
23883
24087
|
id: p,
|
|
23884
24088
|
key: o,
|
|
@@ -23892,12 +24096,12 @@ wx.get("/tree.json", async (e) => {
|
|
|
23892
24096
|
} catch (t) {
|
|
23893
24097
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
23894
24098
|
}
|
|
23895
|
-
}),
|
|
24099
|
+
}), Tx.delete("/trees.json", async (e) => {
|
|
23896
24100
|
let t = e.get("db"), n = e.req.query("id");
|
|
23897
24101
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
23898
24102
|
let r = Number(n);
|
|
23899
24103
|
try {
|
|
23900
|
-
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), e.json({
|
|
24104
|
+
return await t.prepare("DELETE FROM trees WHERE id = ?").run(r), await t.prepare("DELETE FROM channel_trees WHERE treeId = ?").run(r), await t.prepare("DELETE FROM tree_nodes WHERE treeId = ?").run(r), await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), await px(t), e.json({
|
|
23901
24105
|
success: !0,
|
|
23902
24106
|
deletedTreeId: r
|
|
23903
24107
|
});
|
|
@@ -23905,8 +24109,8 @@ wx.get("/tree.json", async (e) => {
|
|
|
23905
24109
|
return e.json({ error: "Failed to delete tree" }, 500);
|
|
23906
24110
|
}
|
|
23907
24111
|
});
|
|
23908
|
-
var
|
|
23909
|
-
|
|
24112
|
+
var kx = new e();
|
|
24113
|
+
kx.get("/", async (e) => {
|
|
23910
24114
|
try {
|
|
23911
24115
|
let t = e.get("db"), n = await t.prepare("SELECT * FROM channels ORDER BY id ASC").all(), r = Array.isArray(n) ? n : n?.results || [], i = await t.prepare("SELECT channelId, treeId, key, metaJson FROM channel_trees").all(), a = ((Array.isArray(i) ? i : i?.results || []) || []).reduce((e, t) => {
|
|
23912
24116
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -23972,7 +24176,7 @@ Ox.get("/", async (e) => {
|
|
|
23972
24176
|
error: t.message
|
|
23973
24177
|
}, 500);
|
|
23974
24178
|
}
|
|
23975
|
-
}),
|
|
24179
|
+
}), kx.post("/", async (e) => {
|
|
23976
24180
|
try {
|
|
23977
24181
|
let t = e.get("db"), n = await e.req.json(), r = n.channel || n.data || n, i = r.id, a = i != null && i !== "" && !isNaN(Number(i)) ? Number(i) : null, { key: o, label: s, channelType: c = "website", domain: l = "localhost", baseUrl: u = "http://localhost:4321", defaultLanguage: d, default_language: f, language: p, isHidden: m, hidden: h, trees: g = [], createdById: _ = null, updatedById: v = null, id: y, createdAt: b, updatedAt: x, ...S } = r, C = o?.trim() || "main", ee = s?.trim() || "Untitled Channel", w = d || f || p || "";
|
|
23978
24182
|
typeof w == "object" && w && (w = w.value || w.id || ""), w = String(w).trim();
|
|
@@ -23981,17 +24185,17 @@ Ox.get("/", async (e) => {
|
|
|
23981
24185
|
error: `Channel API key "${C}" is already in use.`,
|
|
23982
24186
|
field: "key"
|
|
23983
24187
|
}, 409);
|
|
23984
|
-
let
|
|
24188
|
+
let ne = a;
|
|
23985
24189
|
if (a) await t.prepare("\n UPDATE channels \n SET key = ?, label = ?, channelType = ?, domain = ?, baseUrl = ?, defaultLanguage = ?, \n isHidden = ?, dataJson = ?, updatedById = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ").run(C, ee, c, l, u, w, +!!T, D, te, a);
|
|
23986
24190
|
else {
|
|
23987
24191
|
let e = await t.prepare("\n INSERT INTO channels (key, label, channelType, domain, baseUrl, defaultLanguage, isHidden, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ").run(C, ee, c, l, u, w, +!!T, D, te, te);
|
|
23988
|
-
|
|
24192
|
+
ne = Number(e.lastInsertRowid);
|
|
23989
24193
|
}
|
|
23990
|
-
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(
|
|
23991
|
-
let
|
|
23992
|
-
if (
|
|
23993
|
-
let e =
|
|
23994
|
-
|
|
24194
|
+
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(ne);
|
|
24195
|
+
let O = E.filter((e) => e && e.treeId && e.key);
|
|
24196
|
+
if (O.length > 0) {
|
|
24197
|
+
let e = O.map(() => "(?, ?, ?, ?)").join(", "), n = O.flatMap((e) => [
|
|
24198
|
+
ne,
|
|
23995
24199
|
Number(e.treeId) || e.treeId,
|
|
23996
24200
|
String(e.key).trim(),
|
|
23997
24201
|
JSON.stringify(e.meta || {})
|
|
@@ -24001,10 +24205,10 @@ Ox.get("/", async (e) => {
|
|
|
24001
24205
|
VALUES ${e}
|
|
24002
24206
|
`).run(...n);
|
|
24003
24207
|
}
|
|
24004
|
-
let
|
|
24005
|
-
return await
|
|
24208
|
+
let k = $b(e);
|
|
24209
|
+
return await k.delete(`channel:${C}`), await k.delete(`channel:${ne}`), await k.clear(), new fx(e.env).purgeGlobalCache(e, t), e.json({
|
|
24006
24210
|
success: !0,
|
|
24007
|
-
id:
|
|
24211
|
+
id: ne
|
|
24008
24212
|
});
|
|
24009
24213
|
} catch (t) {
|
|
24010
24214
|
return console.error("[API Channels] Error saving channel:", t), e.json({
|
|
@@ -24012,7 +24216,7 @@ Ox.get("/", async (e) => {
|
|
|
24012
24216
|
details: t.message
|
|
24013
24217
|
}, 500);
|
|
24014
24218
|
}
|
|
24015
|
-
}),
|
|
24219
|
+
}), kx.delete("/", async (e) => {
|
|
24016
24220
|
let t = e.get("db"), n = e.req.query("id");
|
|
24017
24221
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
24018
24222
|
let r = Number(n);
|
|
@@ -24030,15 +24234,15 @@ Ox.get("/", async (e) => {
|
|
|
24030
24234
|
}, 500);
|
|
24031
24235
|
}
|
|
24032
24236
|
});
|
|
24033
|
-
var
|
|
24034
|
-
function
|
|
24237
|
+
var Ax = new e();
|
|
24238
|
+
function jx(e) {
|
|
24035
24239
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
24036
24240
|
}
|
|
24037
|
-
function
|
|
24241
|
+
function Mx(e) {
|
|
24038
24242
|
let t = (e || "").trim().toLowerCase(), n = dx()?.taxonomies || {};
|
|
24039
24243
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
24040
24244
|
}
|
|
24041
|
-
async function
|
|
24245
|
+
async function Nx(e, t, n = []) {
|
|
24042
24246
|
let r = e.prepare(t);
|
|
24043
24247
|
if (typeof r.bind == "function") {
|
|
24044
24248
|
let e = await r.bind(...n).all();
|
|
@@ -24050,10 +24254,10 @@ async function Mx(e, t, n = []) {
|
|
|
24050
24254
|
}
|
|
24051
24255
|
return [];
|
|
24052
24256
|
}
|
|
24053
|
-
|
|
24054
|
-
let t = e.get("db"), n =
|
|
24257
|
+
Ax.get("/:taxonomy", async (e) => {
|
|
24258
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy"));
|
|
24055
24259
|
try {
|
|
24056
|
-
let r = (await
|
|
24260
|
+
let r = (await Nx(t, "\n SELECT id, taxonomy, key, label, parentId, sortOrder, dataJson, createdAt, updatedAt\n FROM taxonomy_terms\n WHERE taxonomy = ?\n ORDER BY sortOrder ASC, label ASC\n ", [n])).map((e) => ({
|
|
24057
24261
|
...e,
|
|
24058
24262
|
data: e.dataJson ? JSON.parse(e.dataJson) : {}
|
|
24059
24263
|
}));
|
|
@@ -24064,12 +24268,12 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24064
24268
|
} catch (t) {
|
|
24065
24269
|
return console.error("[Taxonomy API] Error fetching terms:", t), e.json({ error: "Failed to fetch taxonomy terms" }, 500);
|
|
24066
24270
|
}
|
|
24067
|
-
}),
|
|
24068
|
-
let t = e.get("db"), n =
|
|
24271
|
+
}), Ax.post("/:taxonomy", async (e) => {
|
|
24272
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = await e.req.json(), i = r.label?.trim();
|
|
24069
24273
|
if (!i) return e.json({ error: "Label is required" }, 400);
|
|
24070
|
-
let a = r.key?.trim() ||
|
|
24274
|
+
let a = r.key?.trim() || jx(i), o = r.parentId ? Number(r.parentId) : null, s = r.sortOrder ? Number(r.sortOrder) : 0, c = r.data ? JSON.stringify(r.data) : "{}";
|
|
24071
24275
|
try {
|
|
24072
|
-
if ((await
|
|
24276
|
+
if ((await Nx(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", [n, a])).length > 0) return e.json({ error: `A term with the key '${a}' already exists in this taxonomy.` }, 409);
|
|
24073
24277
|
let r = t.prepare("\n INSERT INTO taxonomy_terms (taxonomy, key, label, parentId, sortOrder, dataJson)\n VALUES (?, ?, ?, ?, ?, ?)\n "), l;
|
|
24074
24278
|
return l = typeof r.bind == "function" ? await r.bind(n, a, i, o, s, c).run() : await r.run(n, a, i, o, s, c), e.json({
|
|
24075
24279
|
success: !0,
|
|
@@ -24078,12 +24282,12 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24078
24282
|
} catch (t) {
|
|
24079
24283
|
return console.error("[Taxonomy API] Error creating term:", t), e.json({ error: "Failed to create taxonomy term" }, 500);
|
|
24080
24284
|
}
|
|
24081
|
-
}),
|
|
24082
|
-
let t = e.get("db"), n =
|
|
24285
|
+
}), Ax.put("/:taxonomy/:id", async (e) => {
|
|
24286
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
24083
24287
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
24084
24288
|
let i = await e.req.json();
|
|
24085
24289
|
try {
|
|
24086
|
-
let a = await
|
|
24290
|
+
let a = await Nx(t, "SELECT * FROM taxonomy_terms WHERE id = ? AND taxonomy = ?", [r, n]);
|
|
24087
24291
|
if (a.length === 0) return e.json({ error: "Term not found" }, 404);
|
|
24088
24292
|
let o = a[0], s = i.label === void 0 ? o.label : i.label.trim(), c = i.key === void 0 ? o.key : i.key.trim(), l = i.parentId === void 0 ? o.parentId : i.parentId ? Number(i.parentId) : null, u = i.sortOrder === void 0 ? o.sortOrder : Number(i.sortOrder), d = o.dataJson;
|
|
24089
24293
|
if (i.data) {
|
|
@@ -24093,14 +24297,14 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24093
24297
|
...i.data
|
|
24094
24298
|
});
|
|
24095
24299
|
}
|
|
24096
|
-
if (c !== o.key && (await
|
|
24300
|
+
if (c !== o.key && (await Nx(t, "SELECT id FROM taxonomy_terms WHERE taxonomy = ? AND key = ?", [n, c])).length > 0) return e.json({ error: `A term with the key '${c}' already exists in this taxonomy.` }, 409);
|
|
24097
24301
|
let f = t.prepare("\n UPDATE taxonomy_terms \n SET label = ?, key = ?, parentId = ?, sortOrder = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ");
|
|
24098
24302
|
return typeof f.bind == "function" ? await f.bind(s, c, l, u, d, r).run() : await f.run(s, c, l, u, d, r), e.json({ success: !0 });
|
|
24099
24303
|
} catch (t) {
|
|
24100
24304
|
return console.error("[Taxonomy API] Error updating term:", t), e.json({ error: "Failed to update taxonomy term" }, 500);
|
|
24101
24305
|
}
|
|
24102
|
-
}),
|
|
24103
|
-
let t = e.get("db"), n =
|
|
24306
|
+
}), Ax.delete("/:taxonomy/:id", async (e) => {
|
|
24307
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
24104
24308
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
24105
24309
|
try {
|
|
24106
24310
|
let i = t.prepare("DELETE FROM taxonomy_terms WHERE id = ? AND taxonomy = ?");
|
|
@@ -24109,20 +24313,20 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24109
24313
|
return console.error("[Taxonomy API] Error deleting term:", t), e.json({ error: "Failed to delete taxonomy term" }, 500);
|
|
24110
24314
|
}
|
|
24111
24315
|
});
|
|
24112
|
-
var
|
|
24316
|
+
var Px = null, Fx = null;
|
|
24113
24317
|
if (typeof process < "u" && process?.versions?.node) try {
|
|
24114
24318
|
let e = i(import.meta.url);
|
|
24115
|
-
|
|
24319
|
+
Px = e("node:fs"), Fx = e("node:path");
|
|
24116
24320
|
} catch {}
|
|
24117
|
-
function
|
|
24321
|
+
function Ix(e, t = "") {
|
|
24118
24322
|
let n = e.split(/[\\/]/).pop() || "";
|
|
24119
24323
|
return t && n.endsWith(t) ? n.slice(0, -t.length) : n;
|
|
24120
24324
|
}
|
|
24121
|
-
function
|
|
24325
|
+
function Lx(e) {
|
|
24122
24326
|
let t = e.match(/\.[^.\\/]+$/);
|
|
24123
24327
|
return t ? t[0] : "";
|
|
24124
24328
|
}
|
|
24125
|
-
var
|
|
24329
|
+
var Rx = {
|
|
24126
24330
|
nodes: {},
|
|
24127
24331
|
trees: {},
|
|
24128
24332
|
blocks: {},
|
|
@@ -24132,10 +24336,10 @@ var Lx = {
|
|
|
24132
24336
|
nodeLayouts: {},
|
|
24133
24337
|
blockLayouts: {}
|
|
24134
24338
|
};
|
|
24135
|
-
function
|
|
24339
|
+
function zx(e) {
|
|
24136
24340
|
return e ? typeof e == "string" ? e.trim() : Array.isArray(e) ? e.includes("*") ? "*" : e : "*" : "*";
|
|
24137
24341
|
}
|
|
24138
|
-
function
|
|
24342
|
+
function Bx(e = {}, t = {}) {
|
|
24139
24343
|
let n = {
|
|
24140
24344
|
...e,
|
|
24141
24345
|
...t,
|
|
@@ -24147,62 +24351,62 @@ function zx(e = {}, t = {}) {
|
|
|
24147
24351
|
};
|
|
24148
24352
|
return t.required === !0 || String(t.required).toLowerCase() === "true" || t.rules?.required === !0 || String(t.rules?.required).toLowerCase() === "true" || t.required === void 0 && (e.required === !0 || String(e.required).toLowerCase() === "true" || e.rules?.required === !0 || String(e.rules?.required).toLowerCase() === "true") ? (n.required = !0, n.rules.required = !0) : (t.required === !1 || t.rules?.required === !1) && (n.required = !1, n.rules.required = !1), n;
|
|
24149
24353
|
}
|
|
24150
|
-
function
|
|
24354
|
+
function Vx(e) {
|
|
24151
24355
|
if (!e || typeof e != "object") return e;
|
|
24152
|
-
if (Array.isArray(e)) return e.map(
|
|
24356
|
+
if (Array.isArray(e)) return e.map(Vx);
|
|
24153
24357
|
let t = {};
|
|
24154
24358
|
for (let [n, r] of Object.entries(e)) if (n === "<<" || n === "<<:") {
|
|
24155
|
-
let e =
|
|
24359
|
+
let e = Vx(r);
|
|
24156
24360
|
if (typeof e == "object" && e) {
|
|
24157
24361
|
if (Array.isArray(e)) for (let n of e) Object.assign(t, n);
|
|
24158
24362
|
else Object.assign(t, e);
|
|
24159
24363
|
}
|
|
24160
|
-
} else t[n] =
|
|
24364
|
+
} else t[n] = Vx(r);
|
|
24161
24365
|
return t;
|
|
24162
24366
|
}
|
|
24163
|
-
function
|
|
24164
|
-
return e ?
|
|
24367
|
+
function Hx(e, t) {
|
|
24368
|
+
return e ? Vx(n.parseDocument(e, { customTags: [{
|
|
24165
24369
|
tag: "!include",
|
|
24166
24370
|
resolve(e) {
|
|
24167
|
-
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r =
|
|
24371
|
+
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r = Ix(n);
|
|
24168
24372
|
if (!r) return n;
|
|
24169
24373
|
if (t && t.fieldSets) {
|
|
24170
24374
|
let e = Object.keys(t.fieldSets).find((e) => e.endsWith("/" + r) || e === r);
|
|
24171
|
-
if (e) return
|
|
24375
|
+
if (e) return Hx(t.fieldSets[e], t);
|
|
24172
24376
|
}
|
|
24173
24377
|
return n;
|
|
24174
24378
|
}
|
|
24175
24379
|
}] }).toJS() || {}) : {};
|
|
24176
24380
|
}
|
|
24177
|
-
function
|
|
24178
|
-
if (!
|
|
24179
|
-
let r =
|
|
24180
|
-
if (t.has(r) || (t.add(r), !
|
|
24181
|
-
let i =
|
|
24182
|
-
return
|
|
24381
|
+
function Ux(e, t = /* @__PURE__ */ new Set()) {
|
|
24382
|
+
if (!Px || !Fx) return {};
|
|
24383
|
+
let r = Fx.resolve(e);
|
|
24384
|
+
if (t.has(r) || (t.add(r), !Px.existsSync(r))) return {};
|
|
24385
|
+
let i = Px.readFileSync(r, "utf-8");
|
|
24386
|
+
return Vx(n.parseDocument(i, { customTags: [{
|
|
24183
24387
|
tag: "!include",
|
|
24184
24388
|
resolve(e) {
|
|
24185
24389
|
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim();
|
|
24186
|
-
return n ?
|
|
24390
|
+
return n ? Ux(Fx.resolve(Fx.dirname(r), n), new Set(t)) : {};
|
|
24187
24391
|
}
|
|
24188
24392
|
}] }).toJS() || {});
|
|
24189
24393
|
}
|
|
24190
|
-
function
|
|
24191
|
-
if (!
|
|
24394
|
+
function Wx() {
|
|
24395
|
+
if (!Px || !Fx || typeof process > "u" || !process?.versions?.node) return null;
|
|
24192
24396
|
try {
|
|
24193
24397
|
let e = process.cwd(), t = "", n = [
|
|
24194
|
-
|
|
24195
|
-
|
|
24196
|
-
|
|
24197
|
-
|
|
24398
|
+
Fx.resolve(e, "content/definitions"),
|
|
24399
|
+
Fx.resolve(e, "content"),
|
|
24400
|
+
Fx.resolve(e, "definitions"),
|
|
24401
|
+
Fx.resolve(e, "kama-worker/content/definitions")
|
|
24198
24402
|
];
|
|
24199
24403
|
try {
|
|
24200
24404
|
if (import.meta.url) {
|
|
24201
|
-
let e =
|
|
24202
|
-
n.push(
|
|
24405
|
+
let e = Fx.dirname(r(import.meta.url));
|
|
24406
|
+
n.push(Fx.resolve(e, "../../content/definitions")), n.push(Fx.resolve(e, "../content/definitions"));
|
|
24203
24407
|
}
|
|
24204
24408
|
} catch {}
|
|
24205
|
-
for (let e of n) if (
|
|
24409
|
+
for (let e of n) if (Px.existsSync(e)) {
|
|
24206
24410
|
t = e;
|
|
24207
24411
|
break;
|
|
24208
24412
|
}
|
|
@@ -24210,19 +24414,19 @@ function Ux() {
|
|
|
24210
24414
|
let i = (e) => {
|
|
24211
24415
|
let n = "";
|
|
24212
24416
|
for (let r of e) {
|
|
24213
|
-
let e =
|
|
24214
|
-
if (
|
|
24417
|
+
let e = Fx.join(t, r);
|
|
24418
|
+
if (Px.existsSync(e)) {
|
|
24215
24419
|
n = e;
|
|
24216
24420
|
break;
|
|
24217
24421
|
}
|
|
24218
24422
|
}
|
|
24219
24423
|
if (!n) return {};
|
|
24220
|
-
let r = {}, i =
|
|
24424
|
+
let r = {}, i = Px.readdirSync(n);
|
|
24221
24425
|
for (let e of i) {
|
|
24222
24426
|
if (!e.endsWith(".yaml") && !e.endsWith(".yml")) continue;
|
|
24223
|
-
let t =
|
|
24427
|
+
let t = Fx.join(n, e), i = Ix(e, Lx(e));
|
|
24224
24428
|
try {
|
|
24225
|
-
r[i] =
|
|
24429
|
+
r[i] = Ux(t);
|
|
24226
24430
|
} catch (t) {
|
|
24227
24431
|
console.error(`❌ Error parsing ${e}:`, t.message);
|
|
24228
24432
|
}
|
|
@@ -24251,59 +24455,59 @@ function Ux() {
|
|
|
24251
24455
|
return console.error("❌ Exception inside readLocalFsBundle:", e), null;
|
|
24252
24456
|
}
|
|
24253
24457
|
}
|
|
24254
|
-
var
|
|
24255
|
-
function Kx(e) {
|
|
24256
|
-
if (!e) Wx = null, Gx = null;
|
|
24257
|
-
else if (Wx && Gx === e) return Wx;
|
|
24258
|
-
let t = qx(e);
|
|
24259
|
-
return Wx = t, Gx = e, t;
|
|
24260
|
-
}
|
|
24458
|
+
var Gx = null, Kx = null;
|
|
24261
24459
|
function qx(e) {
|
|
24460
|
+
if (!e) Gx = null, Kx = null;
|
|
24461
|
+
else if (Gx && Kx === e) return Gx;
|
|
24462
|
+
let t = Jx(e);
|
|
24463
|
+
return Gx = t, Kx = e, t;
|
|
24464
|
+
}
|
|
24465
|
+
function Jx(e) {
|
|
24262
24466
|
if (e) {
|
|
24263
24467
|
let t = {
|
|
24264
24468
|
nodes: {
|
|
24265
24469
|
...e.nodes || e.rawNodes || {},
|
|
24266
|
-
...
|
|
24470
|
+
...Rx.nodes
|
|
24267
24471
|
},
|
|
24268
24472
|
trees: {
|
|
24269
24473
|
...e.trees || e.rawTrees || {},
|
|
24270
|
-
...
|
|
24474
|
+
...Rx.trees
|
|
24271
24475
|
},
|
|
24272
24476
|
channels: {
|
|
24273
24477
|
...e.channels || e.rawChannels || {},
|
|
24274
|
-
...
|
|
24478
|
+
...Rx.channels
|
|
24275
24479
|
},
|
|
24276
24480
|
taxonomies: {
|
|
24277
24481
|
...e.taxonomies || e.rawTaxonomies || {},
|
|
24278
|
-
...
|
|
24482
|
+
...Rx.taxonomies
|
|
24279
24483
|
},
|
|
24280
24484
|
blocks: {
|
|
24281
24485
|
...e.blocks || e.rawBlocks || {},
|
|
24282
|
-
...
|
|
24486
|
+
...Rx.blocks
|
|
24283
24487
|
},
|
|
24284
24488
|
nodeLayouts: {
|
|
24285
24489
|
...e.nodeLayouts || e.rawNodeLayouts || {},
|
|
24286
|
-
...
|
|
24490
|
+
...Rx.nodeLayouts
|
|
24287
24491
|
},
|
|
24288
24492
|
blockLayouts: {
|
|
24289
24493
|
...e.blockLayouts || e.rawBlockLayouts || {},
|
|
24290
|
-
...
|
|
24494
|
+
...Rx.blockLayouts
|
|
24291
24495
|
},
|
|
24292
24496
|
fieldSets: {
|
|
24293
24497
|
...e.fieldSets || e.rawFieldSets || {},
|
|
24294
|
-
...
|
|
24498
|
+
...Rx.fieldSets
|
|
24295
24499
|
}
|
|
24296
24500
|
};
|
|
24297
24501
|
if (typeof Object.values(t.nodes)[0] == "string") {
|
|
24298
24502
|
let e = (e) => {
|
|
24299
24503
|
let n = {};
|
|
24300
24504
|
for (let [r, i] of Object.entries(e || {})) {
|
|
24301
|
-
let e =
|
|
24302
|
-
n[e] =
|
|
24505
|
+
let e = Ix(r, Lx(r));
|
|
24506
|
+
n[e] = Hx(i, t);
|
|
24303
24507
|
}
|
|
24304
24508
|
return n;
|
|
24305
24509
|
};
|
|
24306
|
-
return
|
|
24510
|
+
return Yx({
|
|
24307
24511
|
rawNodes: e(t.nodes),
|
|
24308
24512
|
rawTrees: e(t.trees),
|
|
24309
24513
|
rawChannels: e(t.channels),
|
|
@@ -24314,12 +24518,12 @@ function qx(e) {
|
|
|
24314
24518
|
rawFieldSets: e(t.fieldSets)
|
|
24315
24519
|
});
|
|
24316
24520
|
}
|
|
24317
|
-
return
|
|
24521
|
+
return Yx(t);
|
|
24318
24522
|
}
|
|
24319
|
-
let t =
|
|
24320
|
-
return t && Object.keys(t.rawNodes || {}).length > 0 ?
|
|
24523
|
+
let t = Wx();
|
|
24524
|
+
return t && Object.keys(t.rawNodes || {}).length > 0 ? Yx(t) : Yx(null);
|
|
24321
24525
|
}
|
|
24322
|
-
function
|
|
24526
|
+
function Yx(e) {
|
|
24323
24527
|
if (!e) return {
|
|
24324
24528
|
nodes: {},
|
|
24325
24529
|
trees: {},
|
|
@@ -24334,16 +24538,16 @@ function Jx(e) {
|
|
|
24334
24538
|
channelTemplate: null,
|
|
24335
24539
|
userTemplate: null
|
|
24336
24540
|
};
|
|
24337
|
-
let { rawNodes: t = {}, rawTrees: n = {}, rawChannels: r = {}, channels: i = {}, rawTaxonomies: a = {}, taxonomies: o = {}, rawBlocks: s = {}, rawElements: c = {}, rawNodeLayouts: l = {}, rawBlockLayouts: u = {}, rawLayouts: d = {}, rawFieldSets: f = {}, rawTemplates: p = {}, nodeTemplate: m = null, treeTemplate: h = null, channelTemplate: g = null, userTemplate: _ = null, nodes: v = {}, trees: y = {}, blocks: b = {}, nodeLayouts: x = {}, blockLayouts: S = {} } = e, C = Object.keys(t).length > 0 ? t : v, ee = Object.keys(n).length > 0 ? n : y, w = Object.keys(r).length > 0 ? r : i, T = Object.keys(a).length > 0 ? a : o, E = Object.keys(s).length > 0 ? s : Object.keys(c).length > 0 ? c : b, D = Object.keys(l).length > 0 ? l : Object.keys(d).length > 0 ? d : x, te = Object.keys(u).length > 0 ? u : S,
|
|
24541
|
+
let { rawNodes: t = {}, rawTrees: n = {}, rawChannels: r = {}, channels: i = {}, rawTaxonomies: a = {}, taxonomies: o = {}, rawBlocks: s = {}, rawElements: c = {}, rawNodeLayouts: l = {}, rawBlockLayouts: u = {}, rawLayouts: d = {}, rawFieldSets: f = {}, rawTemplates: p = {}, nodeTemplate: m = null, treeTemplate: h = null, channelTemplate: g = null, userTemplate: _ = null, nodes: v = {}, trees: y = {}, blocks: b = {}, nodeLayouts: x = {}, blockLayouts: S = {} } = e, C = Object.keys(t).length > 0 ? t : v, ee = Object.keys(n).length > 0 ? n : y, w = Object.keys(r).length > 0 ? r : i, T = Object.keys(a).length > 0 ? a : o, E = Object.keys(s).length > 0 ? s : Object.keys(c).length > 0 ? c : b, D = Object.keys(l).length > 0 ? l : Object.keys(d).length > 0 ? d : x, te = Object.keys(u).length > 0 ? u : S, ne = m?.fields || {}, O = {
|
|
24338
24542
|
...p,
|
|
24339
24543
|
...f
|
|
24340
|
-
},
|
|
24544
|
+
}, k = (e, t = "settings", n, r) => {
|
|
24341
24545
|
let i = {};
|
|
24342
24546
|
if (!e) return i;
|
|
24343
24547
|
let a = (e) => {
|
|
24344
|
-
let a =
|
|
24548
|
+
let a = O[e] || O[`${e}-base`] || {};
|
|
24345
24549
|
r && typeof a == "object" && a && (r.inTree === void 0 && a.inTree !== void 0 && (r.inTree = a.inTree), r.inVault === void 0 && a.inVault !== void 0 && (r.inVault = a.inVault), r.hasCanvas === void 0 && a.hasCanvas !== void 0 && (r.hasCanvas = a.hasCanvas));
|
|
24346
|
-
let o = a.fields || a, s =
|
|
24550
|
+
let o = a.fields || a, s = k(o, t, n, r);
|
|
24347
24551
|
if (a.tab && n) {
|
|
24348
24552
|
let t = a.tab.id || e, r = a.tab.label || a.label || t;
|
|
24349
24553
|
n[t] || (n[t] = {
|
|
@@ -24351,11 +24555,11 @@ function Jx(e) {
|
|
|
24351
24555
|
fields: {}
|
|
24352
24556
|
}), Object.entries(s).forEach(([e, r]) => {
|
|
24353
24557
|
let i = n[t].fields[e] || {};
|
|
24354
|
-
n[t].fields[e] =
|
|
24558
|
+
n[t].fields[e] = Bx(i, r);
|
|
24355
24559
|
});
|
|
24356
24560
|
} else Object.entries(s).forEach(([e, t]) => {
|
|
24357
24561
|
let n = i[e] || {};
|
|
24358
|
-
i[e] =
|
|
24562
|
+
i[e] = Bx(n, t);
|
|
24359
24563
|
});
|
|
24360
24564
|
};
|
|
24361
24565
|
return !Array.isArray(e) && typeof e == "object" && e ? (Object.entries(e).forEach(([e, t]) => {
|
|
@@ -24364,15 +24568,15 @@ function Jx(e) {
|
|
|
24364
24568
|
a(String(t));
|
|
24365
24569
|
return;
|
|
24366
24570
|
}
|
|
24367
|
-
let n = i[e] ||
|
|
24368
|
-
i[e] =
|
|
24571
|
+
let n = i[e] || ne[e] || {};
|
|
24572
|
+
i[e] = Bx(n, typeof t == "object" && t ? t : { label: String(t) });
|
|
24369
24573
|
}), i) : (Array.isArray(e) && e.forEach((e) => {
|
|
24370
24574
|
if (typeof e == "string") {
|
|
24371
24575
|
if (e.includes("/") || e.endsWith(".yaml") || e.endsWith(".yml")) return;
|
|
24372
24576
|
if (e.startsWith("fieldSet:")) a(e.replace("fieldSet:", "").trim());
|
|
24373
24577
|
else {
|
|
24374
|
-
let t = i[e] ||
|
|
24375
|
-
i[e] =
|
|
24578
|
+
let t = i[e] || ne[e] || {};
|
|
24579
|
+
i[e] = Bx(t, {
|
|
24376
24580
|
type: "text",
|
|
24377
24581
|
label: e
|
|
24378
24582
|
});
|
|
@@ -24380,26 +24584,26 @@ function Jx(e) {
|
|
|
24380
24584
|
} else typeof e == "object" && e && Object.entries(e).forEach(([e, t]) => {
|
|
24381
24585
|
if (e === "fieldSet") a(String(t));
|
|
24382
24586
|
else if (e !== "<<" && e !== "<<:") {
|
|
24383
|
-
let n = i[e] ||
|
|
24384
|
-
i[e] =
|
|
24587
|
+
let n = i[e] || ne[e] || {};
|
|
24588
|
+
i[e] = Bx(n, typeof t == "object" && t ? t : {});
|
|
24385
24589
|
}
|
|
24386
24590
|
});
|
|
24387
24591
|
}), i);
|
|
24388
|
-
},
|
|
24592
|
+
}, A = (e, t) => {
|
|
24389
24593
|
let n = {};
|
|
24390
24594
|
return !e || typeof e != "object" ? n : Array.isArray(e) ? (e.forEach((e) => {
|
|
24391
24595
|
if (typeof e == "object" && e.fieldSet) {
|
|
24392
|
-
let r = String(e.fieldSet), i =
|
|
24596
|
+
let r = String(e.fieldSet), i = O[r] || O[`${r}-base`] || {};
|
|
24393
24597
|
t && (t.inTree === void 0 && i.inTree !== void 0 && (t.inTree = i.inTree), t.inVault === void 0 && i.inVault !== void 0 && (t.inVault = i.inVault), t.hasCanvas === void 0 && i.hasCanvas !== void 0 && (t.hasCanvas = i.hasCanvas));
|
|
24394
24598
|
let a = i.tab?.id || r, o = i.tab?.label || i.label || a;
|
|
24395
24599
|
n[a] || (n[a] = {
|
|
24396
24600
|
label: o,
|
|
24397
24601
|
fields: {}
|
|
24398
24602
|
});
|
|
24399
|
-
let s =
|
|
24603
|
+
let s = k(i.fields || i, a, n, t);
|
|
24400
24604
|
Object.entries(s).forEach(([e, t]) => {
|
|
24401
24605
|
let r = n[a].fields[e] || {};
|
|
24402
|
-
n[a].fields[e] =
|
|
24606
|
+
n[a].fields[e] = Bx(r, t);
|
|
24403
24607
|
});
|
|
24404
24608
|
}
|
|
24405
24609
|
}), n) : (Object.entries(e).forEach(([e, r]) => {
|
|
@@ -24411,21 +24615,21 @@ function Jx(e) {
|
|
|
24411
24615
|
label: i,
|
|
24412
24616
|
fields: {}
|
|
24413
24617
|
});
|
|
24414
|
-
let s =
|
|
24618
|
+
let s = k(o, e, n, t);
|
|
24415
24619
|
Object.entries(s).forEach(([t, r]) => {
|
|
24416
24620
|
if (t === "<<" || t === "<<:" || t === "label") return;
|
|
24417
24621
|
let i = n[e].fields[t] || {};
|
|
24418
|
-
n[e].fields[t] =
|
|
24622
|
+
n[e].fields[t] = Bx(i, r);
|
|
24419
24623
|
});
|
|
24420
24624
|
}), n);
|
|
24421
|
-
},
|
|
24625
|
+
}, re = {};
|
|
24422
24626
|
Object.entries(C).forEach(([e, t]) => {
|
|
24423
24627
|
m && (t.inTree === void 0 && m.inTree !== void 0 && (t.inTree = m.inTree), t.inVault === void 0 && m.inVault !== void 0 && (t.inVault = m.inVault), t.hasCanvas === void 0 && m.hasCanvas !== void 0 && (t.hasCanvas = m.hasCanvas));
|
|
24424
|
-
let n =
|
|
24628
|
+
let n = A(t.tabs, t), r = k(t.fields || [], "settings", n, t);
|
|
24425
24629
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24426
|
-
let i =
|
|
24630
|
+
let i = O[e] || O[`${e}-base`] || {};
|
|
24427
24631
|
t.inTree === void 0 && i.inTree !== void 0 && (t.inTree = i.inTree), t.inVault === void 0 && i.inVault !== void 0 && (t.inVault = i.inVault), t.hasCanvas === void 0 && i.hasCanvas !== void 0 && (t.hasCanvas = i.hasCanvas);
|
|
24428
|
-
let a = i.fields || i, o =
|
|
24632
|
+
let a = i.fields || i, o = k(a, "settings", n, t);
|
|
24429
24633
|
if (i.tab) {
|
|
24430
24634
|
let t = i.tab.id || e, r = i.tab.label || i.label || t;
|
|
24431
24635
|
n[t] || (n[t] = {
|
|
@@ -24433,21 +24637,21 @@ function Jx(e) {
|
|
|
24433
24637
|
fields: {}
|
|
24434
24638
|
}), Object.entries(o).forEach(([e, r]) => {
|
|
24435
24639
|
let i = n[t].fields[e] || {};
|
|
24436
|
-
n[t].fields[e] =
|
|
24640
|
+
n[t].fields[e] = Bx(i, r);
|
|
24437
24641
|
});
|
|
24438
24642
|
} else Object.entries(o).forEach(([e, t]) => {
|
|
24439
|
-
let n = r[e] ||
|
|
24440
|
-
r[e] =
|
|
24643
|
+
let n = r[e] || ne[e] || {};
|
|
24644
|
+
r[e] = Bx(n, t);
|
|
24441
24645
|
});
|
|
24442
24646
|
}), Object.values(n).forEach((e) => {
|
|
24443
24647
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24444
24648
|
let n = r[e] || {};
|
|
24445
|
-
r[e] =
|
|
24649
|
+
r[e] = Bx(n, t);
|
|
24446
24650
|
});
|
|
24447
24651
|
}), Object.keys(n).length === 0 && Object.keys(r).length > 0 && (n.settings = {
|
|
24448
24652
|
label: t.label || "Settings",
|
|
24449
24653
|
fields: r
|
|
24450
|
-
}),
|
|
24654
|
+
}), re[e] = {
|
|
24451
24655
|
...t,
|
|
24452
24656
|
id: t.id || e,
|
|
24453
24657
|
label: t.label || e,
|
|
@@ -24455,25 +24659,25 @@ function Jx(e) {
|
|
|
24455
24659
|
inVault: t.inVault !== !1,
|
|
24456
24660
|
hasCanvas: t.hasCanvas === !0,
|
|
24457
24661
|
defaultLayout: t.defaultLayout,
|
|
24458
|
-
allowedBlocks:
|
|
24459
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24662
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24663
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0,
|
|
24460
24664
|
tabs: n,
|
|
24461
24665
|
fields: r
|
|
24462
24666
|
};
|
|
24463
24667
|
});
|
|
24464
|
-
let
|
|
24668
|
+
let ie = {};
|
|
24465
24669
|
Object.entries(ee).forEach(([e, t]) => {
|
|
24466
|
-
let n =
|
|
24670
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24467
24671
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24468
|
-
let t =
|
|
24672
|
+
let t = O[e] || {}, i = t.fields || t, a = k(i, "settings", n);
|
|
24469
24673
|
Object.entries(a).forEach(([e, t]) => {
|
|
24470
|
-
r[e] =
|
|
24674
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24471
24675
|
});
|
|
24472
24676
|
}), Object.values(n).forEach((e) => {
|
|
24473
24677
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24474
|
-
r[e] =
|
|
24678
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24475
24679
|
});
|
|
24476
|
-
}),
|
|
24680
|
+
}), ie[e] = {
|
|
24477
24681
|
...t,
|
|
24478
24682
|
id: t.id || e,
|
|
24479
24683
|
label: t.label || e,
|
|
@@ -24481,19 +24685,19 @@ function Jx(e) {
|
|
|
24481
24685
|
fields: r
|
|
24482
24686
|
};
|
|
24483
24687
|
});
|
|
24484
|
-
let
|
|
24688
|
+
let ae = {};
|
|
24485
24689
|
Object.entries(w).forEach(([e, t]) => {
|
|
24486
|
-
let n =
|
|
24690
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24487
24691
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24488
|
-
let t =
|
|
24692
|
+
let t = O[e] || {}, n = t.fields || t, i = k(n);
|
|
24489
24693
|
Object.entries(i).forEach(([e, t]) => {
|
|
24490
|
-
r[e] =
|
|
24694
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24491
24695
|
});
|
|
24492
24696
|
}), Object.values(n).forEach((e) => {
|
|
24493
24697
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24494
|
-
r[e] =
|
|
24698
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24495
24699
|
});
|
|
24496
|
-
}),
|
|
24700
|
+
}), ae[e] = {
|
|
24497
24701
|
...t,
|
|
24498
24702
|
id: t.id || e,
|
|
24499
24703
|
label: t.label || e,
|
|
@@ -24502,19 +24706,19 @@ function Jx(e) {
|
|
|
24502
24706
|
fields: r
|
|
24503
24707
|
};
|
|
24504
24708
|
});
|
|
24505
|
-
let
|
|
24709
|
+
let oe = {};
|
|
24506
24710
|
Object.entries(T).forEach(([e, t]) => {
|
|
24507
|
-
let n =
|
|
24711
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24508
24712
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24509
|
-
let t =
|
|
24713
|
+
let t = O[e] || {}, i = t.fields || t, a = k(i, "settings", n);
|
|
24510
24714
|
Object.entries(a).forEach(([e, t]) => {
|
|
24511
|
-
r[e] =
|
|
24715
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24512
24716
|
});
|
|
24513
24717
|
}), Object.values(n).forEach((e) => {
|
|
24514
24718
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24515
|
-
r[e] =
|
|
24719
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24516
24720
|
});
|
|
24517
|
-
}),
|
|
24721
|
+
}), oe[e] = {
|
|
24518
24722
|
...t,
|
|
24519
24723
|
id: t.id || e,
|
|
24520
24724
|
label: t.label || e,
|
|
@@ -24523,15 +24727,15 @@ function Jx(e) {
|
|
|
24523
24727
|
fields: r
|
|
24524
24728
|
};
|
|
24525
24729
|
});
|
|
24526
|
-
let
|
|
24730
|
+
let se = {};
|
|
24527
24731
|
Object.entries(E).forEach(([e, t]) => {
|
|
24528
|
-
let n =
|
|
24732
|
+
let n = k(t.fields || []);
|
|
24529
24733
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24530
|
-
let t =
|
|
24734
|
+
let t = O[e] || {}, r = t.fields || t, i = k(r);
|
|
24531
24735
|
Object.entries(i).forEach(([e, t]) => {
|
|
24532
|
-
n[e] =
|
|
24736
|
+
n[e] = Bx(n[e] || {}, t);
|
|
24533
24737
|
});
|
|
24534
|
-
}),
|
|
24738
|
+
}), se[e] = {
|
|
24535
24739
|
...t,
|
|
24536
24740
|
id: t.id || e,
|
|
24537
24741
|
label: t.label || e,
|
|
@@ -24539,17 +24743,17 @@ function Jx(e) {
|
|
|
24539
24743
|
fields: n
|
|
24540
24744
|
};
|
|
24541
24745
|
});
|
|
24542
|
-
let
|
|
24746
|
+
let ce = {};
|
|
24543
24747
|
Object.entries(D).forEach(([e, t]) => {
|
|
24544
|
-
let n =
|
|
24748
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { content: { label: "Content" } };
|
|
24545
24749
|
Object.entries(a).forEach(([e, t]) => {
|
|
24546
24750
|
i[e] = {
|
|
24547
24751
|
...t,
|
|
24548
24752
|
label: t.label || e,
|
|
24549
|
-
allowedBlocks:
|
|
24550
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24753
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24754
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0
|
|
24551
24755
|
};
|
|
24552
|
-
}),
|
|
24756
|
+
}), ce[e] = {
|
|
24553
24757
|
...t,
|
|
24554
24758
|
id: t.id || e,
|
|
24555
24759
|
label: t.label || e,
|
|
@@ -24562,17 +24766,17 @@ function Jx(e) {
|
|
|
24562
24766
|
tabs: n
|
|
24563
24767
|
};
|
|
24564
24768
|
});
|
|
24565
|
-
let
|
|
24769
|
+
let le = {};
|
|
24566
24770
|
Object.entries(te).forEach(([e, t]) => {
|
|
24567
|
-
let n =
|
|
24771
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { main: { label: "Main Content" } };
|
|
24568
24772
|
Object.entries(a).forEach(([e, t]) => {
|
|
24569
24773
|
i[e] = {
|
|
24570
24774
|
...t,
|
|
24571
24775
|
label: t.label || e,
|
|
24572
|
-
allowedBlocks:
|
|
24573
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24776
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24777
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0
|
|
24574
24778
|
};
|
|
24575
|
-
}),
|
|
24779
|
+
}), le[e] = {
|
|
24576
24780
|
...t,
|
|
24577
24781
|
id: t.id || e,
|
|
24578
24782
|
label: t.label || e,
|
|
@@ -24585,21 +24789,21 @@ function Jx(e) {
|
|
|
24585
24789
|
tabs: n
|
|
24586
24790
|
};
|
|
24587
24791
|
});
|
|
24588
|
-
let
|
|
24792
|
+
let j = g?.fields || {};
|
|
24589
24793
|
Array.isArray(g?.fieldSets) && g?.fieldSets.forEach((e) => {
|
|
24590
|
-
let t =
|
|
24794
|
+
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
24591
24795
|
Object.entries(r).forEach(([e, t]) => {
|
|
24592
|
-
|
|
24796
|
+
j[e] = Bx(j[e] || {}, t);
|
|
24593
24797
|
});
|
|
24594
24798
|
});
|
|
24595
24799
|
let ue = g ? {
|
|
24596
24800
|
...g,
|
|
24597
|
-
fields:
|
|
24801
|
+
fields: j
|
|
24598
24802
|
} : null, de = _?.fields || {};
|
|
24599
24803
|
Array.isArray(_?.fieldSets) && _?.fieldSets.forEach((e) => {
|
|
24600
|
-
let t =
|
|
24804
|
+
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
24601
24805
|
Object.entries(r).forEach(([e, t]) => {
|
|
24602
|
-
de[e] =
|
|
24806
|
+
de[e] = Bx(de[e] || {}, t);
|
|
24603
24807
|
});
|
|
24604
24808
|
});
|
|
24605
24809
|
let fe = _ ? {
|
|
@@ -24607,25 +24811,25 @@ function Jx(e) {
|
|
|
24607
24811
|
fields: de
|
|
24608
24812
|
} : null;
|
|
24609
24813
|
return {
|
|
24610
|
-
nodes:
|
|
24611
|
-
trees:
|
|
24612
|
-
channels:
|
|
24613
|
-
taxonomies:
|
|
24614
|
-
blocks:
|
|
24615
|
-
nodeLayouts:
|
|
24616
|
-
blockLayouts:
|
|
24617
|
-
fieldSets:
|
|
24814
|
+
nodes: re,
|
|
24815
|
+
trees: ie,
|
|
24816
|
+
channels: ae,
|
|
24817
|
+
taxonomies: oe,
|
|
24818
|
+
blocks: se,
|
|
24819
|
+
nodeLayouts: ce,
|
|
24820
|
+
blockLayouts: le,
|
|
24821
|
+
fieldSets: O,
|
|
24618
24822
|
nodeTemplate: m || null,
|
|
24619
24823
|
treeTemplate: h || null,
|
|
24620
24824
|
channelTemplate: ue,
|
|
24621
24825
|
userTemplate: fe
|
|
24622
24826
|
};
|
|
24623
24827
|
}
|
|
24624
|
-
var
|
|
24828
|
+
var Xx = new e(), Zx = (e) => {
|
|
24625
24829
|
try {
|
|
24626
24830
|
let t = e.env?.BUNDLED_DEFINITIONS;
|
|
24627
24831
|
(!t || Object.keys(t).length === 0) && (t = Db || Eb || Tb);
|
|
24628
|
-
let n =
|
|
24832
|
+
let n = qx(t);
|
|
24629
24833
|
return e.json(n, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
24630
24834
|
} catch (t) {
|
|
24631
24835
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
@@ -24634,8 +24838,8 @@ var Yx = new e(), Xx = (e) => {
|
|
|
24634
24838
|
}, 500);
|
|
24635
24839
|
}
|
|
24636
24840
|
};
|
|
24637
|
-
|
|
24638
|
-
var
|
|
24841
|
+
Xx.get("/", Zx), Xx.get("/schemas.json", Zx);
|
|
24842
|
+
var Qx = new e(), $x = {
|
|
24639
24843
|
node: "content_nodes",
|
|
24640
24844
|
nodes: "content_nodes",
|
|
24641
24845
|
content_node: "content_nodes",
|
|
@@ -24647,7 +24851,7 @@ var Zx = new e(), Qx = {
|
|
|
24647
24851
|
user: "users",
|
|
24648
24852
|
users: "users",
|
|
24649
24853
|
user_account: "user_accounts"
|
|
24650
|
-
},
|
|
24854
|
+
}, eS = {
|
|
24651
24855
|
content_nodes: [
|
|
24652
24856
|
"id",
|
|
24653
24857
|
"title",
|
|
@@ -24704,11 +24908,11 @@ var Zx = new e(), Qx = {
|
|
|
24704
24908
|
"createdAt"
|
|
24705
24909
|
]
|
|
24706
24910
|
};
|
|
24707
|
-
|
|
24911
|
+
Qx.post("/validate-unique", async (e) => {
|
|
24708
24912
|
try {
|
|
24709
24913
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
24710
24914
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
24711
|
-
let o =
|
|
24915
|
+
let o = $x[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (eS[o] || eS.content_nodes).includes(s), l = -1;
|
|
24712
24916
|
if (a != null && String(a).trim() !== "") {
|
|
24713
24917
|
let e = Number(a);
|
|
24714
24918
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -24720,9 +24924,9 @@ Zx.post("/validate-unique", async (e) => {
|
|
|
24720
24924
|
} catch (t) {
|
|
24721
24925
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
24722
24926
|
}
|
|
24723
|
-
}),
|
|
24724
|
-
var
|
|
24725
|
-
|
|
24927
|
+
}), Qx.post("/validate-unique-sibling", async (e) => e.json({ isUnique: !0 }));
|
|
24928
|
+
var tS = new e();
|
|
24929
|
+
tS.get("/", async (e) => {
|
|
24726
24930
|
try {
|
|
24727
24931
|
let t = e.get("db"), n = await t.prepare("\n SELECT \n COUNT(*) as total,\n SUM(CASE WHEN isHidden = 0 THEN 1 ELSE 0 END) as published,\n SUM(CASE WHEN isHidden = 1 THEN 1 ELSE 0 END) as hidden\n FROM content_nodes\n WHERE deletedAt IS NULL OR deletedAt = ''\n ").get(), r = Number(n?.total) || 0, i = Number(n?.published) || 0, a = Number(n?.hidden) || 0, o = await t.prepare("\n SELECT \n (SELECT COUNT(*) FROM channels) as totalChannels,\n (SELECT COUNT(*) FROM trees) as totalTrees,\n (SELECT COUNT(*) FROM users) as totalUsers\n ").get(), s = await t.prepare("\n SELECT contentType as type, COUNT(*) as count \n FROM content_nodes \n WHERE deletedAt IS NULL OR deletedAt = ''\n GROUP BY contentType \n ORDER BY count DESC\n ").all(), c = Array.isArray(s) ? s : s?.results || [], l = await t.prepare("\n SELECT id, title, slug, contentType, isHidden, status, updatedAt \n FROM content_nodes \n WHERE deletedAt IS NULL OR deletedAt = ''\n ORDER BY updatedAt DESC \n LIMIT 5\n ").all(), u = (Array.isArray(l) ? l : l?.results || []).map((e) => ({
|
|
24728
24932
|
...e,
|
|
@@ -24765,8 +24969,8 @@ eS.get("/", async (e) => {
|
|
|
24765
24969
|
}, 500);
|
|
24766
24970
|
}
|
|
24767
24971
|
});
|
|
24768
|
-
var
|
|
24769
|
-
async function
|
|
24972
|
+
var nS = new e();
|
|
24973
|
+
async function rS(e, t, n = []) {
|
|
24770
24974
|
let r = e.prepare(t);
|
|
24771
24975
|
if (typeof r.bind == "function") {
|
|
24772
24976
|
let e = await r.bind(...n).all();
|
|
@@ -24778,16 +24982,16 @@ async function nS(e, t, n = []) {
|
|
|
24778
24982
|
}
|
|
24779
24983
|
return [];
|
|
24780
24984
|
}
|
|
24781
|
-
async function
|
|
24985
|
+
async function iS(e, t, n = []) {
|
|
24782
24986
|
let r = e.prepare(t);
|
|
24783
24987
|
if (typeof r.bind == "function") return await r.bind(...n).run();
|
|
24784
24988
|
if (typeof r.run == "function") return await r.run(...n);
|
|
24785
24989
|
}
|
|
24786
|
-
function
|
|
24990
|
+
function aS(e, t, n) {
|
|
24787
24991
|
let r = e || (t ? `/media/${t}` : "");
|
|
24788
24992
|
return r && n && r.startsWith(`https://${n}/`) && !r.includes("/media/") && (r = r.replace(`https://${n}/`, `https://${n}/media/`)), r;
|
|
24789
24993
|
}
|
|
24790
|
-
|
|
24994
|
+
nS.get("/", async (e) => {
|
|
24791
24995
|
try {
|
|
24792
24996
|
let t = wb(e), { search: n = "", type: r = "all", page: i = "1", limit: a = "24", sort: o = "createdAt", order: s = "DESC", nodeId: c, channelId: l, trashed: u } = e.req.query(), d = Math.max(1, parseInt(i, 10) || 1), f = Math.max(1, Math.min(100, parseInt(a, 10) || 24)), p = (d - 1) * f, m = {
|
|
24793
24997
|
createdAt: "a.createdAt",
|
|
@@ -24797,7 +25001,7 @@ tS.get("/", async (e) => {
|
|
|
24797
25001
|
sizeBytes: "a.sizeBytes"
|
|
24798
25002
|
}[o] || "a.createdAt", h = s.toUpperCase() === "ASC" ? "ASC" : "DESC", g = [], _ = ["(a.isSystemVariant = 0 OR a.isSystemVariant IS NULL)", u === "true" || u === "1" ? "(a.deletedAt IS NOT NULL AND a.deletedAt != '')" : "(a.deletedAt IS NULL OR a.deletedAt = '')"];
|
|
24799
25003
|
if (c) {
|
|
24800
|
-
let e = await
|
|
25004
|
+
let e = await rS(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)]);
|
|
24801
25005
|
if (e.length === 0) _.push("1 = 0");
|
|
24802
25006
|
else {
|
|
24803
25007
|
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 ");
|
|
@@ -24811,10 +25015,10 @@ tS.get("/", async (e) => {
|
|
|
24811
25015
|
n && n.trim() !== "" && (_.push("a.filename LIKE ?"), g.push(`%${n.trim()}%`)), r && r !== "all" && (r === "image" ? (_.push("a.mimeType LIKE ?"), g.push("image/%")) : r === "document" ? (_.push("(a.mimeType LIKE ? OR a.mimeType LIKE ? OR a.mimeType LIKE ?)"), g.push("application/pdf%", "application/msword%", "application/vnd%")) : r === "video" && (_.push("(a.mimeType LIKE ? OR a.mimeType LIKE ?)"), g.push("video/%", "audio/%")));
|
|
24812
25016
|
let v = `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 ${_.join(" AND ")}`} ORDER BY ${m} ${h} LIMIT ? OFFSET ?`;
|
|
24813
25017
|
g.push(f, p);
|
|
24814
|
-
let y = await
|
|
25018
|
+
let y = await rS(t, v, g), b = y.map((e) => e.id), x = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map();
|
|
24815
25019
|
if (b.length > 0) {
|
|
24816
25020
|
let e = b.map(() => "?").join(",");
|
|
24817
|
-
(await
|
|
25021
|
+
(await rS(t, `
|
|
24818
25022
|
SELECT master.id AS assetId, COUNT(DISTINCT na.nodeId) AS count
|
|
24819
25023
|
FROM assets master
|
|
24820
25024
|
INNER JOIN node_assets na ON (
|
|
@@ -24822,7 +25026,7 @@ tS.get("/", async (e) => {
|
|
|
24822
25026
|
EXISTS (SELECT 1 FROM assets crop WHERE crop.id = na.assetId AND crop.isSystemVariant = 1 AND crop.parentAssetId = master.id)
|
|
24823
25027
|
)
|
|
24824
25028
|
WHERE master.id IN (${e})
|
|
24825
|
-
GROUP BY master.id`, b)).forEach((e) => x.set(String(e.assetId), e.count || 0)), (await
|
|
25029
|
+
GROUP BY master.id`, b)).forEach((e) => x.set(String(e.assetId), e.count || 0)), (await rS(t, `
|
|
24826
25030
|
SELECT parentAssetId, COUNT(id) AS count
|
|
24827
25031
|
FROM assets
|
|
24828
25032
|
WHERE isSystemVariant = 1 AND parentAssetId IN (${e})
|
|
@@ -24840,7 +25044,7 @@ tS.get("/", async (e) => {
|
|
|
24840
25044
|
...JSON.parse(t.dataJson || "{}")
|
|
24841
25045
|
};
|
|
24842
25046
|
} catch {}
|
|
24843
|
-
let r =
|
|
25047
|
+
let r = aS(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
24844
25048
|
return {
|
|
24845
25049
|
id: t.id,
|
|
24846
25050
|
filename: t.filename || "Untitled Asset",
|
|
@@ -24865,7 +25069,7 @@ tS.get("/", async (e) => {
|
|
|
24865
25069
|
details: t.message || String(t)
|
|
24866
25070
|
}, 500);
|
|
24867
25071
|
}
|
|
24868
|
-
}),
|
|
25072
|
+
}), nS.post("/upload", async (e) => {
|
|
24869
25073
|
try {
|
|
24870
25074
|
let t = wb(e), { storage: n } = ix(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, l = typeof c == "string" && c.trim().length > 0 ? c.trim() : null;
|
|
24871
25075
|
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
@@ -24881,13 +25085,13 @@ tS.get("/", async (e) => {
|
|
|
24881
25085
|
let p = crypto.randomUUID().replace(/-/g, "").slice(0, 12), m = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7).replace("-", "/"), h = a || i.name.startsWith("crop_"), g = h ? `kama/cache/${m}/${p}` : `kama/uploads/${m}/${p}`, _ = await n.upload(i, g), v = typeof _ == "string" ? _ : _?.key || _?.storageKeyPrivate || _?.storageKey || `${g}/${p}_${i.name}`;
|
|
24882
25086
|
if (!v) throw Error("Storage provider failed to return a valid storage key");
|
|
24883
25087
|
let y = e.env.CDN_DOMAIN, b = v.replace(/^\//, ""), x = y ? `https://${y}/media/${b}` : `/media/${b}`, S = i.type || "application/octet-stream", C = i.size || 0, ee = e.get("userId"), w = typeof ee == "string" && ee.trim().length > 0 ? ee : null;
|
|
24884
|
-
w && (await
|
|
25088
|
+
w && (await rS(t, "SELECT id FROM users WHERE id = ?", [w])).length === 0 && (w = null);
|
|
24885
25089
|
let T = new fx(e.env);
|
|
24886
25090
|
if (s) {
|
|
24887
|
-
let r = await
|
|
25091
|
+
let r = await rS(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
24888
25092
|
if (r.length > 0) {
|
|
24889
25093
|
let a = r[0];
|
|
24890
|
-
if (await
|
|
25094
|
+
if (await iS(t, "UPDATE assets SET filename = ?, mimeType = ?, sizeBytes = ?, storageKeyPrivate = ?, cdnUrl = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
24891
25095
|
i.name,
|
|
24892
25096
|
S,
|
|
24893
25097
|
C,
|
|
@@ -24916,7 +25120,7 @@ tS.get("/", async (e) => {
|
|
|
24916
25120
|
}
|
|
24917
25121
|
}
|
|
24918
25122
|
let E = `ast_${p}`, D = +!!h;
|
|
24919
|
-
await
|
|
25123
|
+
await iS(t, "INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
24920
25124
|
E,
|
|
24921
25125
|
i.name,
|
|
24922
25126
|
S,
|
|
@@ -24930,8 +25134,8 @@ tS.get("/", async (e) => {
|
|
|
24930
25134
|
]);
|
|
24931
25135
|
let te = x;
|
|
24932
25136
|
if (l) {
|
|
24933
|
-
let n = await
|
|
24934
|
-
n.length > 0 && (te =
|
|
25137
|
+
let n = await rS(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [l]);
|
|
25138
|
+
n.length > 0 && (te = aS(n[0].cdnUrl, n[0].storageKeyPrivate, y)), T.purgeAsset(e, t, l);
|
|
24935
25139
|
}
|
|
24936
25140
|
return e.json({
|
|
24937
25141
|
id: E,
|
|
@@ -24950,11 +25154,11 @@ tS.get("/", async (e) => {
|
|
|
24950
25154
|
details: t.message || String(t)
|
|
24951
25155
|
}, 500);
|
|
24952
25156
|
}
|
|
24953
|
-
}),
|
|
25157
|
+
}), nS.get("/:id/details", async (e) => {
|
|
24954
25158
|
try {
|
|
24955
|
-
let t = wb(e), n = e.req.param("id"), r = await
|
|
25159
|
+
let t = wb(e), n = e.req.param("id"), r = await rS(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
24956
25160
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
24957
|
-
let i = r[0], a = await
|
|
25161
|
+
let i = r[0], a = await rS(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 rS(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 = {
|
|
24958
25162
|
title: "",
|
|
24959
25163
|
alt: "",
|
|
24960
25164
|
description: ""
|
|
@@ -24965,7 +25169,7 @@ tS.get("/", async (e) => {
|
|
|
24965
25169
|
...JSON.parse(i.dataJson || "{}")
|
|
24966
25170
|
};
|
|
24967
25171
|
} catch {}
|
|
24968
|
-
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), l = `${
|
|
25172
|
+
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), l = `${aS(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)}?v=${c}`;
|
|
24969
25173
|
return e.json({
|
|
24970
25174
|
id: i.id,
|
|
24971
25175
|
filename: i.filename,
|
|
@@ -24984,7 +25188,7 @@ tS.get("/", async (e) => {
|
|
|
24984
25188
|
if (t.cropCoordinatesJson) try {
|
|
24985
25189
|
n = JSON.parse(t.cropCoordinatesJson);
|
|
24986
25190
|
} catch {}
|
|
24987
|
-
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a =
|
|
25191
|
+
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a = aS(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
24988
25192
|
return {
|
|
24989
25193
|
id: t.id,
|
|
24990
25194
|
filename: t.filename,
|
|
@@ -25001,15 +25205,15 @@ tS.get("/", async (e) => {
|
|
|
25001
25205
|
} catch {
|
|
25002
25206
|
return e.json({ error: "Failed to load details" }, 500);
|
|
25003
25207
|
}
|
|
25004
|
-
}),
|
|
25208
|
+
}), nS.put("/:id", async (e) => {
|
|
25005
25209
|
try {
|
|
25006
|
-
let t = wb(e), n = e.req.param("id"), r = await e.req.json(), i = await
|
|
25210
|
+
let t = wb(e), n = e.req.param("id"), r = await e.req.json(), i = await rS(t, "SELECT filename, dataJson FROM assets WHERE id = ?", [n]);
|
|
25007
25211
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
25008
25212
|
let a = i[0], o = {};
|
|
25009
25213
|
try {
|
|
25010
25214
|
o = JSON.parse(a.dataJson || "{}");
|
|
25011
25215
|
} catch {}
|
|
25012
|
-
return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await
|
|
25216
|
+
return r.title !== void 0 && (o.title = r.title), r.alt !== void 0 && (o.alt = r.alt), r.description !== void 0 && (o.description = r.description), await iS(t, "UPDATE assets SET filename = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
25013
25217
|
r.filename === void 0 ? a.filename : r.filename,
|
|
25014
25218
|
JSON.stringify(o),
|
|
25015
25219
|
n
|
|
@@ -25017,10 +25221,10 @@ tS.get("/", async (e) => {
|
|
|
25017
25221
|
} catch {
|
|
25018
25222
|
return e.json({ error: "Failed to update asset" }, 500);
|
|
25019
25223
|
}
|
|
25020
|
-
}),
|
|
25224
|
+
}), nS.delete("/:id", async (e) => {
|
|
25021
25225
|
try {
|
|
25022
|
-
let t = wb(e), n = e.req.param("id"), r = (await
|
|
25023
|
-
return r ? (new fx(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await
|
|
25226
|
+
let t = wb(e), n = e.req.param("id"), r = (await rS(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
25227
|
+
return r ? (new fx(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await iS(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?", [n]) : await iS(t, "UPDATE assets SET deletedAt = CURRENT_TIMESTAMP WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [n, n]), e.json({
|
|
25024
25228
|
success: !0,
|
|
25025
25229
|
id: n,
|
|
25026
25230
|
trashed: !0
|
|
@@ -25031,10 +25235,10 @@ tS.get("/", async (e) => {
|
|
|
25031
25235
|
details: t.message || String(t)
|
|
25032
25236
|
}, 500);
|
|
25033
25237
|
}
|
|
25034
|
-
}),
|
|
25238
|
+
}), nS.post("/restore", async (e) => {
|
|
25035
25239
|
try {
|
|
25036
25240
|
let t = wb(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
25037
|
-
return r ? (await
|
|
25241
|
+
return r ? (await rS(t, "SELECT id, filename FROM assets WHERE id = ?", [r]))[0] ? (await iS(t, "UPDATE assets SET deletedAt = NULL WHERE id = ? OR (isSystemVariant = 1 AND parentAssetId = ?)", [r, r]), new fx(e.env).purgeAsset(e, t, r), e.json({
|
|
25038
25242
|
success: !0,
|
|
25039
25243
|
id: r,
|
|
25040
25244
|
restored: !0
|
|
@@ -25045,13 +25249,13 @@ tS.get("/", async (e) => {
|
|
|
25045
25249
|
details: t.message
|
|
25046
25250
|
}, 500);
|
|
25047
25251
|
}
|
|
25048
|
-
}),
|
|
25252
|
+
}), nS.delete("/purge/:id", async (e) => {
|
|
25049
25253
|
try {
|
|
25050
|
-
let t = wb(e), { storage: n } = ix(e.env), r = e.req.param("id"), i = (await
|
|
25254
|
+
let t = wb(e), { storage: n } = ix(e.env), r = e.req.param("id"), i = (await rS(t, "SELECT id, filename, storageKeyPrivate, isSystemVariant FROM assets WHERE id = ?", [r]))[0];
|
|
25051
25255
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
25052
25256
|
new fx(e.env).purgeAsset(e, t, r);
|
|
25053
25257
|
let a = [i];
|
|
25054
|
-
i.isSystemVariant || (a = [i, ...await
|
|
25258
|
+
i.isSystemVariant || (a = [i, ...await rS(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
25055
25259
|
let o = a.map((e) => e.id);
|
|
25056
25260
|
if (typeof n.delete == "function") {
|
|
25057
25261
|
for (let e of a) if (e.storageKeyPrivate) try {
|
|
@@ -25061,7 +25265,7 @@ tS.get("/", async (e) => {
|
|
|
25061
25265
|
}
|
|
25062
25266
|
}
|
|
25063
25267
|
let s = o.map(() => "?").join(",");
|
|
25064
|
-
return await
|
|
25268
|
+
return await iS(t, `DELETE FROM node_assets WHERE assetId IN (${s})`, o), await iS(t, `DELETE FROM assets WHERE id IN (${s})`, o), e.json({
|
|
25065
25269
|
success: !0,
|
|
25066
25270
|
id: r,
|
|
25067
25271
|
purged: !0,
|
|
@@ -25075,8 +25279,8 @@ tS.get("/", async (e) => {
|
|
|
25075
25279
|
}, 500);
|
|
25076
25280
|
}
|
|
25077
25281
|
});
|
|
25078
|
-
var
|
|
25079
|
-
function
|
|
25282
|
+
var oS = new $y();
|
|
25283
|
+
function sS() {
|
|
25080
25284
|
return {
|
|
25081
25285
|
fullPath: /* @__PURE__ */ new Map(),
|
|
25082
25286
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -25084,9 +25288,6 @@ function oS() {
|
|
|
25084
25288
|
assetUrls: /* @__PURE__ */ new Map()
|
|
25085
25289
|
};
|
|
25086
25290
|
}
|
|
25087
|
-
function sS(...e) {
|
|
25088
|
-
return e.map((e) => String(e ?? "")).join(":");
|
|
25089
|
-
}
|
|
25090
25291
|
function cS(e, t) {
|
|
25091
25292
|
let n = Date.now();
|
|
25092
25293
|
if (e && String(e).trim() !== "") {
|
|
@@ -25244,7 +25445,7 @@ function fS(e) {
|
|
|
25244
25445
|
}
|
|
25245
25446
|
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, fS(t)]));
|
|
25246
25447
|
}
|
|
25247
|
-
async function pS(e, t, n) {
|
|
25448
|
+
async function pS(e, t, n, r) {
|
|
25248
25449
|
if (typeof t == "string") {
|
|
25249
25450
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
25250
25451
|
let r = (e, t) => {
|
|
@@ -25254,78 +25455,48 @@ async function pS(e, t, n) {
|
|
|
25254
25455
|
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi)) i.add(e[1]);
|
|
25255
25456
|
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi)) a.add(e[1]);
|
|
25256
25457
|
if (i.size === 0 && a.size === 0) return t;
|
|
25257
|
-
let o =
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
if (!a || !o) return;
|
|
25265
|
-
let s = await hS(e, a, o, n);
|
|
25266
|
-
if (s?.treeNodeId) {
|
|
25267
|
-
let t = await yS(e, String(s.treeNodeId), o, n);
|
|
25268
|
-
f.set(`${a}:${o}`, t);
|
|
25269
|
-
}
|
|
25270
|
-
})), t.replace(p, (e, t) => {
|
|
25458
|
+
let o = /* @__PURE__ */ new Map();
|
|
25459
|
+
if (i.size > 0) {
|
|
25460
|
+
let t = Array.from(i).map(() => "?").join(","), r = await e.prepare(`SELECT nodeId, path FROM node_routes WHERE channelId = ? AND nodeId IN (${t}) AND isCanonical = 1`).all(n, ...i);
|
|
25461
|
+
(Array.isArray(r) ? r : r?.results || []).forEach((e) => o.set(String(e.nodeId), e.path));
|
|
25462
|
+
}
|
|
25463
|
+
let s = Array.from(a).map(() => "?").join(","), c = a.size > 0 ? await e.prepare(`SELECT id, cdnUrl, storageKeyPrivate FROM assets WHERE id IN (${s})`).all(...a) : [], l = /* @__PURE__ */ new Map();
|
|
25464
|
+
return (Array.isArray(c) ? c : c?.results || []).forEach((e) => l.set(String(e.id), e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""))), t.replace(/<a\s+([^>]+)>/gi, (e, t) => {
|
|
25271
25465
|
let n = r(t, "data-node-id"), i = r(t, "data-asset-id"), a = r(t, "href") || "";
|
|
25272
25466
|
if (a.startsWith("mailto:")) return `<a ${t.replace(/\s+target\s*=\s*["'][^"']*["']/i, "")}>`;
|
|
25273
|
-
let
|
|
25274
|
-
if (!
|
|
25275
|
-
if (
|
|
25276
|
-
let n =
|
|
25467
|
+
let s = i || a.match(/^#asset:(.+)$/i)?.[1], c = n || a.match(/^#node:(.+)$/i)?.[1];
|
|
25468
|
+
if (!c && !s) return e;
|
|
25469
|
+
if (s && !c) {
|
|
25470
|
+
let n = l.get(s);
|
|
25277
25471
|
if (n) {
|
|
25278
25472
|
let e = t;
|
|
25279
|
-
return /href\s*=\s*["'][^"']*["']/i.test(e) ? e = e.replace(/href\s*=\s*["'][^"']*["']/i, `href="${n}"`) : e += ` href="${n}"`, i || (e += ` data-asset-id="${
|
|
25473
|
+
return /href\s*=\s*["'][^"']*["']/i.test(e) ? e = e.replace(/href\s*=\s*["'][^"']*["']/i, `href="${n}"`) : e += ` href="${n}"`, i || (e += ` data-asset-id="${s}"`), `<a ${e}>`;
|
|
25280
25474
|
}
|
|
25281
25475
|
return e;
|
|
25282
25476
|
}
|
|
25283
|
-
let
|
|
25284
|
-
return /href\s*=\s*["'][^"']*["']/i.test(
|
|
25477
|
+
let u = o.get(c) || "#", d = t;
|
|
25478
|
+
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
25285
25479
|
});
|
|
25286
25480
|
}
|
|
25287
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) => pS(e, t, n)));
|
|
25481
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => pS(e, t, n, r)));
|
|
25288
25482
|
if (t && typeof t == "object") {
|
|
25289
25483
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
|
|
25290
25484
|
...t,
|
|
25291
|
-
href: await mS(e, t, n)
|
|
25485
|
+
href: await mS(e, t, n, r)
|
|
25292
25486
|
};
|
|
25293
|
-
let
|
|
25294
|
-
return Object.fromEntries(
|
|
25487
|
+
let i = await Promise.all(Object.entries(t).map(async ([t, i]) => [t, await pS(e, i, n, r)]));
|
|
25488
|
+
return Object.fromEntries(i);
|
|
25295
25489
|
}
|
|
25296
25490
|
return t;
|
|
25297
25491
|
}
|
|
25298
|
-
async function mS(e, t, n) {
|
|
25299
|
-
let
|
|
25300
|
-
if (
|
|
25301
|
-
if (!
|
|
25302
|
-
let
|
|
25303
|
-
|
|
25304
|
-
let r = await hS(e, a, String(t.treeId), n);
|
|
25305
|
-
if (r?.treeNodeId) {
|
|
25306
|
-
let i = await yS(e, String(r.treeNodeId), String(t.treeId), n);
|
|
25307
|
-
if (i) return i;
|
|
25308
|
-
}
|
|
25309
|
-
}
|
|
25310
|
-
let o = await gS(e, a, n);
|
|
25311
|
-
return o === void 0 ? "#" : `/${o}`;
|
|
25312
|
-
}
|
|
25313
|
-
async function hS(e, t, n, r) {
|
|
25314
|
-
let i = sS(t, n), a = r.treeEdges.get(i);
|
|
25315
|
-
if (a) return a;
|
|
25316
|
-
let o = e.prepare("SELECT contentId as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
|
|
25317
|
-
return r.treeEdges.set(i, Promise.resolve(o)), o;
|
|
25318
|
-
}
|
|
25319
|
-
async function gS(e, t, n) {
|
|
25320
|
-
let r = String(t), i = n.nodeSlugs.get(r);
|
|
25321
|
-
if (i) return i;
|
|
25322
|
-
let a = (async () => {
|
|
25323
|
-
let n = await e.prepare("SELECT slug FROM content_nodes WHERE id = ?").get(t);
|
|
25324
|
-
return n?.slug ? String(n.slug).replace(/^\/+|\/+$/g, "") : void 0;
|
|
25325
|
-
})();
|
|
25326
|
-
return n.nodeSlugs.set(r, a), a;
|
|
25492
|
+
async function mS(e, t, n, r) {
|
|
25493
|
+
let i = t.href.match(/^#node:(.+)$/), a = t.href.match(/^#asset:(.+)$/);
|
|
25494
|
+
if (a) return hS(e, a[1], r);
|
|
25495
|
+
if (!i) return t.href;
|
|
25496
|
+
let o = i[1];
|
|
25497
|
+
return (await e.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND channelId = ? AND isCanonical = 1 LIMIT 1").get(Number(o), n))?.path || "#";
|
|
25327
25498
|
}
|
|
25328
|
-
async function
|
|
25499
|
+
async function hS(e, t, n) {
|
|
25329
25500
|
let r = String(t), i = n.assetUrls.get(r);
|
|
25330
25501
|
if (i) return i;
|
|
25331
25502
|
let a = (async () => {
|
|
@@ -25334,7 +25505,7 @@ async function _S(e, t, n) {
|
|
|
25334
25505
|
})();
|
|
25335
25506
|
return n.assetUrls.set(r, a), a;
|
|
25336
25507
|
}
|
|
25337
|
-
function
|
|
25508
|
+
function gS(e) {
|
|
25338
25509
|
let t = e.socialImage;
|
|
25339
25510
|
if (!t || typeof t != "object") return null;
|
|
25340
25511
|
let n = (e, t) => {
|
|
@@ -25365,24 +25536,7 @@ function vS(e) {
|
|
|
25365
25536
|
])
|
|
25366
25537
|
};
|
|
25367
25538
|
}
|
|
25368
|
-
async function
|
|
25369
|
-
if (!t) return "";
|
|
25370
|
-
let i = sS(t, n);
|
|
25371
|
-
if (r) {
|
|
25372
|
-
let e = r.fullPath.get(i);
|
|
25373
|
-
if (e) return e;
|
|
25374
|
-
}
|
|
25375
|
-
let a = (async () => {
|
|
25376
|
-
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 = [];
|
|
25377
|
-
for (let e of i) {
|
|
25378
|
-
let t = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
25379
|
-
t === "home" || t === "homee" ? i.length === 1 && (a.length = 0) : t && a.push(t);
|
|
25380
|
-
}
|
|
25381
|
-
return "/" + a.join("/");
|
|
25382
|
-
})();
|
|
25383
|
-
return r && r.fullPath.set(i, a), a;
|
|
25384
|
-
}
|
|
25385
|
-
async function bS(e, t, n, r, i) {
|
|
25539
|
+
async function _S(e, t, n, r, i) {
|
|
25386
25540
|
let a = {}, o = null;
|
|
25387
25541
|
if (t) {
|
|
25388
25542
|
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([
|
|
@@ -25420,200 +25574,151 @@ async function bS(e, t, n, r, i) {
|
|
|
25420
25574
|
inheritedFields: a
|
|
25421
25575
|
};
|
|
25422
25576
|
}
|
|
25423
|
-
function
|
|
25577
|
+
function vS(e) {
|
|
25424
25578
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
25425
25579
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
25426
25580
|
}
|
|
25427
|
-
async function
|
|
25581
|
+
async function yS(e, t, n, r) {
|
|
25428
25582
|
try {
|
|
25429
25583
|
await e.set(t, n, r);
|
|
25430
25584
|
} catch (e) {
|
|
25431
25585
|
console.warn("[CMS Cache] Failed to write node response to cache:", e);
|
|
25432
25586
|
}
|
|
25433
25587
|
}
|
|
25434
|
-
|
|
25435
|
-
channelId: J().optional().openapi({ description: "The ID or key of the channel" }),
|
|
25436
|
-
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25437
|
-
lang: J().optional().openapi({ description: "Requested language code" }),
|
|
25438
|
-
preview: lv(["true", "false"]).optional().openapi({ description: "Request unpublished draft data" }),
|
|
25439
|
-
revisionId: J().optional().openapi({ description: "Historical revision version to load" }),
|
|
25440
|
-
treeId: J().optional().openapi({ description: "The ID of the tree to resolve paths against" })
|
|
25441
|
-
}), wS = X({
|
|
25442
|
-
error: J(),
|
|
25443
|
-
details: J().optional()
|
|
25444
|
-
}).openapi("ErrorResponse"), TS = X({
|
|
25445
|
-
channelId: G_([J(), c_()]),
|
|
25446
|
-
treeId: J().nullable(),
|
|
25447
|
-
language: J().nullable(),
|
|
25448
|
-
node: tv(k_()),
|
|
25449
|
-
content: tv(z_(k_())),
|
|
25450
|
-
regionMeta: tv(X({
|
|
25451
|
-
isInherited: g_(),
|
|
25452
|
-
inheritedFromId: J().optional(),
|
|
25453
|
-
inheritedFromTitle: J().optional()
|
|
25454
|
-
}))
|
|
25455
|
-
}).openapi("NodeResponse"), ES = eb({
|
|
25456
|
-
method: "get",
|
|
25457
|
-
path: "/{path+}",
|
|
25458
|
-
summary: "Fetch CMS Node Content",
|
|
25459
|
-
description: "Retrieves a fully hydrated CMS node along with its content blocks and inherited regions.",
|
|
25460
|
-
tags: ["Public Node API"],
|
|
25461
|
-
request: {
|
|
25462
|
-
params: X({ path: J().optional().openapi({ description: "The full URL path or slug of the requested node" }) }),
|
|
25463
|
-
query: CS
|
|
25464
|
-
},
|
|
25465
|
-
responses: {
|
|
25466
|
-
200: {
|
|
25467
|
-
description: "Fully hydrated CMS Node",
|
|
25468
|
-
content: { "application/json": { schema: TS } }
|
|
25469
|
-
},
|
|
25470
|
-
404: {
|
|
25471
|
-
description: "Node or Channel not found",
|
|
25472
|
-
content: { "application/json": { schema: wS } }
|
|
25473
|
-
},
|
|
25474
|
-
500: {
|
|
25475
|
-
description: "Server error during hydration",
|
|
25476
|
-
content: { "application/json": { schema: wS } }
|
|
25477
|
-
}
|
|
25478
|
-
}
|
|
25479
|
-
});
|
|
25480
|
-
aS.openapi(ES, async (e) => {
|
|
25588
|
+
async function bS(e) {
|
|
25481
25589
|
try {
|
|
25482
|
-
let t = e.get("db"), n =
|
|
25483
|
-
|
|
25484
|
-
|
|
25485
|
-
|
|
25486
|
-
|
|
25487
|
-
|
|
25488
|
-
|
|
25489
|
-
|
|
25490
|
-
|
|
25491
|
-
|
|
25492
|
-
|
|
25493
|
-
|
|
25494
|
-
|
|
25495
|
-
|
|
25496
|
-
|
|
25497
|
-
|
|
25498
|
-
|
|
25499
|
-
|
|
25500
|
-
|
|
25501
|
-
|
|
25502
|
-
|
|
25503
|
-
}
|
|
25590
|
+
let t = e.get("db"), n = sS(), r = new URL(e.req.url), i = r.searchParams.get("channelId") || r.searchParams.get("channel"), a = r.searchParams.get("lang"), o = r.searchParams.get("preview") === "true", s = r.searchParams.get("revisionId"), c = r.searchParams.get("treeId"), l = r.pathname, u = "";
|
|
25591
|
+
l.includes("/node/") ? u = l.substring(l.indexOf("/node/") + 6) : l.endsWith("/node") && (u = "");
|
|
25592
|
+
try {
|
|
25593
|
+
u = decodeURIComponent(u);
|
|
25594
|
+
} catch {}
|
|
25595
|
+
u = u.replace(/^\/+|\/+$/g, "");
|
|
25596
|
+
let d = u === "" || u === "index" ? "/" : `/${u}`, f = i || "1", p = isNaN(Number(f)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(f) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(f));
|
|
25597
|
+
if (!p) return e.json({ error: `Channel '${f}' not found` }, 404);
|
|
25598
|
+
let m = p.status === "disabled" || p.status === "inactive" || p.isEnabled === 0 || p.isEnabled === !1;
|
|
25599
|
+
if (!o && m) return e.json({ error: `Channel '${p.key || f}' is currently inactive` }, 404);
|
|
25600
|
+
let h = p.id, g = p.key || f, _ = await t.prepare("\n SELECT * FROM node_routes WHERE path = ? AND channelId = ? LIMIT 1\n ").get(d, h);
|
|
25601
|
+
if (_?.redirectUrl) return e.json({
|
|
25602
|
+
redirect: _.redirectUrl,
|
|
25603
|
+
isCanonical: !1
|
|
25604
|
+
});
|
|
25605
|
+
let v = null, y = _?.treeId || c || null;
|
|
25606
|
+
if (_?.nodeId) v = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(_.nodeId);
|
|
25607
|
+
else if (/^\d+$/.test(u)) v = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(Number(u));
|
|
25608
|
+
else {
|
|
25609
|
+
let e = u.split("/").pop() || u;
|
|
25610
|
+
v = await t.prepare("SELECT * FROM content_nodes WHERE slug = ?").get(e);
|
|
25504
25611
|
}
|
|
25505
|
-
if (!
|
|
25506
|
-
let
|
|
25507
|
-
if (
|
|
25508
|
-
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(
|
|
25612
|
+
if (!v) return e.json({ error: `Node '${u}' not found for Channel '${f}'` }, 404);
|
|
25613
|
+
let b = null;
|
|
25614
|
+
if (s) {
|
|
25615
|
+
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(v.id, Number(s));
|
|
25509
25616
|
if (e && e.snapshotJson) try {
|
|
25510
|
-
|
|
25617
|
+
b = JSON.parse(e.snapshotJson), b.node && (b.node.title && (v.title = b.node.title), b.node.slug && (v.slug = b.node.slug));
|
|
25511
25618
|
} catch (e) {
|
|
25512
25619
|
console.error("[CMS] Failed to parse snapshotJson", e);
|
|
25513
25620
|
}
|
|
25514
25621
|
}
|
|
25515
|
-
|
|
25516
|
-
|
|
25517
|
-
|
|
25518
|
-
|
|
25519
|
-
|
|
25520
|
-
if (D) {
|
|
25521
|
-
let e = await t.prepare("\n SELECT dataJson \n FROM trees \n WHERE id = ? OR key = ? \n LIMIT 1\n ").get(Number(D) || -1, String(D));
|
|
25622
|
+
let x = await t.prepare(`SELECT contentId as treeNodeId, treeId, parentId FROM tree_nodes WHERE contentId = ? ${y ? "AND treeId = ?" : ""} LIMIT 1`).get(v.id, ...y ? [y] : []);
|
|
25623
|
+
!y && x?.treeId && (y = x.treeId), y ||= "main-nav";
|
|
25624
|
+
let S = null;
|
|
25625
|
+
if (y) {
|
|
25626
|
+
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(y) || -1, String(y));
|
|
25522
25627
|
if (e?.dataJson) try {
|
|
25523
25628
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
25524
|
-
t.defaultLanguage ?
|
|
25629
|
+
t.defaultLanguage ? S = String(t.defaultLanguage).trim() : t.language && (S = String(t.language).trim());
|
|
25525
25630
|
} catch {}
|
|
25526
25631
|
}
|
|
25527
|
-
let
|
|
25528
|
-
if (
|
|
25529
|
-
if (
|
|
25530
|
-
else if (
|
|
25531
|
-
let e = typeof
|
|
25532
|
-
e.defaultLanguage ?
|
|
25632
|
+
let C = null;
|
|
25633
|
+
if (p) {
|
|
25634
|
+
if (p.defaultLanguage) C = String(p.defaultLanguage).trim();
|
|
25635
|
+
else if (p.dataJson) try {
|
|
25636
|
+
let e = typeof p.dataJson == "string" ? JSON.parse(p.dataJson) : p.dataJson;
|
|
25637
|
+
e.defaultLanguage ? C = String(e.defaultLanguage).trim() : e.language && (C = String(e.language).trim());
|
|
25533
25638
|
} catch {}
|
|
25534
25639
|
}
|
|
25535
|
-
let
|
|
25536
|
-
if (!
|
|
25537
|
-
let t = await
|
|
25640
|
+
let ee = v.language?.trim() || null, w = S || C || a?.trim() || null, T = ee || w || null, E = `node:${h || g}:${T || "default"}:${u}`, D = e.req.header("x-bypass-cache") === "true" || !!s, te = $b(e);
|
|
25641
|
+
if (!o && !D) {
|
|
25642
|
+
let t = await te.get(E);
|
|
25538
25643
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
25539
25644
|
}
|
|
25540
|
-
let
|
|
25541
|
-
id:
|
|
25542
|
-
title:
|
|
25543
|
-
slug:
|
|
25544
|
-
language:
|
|
25545
|
-
path:
|
|
25546
|
-
nodeType:
|
|
25547
|
-
createdAt:
|
|
25548
|
-
updatedAt:
|
|
25549
|
-
},
|
|
25550
|
-
|
|
25551
|
-
Object.assign(
|
|
25645
|
+
let ne = x?.parentId || null, O = _?.path || (d === "" ? "/" : d), k = {
|
|
25646
|
+
id: v.id,
|
|
25647
|
+
title: v.title,
|
|
25648
|
+
slug: v.slug,
|
|
25649
|
+
language: T,
|
|
25650
|
+
path: O,
|
|
25651
|
+
nodeType: v.contentType,
|
|
25652
|
+
createdAt: v.createdAt,
|
|
25653
|
+
updatedAt: v.updatedAt
|
|
25654
|
+
}, A = dx(e.env?.BUNDLED_DEFINITIONS), re = v.contentType || "node", ie = A.nodes?.[re] || Object.values(A.nodes || {})[0] || {}, ae = { ...ie.fields || {} };
|
|
25655
|
+
ie.tabs && Object.values(ie.tabs).forEach((e) => {
|
|
25656
|
+
Object.assign(ae, e.fields || {});
|
|
25552
25657
|
});
|
|
25553
|
-
let
|
|
25554
|
-
if (
|
|
25555
|
-
|
|
25658
|
+
let oe = {}, se = null, ce = null, le = !1, j = {}, ue = o && v.draftDataJson || v.dataJson;
|
|
25659
|
+
if (b && b.node && b.node.dataJson && (ue = b.node.dataJson), ue) try {
|
|
25660
|
+
j = typeof ue == "string" ? JSON.parse(ue) : ue;
|
|
25556
25661
|
} catch {}
|
|
25557
|
-
|
|
25558
|
-
let
|
|
25559
|
-
for (let [e, t] of Object.entries(
|
|
25560
|
-
let
|
|
25561
|
-
|
|
25562
|
-
let
|
|
25563
|
-
delete
|
|
25564
|
-
let
|
|
25565
|
-
if (!
|
|
25566
|
-
let
|
|
25567
|
-
if (
|
|
25568
|
-
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(
|
|
25569
|
-
|
|
25570
|
-
let t = {}, n =
|
|
25662
|
+
j.disabledRegions && (oe = j.disabledRegions), le = j.hidden === !0 || j.hidden === 1 || j.hidden === "1" || j.hidden === "true", se = j.startShowingAt || null, ce = j.stopShowingAt || null;
|
|
25663
|
+
let de = j.layoutId, fe = de && de !== "inherit", { resolvedLayoutId: pe, inheritedFields: me } = await _S(t, ne, y, o, ae), he = fe ? de : pe || ie.defaultLayout || null;
|
|
25664
|
+
for (let [e, t] of Object.entries(me)) (j[e] === void 0 || j[e] === null || j[e] === "" || j[e] === "inherit") && t !== void 0 && (j[e] = t);
|
|
25665
|
+
let ge = await ux(t, dS(j, ae));
|
|
25666
|
+
ge = fS(ge), ge = await pS(t, ge, h, n), delete ge.language;
|
|
25667
|
+
let _e = gS(ge);
|
|
25668
|
+
delete ge.socialImage, delete ge.fbImage, delete ge.xImage, delete ge.whatsappImage, _e && (ge.socialImages = _e), Object.assign(k, ge), k.id = v.id, k.slug = v.slug, k.title = v.title, k.path = O, k.layoutId = he;
|
|
25669
|
+
let ve = Number(v.isHidden) === 1 || le, ye = !cS(se, ce), be = v.status === "draft" || v.status === "new", xe = v.dataJson && v.dataJson !== "{}" && v.dataJson !== "null";
|
|
25670
|
+
if (!o && (ve || ye || be && !xe)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
25671
|
+
let Se = [];
|
|
25672
|
+
if (x?.treeNodeId) {
|
|
25673
|
+
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(x.treeNodeId, y), n = Array.isArray(e) ? e : e?.results || [], r = k.path || "", i = r === "/" ? "" : r;
|
|
25674
|
+
Se = n.map((e) => {
|
|
25675
|
+
let t = {}, n = o && e.draftDataJson || e.dataJson;
|
|
25571
25676
|
if (!n) return null;
|
|
25572
25677
|
try {
|
|
25573
25678
|
t = (typeof n == "string" ? JSON.parse(n) : n) || {};
|
|
25574
25679
|
} catch {}
|
|
25575
|
-
let
|
|
25576
|
-
return !
|
|
25680
|
+
let r = Number(e.isHidden) === 1 || t.hidden === !0 || t.hidden === 1 || t.hidden === "1", a = cS(t.startShowingAt, t.stopShowingAt), s = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
25681
|
+
return !o && (r || !a) ? null : {
|
|
25577
25682
|
treeNodeId: e.treeNodeId,
|
|
25578
25683
|
id: e.id,
|
|
25579
25684
|
title: e.title,
|
|
25580
|
-
slug:
|
|
25581
|
-
language: e.language?.trim() ||
|
|
25582
|
-
path: `${
|
|
25685
|
+
slug: s,
|
|
25686
|
+
language: e.language?.trim() || T || null,
|
|
25687
|
+
path: `${i}/${s}`.replace(/\/+/g, "/"),
|
|
25583
25688
|
nodeType: e.nodeType
|
|
25584
25689
|
};
|
|
25585
25690
|
}).filter(Boolean);
|
|
25586
25691
|
}
|
|
25587
|
-
|
|
25588
|
-
let
|
|
25589
|
-
if (
|
|
25692
|
+
k.children = Se;
|
|
25693
|
+
let Ce = [];
|
|
25694
|
+
if (b && b.blocks && Array.isArray(b.blocks)) Ce = b.blocks.map((e) => ({
|
|
25590
25695
|
...e,
|
|
25591
25696
|
isDraft: 1
|
|
25592
25697
|
}));
|
|
25593
25698
|
else {
|
|
25594
|
-
let e = +!!
|
|
25595
|
-
|
|
25699
|
+
let e = +!!o, n = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(v.id, e);
|
|
25700
|
+
Ce = Array.isArray(n) ? n : n?.results || [];
|
|
25596
25701
|
}
|
|
25597
|
-
let
|
|
25702
|
+
let we = {}, Te = {}, Ee = await Promise.all(Ce.map(async (e) => {
|
|
25598
25703
|
let r = e.region || "main", i = {};
|
|
25599
25704
|
try {
|
|
25600
25705
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
25601
25706
|
} catch {}
|
|
25602
|
-
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true",
|
|
25603
|
-
if (!
|
|
25604
|
-
let
|
|
25605
|
-
return d = await ux(t, d), d = fS(d), d = await pS(t, d, n), d.blockId = u, {
|
|
25707
|
+
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", s = cS(i.startShowingAt, i.stopShowingAt);
|
|
25708
|
+
if (!o && (a || !s)) return null;
|
|
25709
|
+
let c = e.elementType || e.componentId || "text-block", l = A.blocks?.[c]?.fields || A.elements?.[c]?.fields || A.components?.[c]?.fields || {}, u = String(i.blockId || i._instanceId || i.id || e.blockId || e.id), d = dS(i, l);
|
|
25710
|
+
return d = await ux(t, d), d = fS(d), d = await pS(t, d, h, n), d.blockId = u, {
|
|
25606
25711
|
region: r,
|
|
25607
25712
|
block: {
|
|
25608
25713
|
instanceId: e.id,
|
|
25609
25714
|
blockId: u,
|
|
25610
|
-
componentId:
|
|
25715
|
+
componentId: c,
|
|
25611
25716
|
data: d
|
|
25612
25717
|
}
|
|
25613
25718
|
};
|
|
25614
25719
|
}));
|
|
25615
|
-
for (let e of
|
|
25616
|
-
let
|
|
25720
|
+
for (let e of Ee) e && (we[e.region] || (we[e.region] = [], Te[e.region] = { isInherited: !1 }), we[e.region].push(e.block));
|
|
25721
|
+
let De = {
|
|
25617
25722
|
header: {
|
|
25618
25723
|
label: "Header",
|
|
25619
25724
|
inherit: "parent"
|
|
@@ -25622,42 +25727,89 @@ aS.openapi(ES, async (e) => {
|
|
|
25622
25727
|
label: "Footer",
|
|
25623
25728
|
inherit: "parent"
|
|
25624
25729
|
},
|
|
25625
|
-
...(
|
|
25730
|
+
...(he ? A.nodeLayouts?.[he] || A.layouts?.[he] : null)?.regions || { main: { label: "Content" } }
|
|
25626
25731
|
};
|
|
25627
|
-
for (let [e, r] of Object.entries(
|
|
25628
|
-
let i =
|
|
25629
|
-
if (
|
|
25630
|
-
let r = await uS(t,
|
|
25631
|
-
if (r.blocks.length > 0 && (
|
|
25732
|
+
for (let [e, r] of Object.entries(De)) {
|
|
25733
|
+
let i = we[e] && we[e].length > 0, a = !!oe[e];
|
|
25734
|
+
if (we[e] || (we[e] = [], Te[e] = { isInherited: !1 }), (r?.inherit === "parent" || r?.inherit === !0 || r?.inherit === "true" || e === "header" || e === "footer") && !i && !a && ne) {
|
|
25735
|
+
let r = await uS(t, ne, String(y), e, A, o, n);
|
|
25736
|
+
if (r.blocks.length > 0 && (we[e] = r.blocks, Te[e] = {
|
|
25632
25737
|
isInherited: !0,
|
|
25633
25738
|
inheritedFromId: r.inheritedFromId,
|
|
25634
25739
|
inheritedFromTitle: r.inheritedFromTitle
|
|
25635
|
-
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (
|
|
25740
|
+
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (we[t] = n, Te[t] = {
|
|
25636
25741
|
isInherited: !0,
|
|
25637
25742
|
inheritedFromId: r.inheritedFromId,
|
|
25638
25743
|
inheritedFromTitle: r.inheritedFromTitle
|
|
25639
25744
|
});
|
|
25640
25745
|
}
|
|
25641
25746
|
}
|
|
25642
|
-
await Promise.all(Object.keys(
|
|
25643
|
-
let
|
|
25644
|
-
channelId:
|
|
25645
|
-
treeId:
|
|
25646
|
-
language:
|
|
25647
|
-
node:
|
|
25648
|
-
content:
|
|
25649
|
-
regionMeta:
|
|
25747
|
+
await Promise.all(Object.keys(we).map((e) => lS(t, we[e], h, T)));
|
|
25748
|
+
let Oe = {
|
|
25749
|
+
channelId: h || g,
|
|
25750
|
+
treeId: y,
|
|
25751
|
+
language: T,
|
|
25752
|
+
node: k,
|
|
25753
|
+
content: we,
|
|
25754
|
+
regionMeta: Te
|
|
25650
25755
|
};
|
|
25651
|
-
return !
|
|
25756
|
+
return !o && !D && (e.header("X-Cache", "MISS"), await yS(te, E, Oe, vS(e))), e.json(Oe, 200);
|
|
25652
25757
|
} catch (t) {
|
|
25653
25758
|
return console.error("[CMS Public API] Error fetching node by path:", t), e.json({
|
|
25654
25759
|
error: "Failed to fetch JSON payload",
|
|
25655
25760
|
...e.env?.ENVIRONMENT === "development" ? { details: t.message } : {}
|
|
25656
25761
|
}, 500);
|
|
25657
25762
|
}
|
|
25763
|
+
}
|
|
25764
|
+
var xS = X({
|
|
25765
|
+
channelId: J().optional().openapi({ description: "The ID or key of the channel" }),
|
|
25766
|
+
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25767
|
+
lang: J().optional().openapi({ description: "Requested language code" }),
|
|
25768
|
+
preview: lv(["true", "false"]).optional().openapi({ description: "Request unpublished draft data" }),
|
|
25769
|
+
revisionId: J().optional().openapi({ description: "Historical revision version to load" }),
|
|
25770
|
+
treeId: J().optional().openapi({ description: "The ID of the tree to resolve paths against" })
|
|
25771
|
+
}), SS = X({
|
|
25772
|
+
error: J(),
|
|
25773
|
+
details: J().optional()
|
|
25774
|
+
}).openapi("ErrorResponse"), CS = X({
|
|
25775
|
+
channelId: G_([J(), c_()]),
|
|
25776
|
+
treeId: J().nullable(),
|
|
25777
|
+
language: J().nullable(),
|
|
25778
|
+
node: tv(k_()),
|
|
25779
|
+
content: tv(z_(k_())),
|
|
25780
|
+
regionMeta: tv(X({
|
|
25781
|
+
isInherited: g_(),
|
|
25782
|
+
inheritedFromId: J().optional(),
|
|
25783
|
+
inheritedFromTitle: J().optional()
|
|
25784
|
+
}))
|
|
25785
|
+
}).openapi("NodeResponse"), wS = eb({
|
|
25786
|
+
method: "get",
|
|
25787
|
+
path: "/{path}",
|
|
25788
|
+
summary: "Fetch CMS Node Content",
|
|
25789
|
+
description: "Retrieves a fully hydrated CMS node along with its content blocks and inherited regions using $O(1)$ routing table lookups.",
|
|
25790
|
+
tags: ["Public Node API"],
|
|
25791
|
+
request: {
|
|
25792
|
+
params: X({ path: J().optional().openapi({ description: "The full URL path or slug of the requested node" }) }),
|
|
25793
|
+
query: xS
|
|
25794
|
+
},
|
|
25795
|
+
responses: {
|
|
25796
|
+
200: {
|
|
25797
|
+
description: "Fully hydrated CMS Node",
|
|
25798
|
+
content: { "application/json": { schema: CS } }
|
|
25799
|
+
},
|
|
25800
|
+
404: {
|
|
25801
|
+
description: "Node or Channel not found",
|
|
25802
|
+
content: { "application/json": { schema: SS } }
|
|
25803
|
+
},
|
|
25804
|
+
500: {
|
|
25805
|
+
description: "Server error during hydration",
|
|
25806
|
+
content: { "application/json": { schema: SS } }
|
|
25807
|
+
}
|
|
25808
|
+
}
|
|
25658
25809
|
});
|
|
25659
|
-
|
|
25660
|
-
|
|
25810
|
+
oS.openapi(wS, bS), oS.get("*", bS);
|
|
25811
|
+
var TS = new $y();
|
|
25812
|
+
function ES(e, t) {
|
|
25661
25813
|
let n = /* @__PURE__ */ new Date();
|
|
25662
25814
|
if (e && String(e).trim() !== "") {
|
|
25663
25815
|
let t = new Date(e);
|
|
@@ -25669,22 +25821,22 @@ function OS(e, t) {
|
|
|
25669
25821
|
}
|
|
25670
25822
|
return !0;
|
|
25671
25823
|
}
|
|
25672
|
-
async function
|
|
25824
|
+
async function DS(e, t, n, r) {
|
|
25673
25825
|
try {
|
|
25674
25826
|
await e.set(t, n, r);
|
|
25675
25827
|
} catch (e) {
|
|
25676
25828
|
console.warn("[CMS Cache] Failed to write tree response to cache:", e);
|
|
25677
25829
|
}
|
|
25678
25830
|
}
|
|
25679
|
-
var
|
|
25831
|
+
var OS = X({ treeParam: J().openapi({ description: "The ID or key of the requested tree (e.g., \"main-nav\")" }) }), kS = X({
|
|
25680
25832
|
channelId: J().optional().openapi({ description: "Channel ID to resolve context-aware routing" }),
|
|
25681
25833
|
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25682
25834
|
lang: J().optional().openapi({ description: "Requested language code for tree nodes" }),
|
|
25683
25835
|
preview: lv(["true", "false"]).optional().openapi({ description: "Set to true to retrieve unpublished draft data" })
|
|
25684
|
-
}),
|
|
25836
|
+
}), AS = X({
|
|
25685
25837
|
error: J(),
|
|
25686
25838
|
details: J().optional()
|
|
25687
|
-
}).openapi("ErrorResponse"),
|
|
25839
|
+
}).openapi("ErrorResponse"), jS = qv(() => X({
|
|
25688
25840
|
id: G_([J(), c_()]),
|
|
25689
25841
|
treeNodeId: G_([J(), c_()]),
|
|
25690
25842
|
parentId: G_([J(), c_()]).nullable(),
|
|
@@ -25697,129 +25849,129 @@ var AS = X({ treeParam: J().openapi({ description: "The ID or key of the request
|
|
|
25697
25849
|
summary: J(),
|
|
25698
25850
|
url: J().optional(),
|
|
25699
25851
|
target: J().optional(),
|
|
25700
|
-
children: z_(
|
|
25701
|
-
})).openapi("TreeItem"),
|
|
25852
|
+
children: z_(jS).optional()
|
|
25853
|
+
})).openapi("TreeItem"), MS = X({
|
|
25702
25854
|
treeId: G_([c_(), J()]),
|
|
25703
25855
|
key: J(),
|
|
25704
25856
|
channelId: J(),
|
|
25705
25857
|
language: J().nullable(),
|
|
25706
25858
|
label: J(),
|
|
25707
|
-
items: z_(
|
|
25708
|
-
}).catchall(k_()).openapi("TreeResponse"),
|
|
25859
|
+
items: z_(jS)
|
|
25860
|
+
}).catchall(k_()).openapi("TreeResponse"), NS = eb({
|
|
25709
25861
|
method: "get",
|
|
25710
25862
|
path: "/{treeParam}",
|
|
25711
25863
|
summary: "Fetch CMS Navigation Tree",
|
|
25712
|
-
description: "Retrieves a fully hydrated, recursive navigation tree structure.
|
|
25864
|
+
description: "Retrieves a fully hydrated, recursive navigation tree structure. Uses $O(1)$ pre-computed routing table paths.",
|
|
25713
25865
|
tags: ["Public Tree API"],
|
|
25714
25866
|
request: {
|
|
25715
|
-
params:
|
|
25716
|
-
query:
|
|
25867
|
+
params: OS,
|
|
25868
|
+
query: kS
|
|
25717
25869
|
},
|
|
25718
25870
|
responses: {
|
|
25719
25871
|
200: {
|
|
25720
25872
|
description: "Fully hydrated CMS Tree payload",
|
|
25721
|
-
content: { "application/json": { schema:
|
|
25873
|
+
content: { "application/json": { schema: MS } }
|
|
25722
25874
|
},
|
|
25723
25875
|
404: {
|
|
25724
25876
|
description: "Tree or Channel not found / inactive",
|
|
25725
|
-
content: { "application/json": { schema:
|
|
25877
|
+
content: { "application/json": { schema: AS } }
|
|
25726
25878
|
},
|
|
25727
25879
|
500: {
|
|
25728
25880
|
description: "Server error during hydration",
|
|
25729
|
-
content: { "application/json": { schema:
|
|
25881
|
+
content: { "application/json": { schema: AS } }
|
|
25730
25882
|
}
|
|
25731
25883
|
}
|
|
25732
25884
|
});
|
|
25733
|
-
|
|
25885
|
+
TS.openapi(NS, async (e) => {
|
|
25734
25886
|
try {
|
|
25735
|
-
let t = e.get("db"), { treeParam: n } = e.req.valid("param"), r = e.req.valid("query"), i = r.channelId || r.channel || "default", a = r.lang, o = r.preview === "true", s = null;
|
|
25887
|
+
let t = e.get("db"), { treeParam: n } = e.req.valid("param"), r = e.req.valid("query"), i = r.channelId || r.channel || "default", a = r.lang, o = r.preview === "true", s = null, c = -1;
|
|
25736
25888
|
if (i && i !== "default" && i !== "all") {
|
|
25737
25889
|
let n = isNaN(Number(i)) ? await t.prepare("SELECT * FROM channels WHERE key = ?").get(i) : await t.prepare("SELECT * FROM channels WHERE id = ?").get(Number(i));
|
|
25738
25890
|
if (n) {
|
|
25739
|
-
n.defaultLanguage && (s = n.defaultLanguage.trim());
|
|
25891
|
+
c = Number(n.id), n.defaultLanguage && (s = n.defaultLanguage.trim());
|
|
25740
25892
|
let t = n.status === "disabled" || n.status === "inactive" || n.isEnabled === 0 || n.isEnabled === !1;
|
|
25741
25893
|
if (!o && t) return e.json({ error: `Channel '${n.key || i}' is currently inactive` }, 404);
|
|
25742
25894
|
}
|
|
25743
25895
|
}
|
|
25744
|
-
let
|
|
25745
|
-
if (
|
|
25746
|
-
let
|
|
25747
|
-
if (
|
|
25748
|
-
if (
|
|
25749
|
-
else if (
|
|
25750
|
-
let e = typeof
|
|
25751
|
-
e.defaultLanguage && (
|
|
25896
|
+
let l = !isNaN(Number(n)), u = l ? await t.prepare("SELECT * FROM trees WHERE id = ?").get(Number(n)) : await t.prepare("SELECT * FROM trees WHERE key = ?").get(n);
|
|
25897
|
+
if (u && Number(u.isHidden) === 1 && !o) return e.json({ error: `Tree '${n}' is hidden` }, 404);
|
|
25898
|
+
let d = null;
|
|
25899
|
+
if (u) {
|
|
25900
|
+
if (u.defaultLanguage) d = String(u.defaultLanguage).trim();
|
|
25901
|
+
else if (u.dataJson) try {
|
|
25902
|
+
let e = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson;
|
|
25903
|
+
e.defaultLanguage && (d = String(e.defaultLanguage).trim());
|
|
25752
25904
|
} catch {}
|
|
25753
25905
|
}
|
|
25754
|
-
let
|
|
25755
|
-
if (!o && !
|
|
25756
|
-
let t = await
|
|
25906
|
+
let f = d || s || a?.trim() || null, p = $b(e), m = `tree:${i}:${n}:${f || "default"}`, h = e.req.header("x-bypass-cache") === "true";
|
|
25907
|
+
if (!o && !h) {
|
|
25908
|
+
let t = await p.get(m);
|
|
25757
25909
|
if (t) return e.header("X-Cache", "HIT"), e.json(t, 200);
|
|
25758
25910
|
}
|
|
25759
|
-
let
|
|
25760
|
-
if (
|
|
25761
|
-
let t = typeof
|
|
25762
|
-
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (
|
|
25911
|
+
let g = u?.id || (l ? Number(n) : null), _ = {};
|
|
25912
|
+
if (u && u.dataJson) try {
|
|
25913
|
+
let t = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson, r = e.env?.BUNDLED_DEFINITIONS, i = dx(r), a = (i.trees?.[u.treeType || n] || i.trees?.site || {}).fields || {};
|
|
25914
|
+
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (_[e] = n);
|
|
25763
25915
|
} catch (e) {
|
|
25764
25916
|
console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
|
|
25765
25917
|
}
|
|
25766
|
-
let
|
|
25767
|
-
if (
|
|
25768
|
-
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(
|
|
25769
|
-
|
|
25770
|
-
}
|
|
25771
|
-
if ((!_ || _.length === 0) && !l) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
25772
|
-
let v = /* @__PURE__ */ new Map();
|
|
25773
|
-
for (let e of _) {
|
|
25774
|
-
let t = !e.parentId || e.parentId === "null" || e.parentId === "" ? null : e.parentId, n = t === null ? "__ROOT__" : String(t), r = v.get(n);
|
|
25775
|
-
r ? r.push(e) : v.set(n, [e]);
|
|
25918
|
+
let v = [];
|
|
25919
|
+
if (g !== null) {
|
|
25920
|
+
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 (\n SELECT path \n FROM node_routes \n WHERE nodeId = c.id AND channelId = ? \n ORDER BY CASE WHEN treeId = t.treeId THEN 0 ELSE 1 END ASC \n LIMIT 1\n ) as materializedPath\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(c, g);
|
|
25921
|
+
v = Array.isArray(e) ? e : e?.results || [];
|
|
25776
25922
|
}
|
|
25923
|
+
if ((!v || v.length === 0) && !u) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
25777
25924
|
let y = /* @__PURE__ */ new Map();
|
|
25778
|
-
for (let e of
|
|
25925
|
+
for (let e of v) {
|
|
25926
|
+
let t = !e.parentId || e.parentId === "null" || e.parentId === "" ? null : e.parentId, n = t === null ? "__ROOT__" : String(t), r = y.get(n);
|
|
25927
|
+
r ? r.push(e) : y.set(n, [e]);
|
|
25928
|
+
}
|
|
25929
|
+
let b = /* @__PURE__ */ new Map();
|
|
25930
|
+
for (let e of v) {
|
|
25779
25931
|
let t = String(e.id), n = o && e.draftDataJson ? e.draftDataJson : e.dataJson;
|
|
25780
25932
|
if (!n) {
|
|
25781
|
-
|
|
25933
|
+
b.set(t, {});
|
|
25782
25934
|
continue;
|
|
25783
25935
|
}
|
|
25784
25936
|
try {
|
|
25785
25937
|
let e = typeof n == "string" ? JSON.parse(n) : n;
|
|
25786
|
-
|
|
25938
|
+
b.set(t, e && typeof e == "object" ? e : {});
|
|
25787
25939
|
} catch {
|
|
25788
|
-
|
|
25940
|
+
b.set(t, {});
|
|
25789
25941
|
}
|
|
25790
25942
|
}
|
|
25791
|
-
function
|
|
25943
|
+
function x(e = null, t = "") {
|
|
25792
25944
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e);
|
|
25793
|
-
return (
|
|
25794
|
-
let n =
|
|
25945
|
+
return (y.get(n) || []).map((e) => {
|
|
25946
|
+
let n = b.get(String(e.id)) || {}, r = {};
|
|
25795
25947
|
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);
|
|
25796
|
-
let i = !o && (e.status === "draft" || e.status === "new"), a = Number(e.isHidden) === 1 || i || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s =
|
|
25948
|
+
let i = !o && (e.status === "draft" || e.status === "new"), a = Number(e.isHidden) === 1 || i || n.hidden === !0 || n.hidden === 1 || n.hidden === "1" || n.hidden === "true", s = ES(n.startShowingAt, n.stopShowingAt), c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = !e.parentId || e.parentId === "null" || e.parentId === "", u = e.materializedPath || (l ? `/${c}` : `${t}/${c}`.replace(/\/+/g, "/")), d = e.language && String(e.language).trim() !== "" ? e.language.trim() : f, p = {
|
|
25797
25949
|
id: e.id,
|
|
25798
25950
|
treeNodeId: e.id,
|
|
25799
25951
|
parentId: e.parentId || null,
|
|
25800
25952
|
title: e.title,
|
|
25801
25953
|
slug: c,
|
|
25802
|
-
language:
|
|
25803
|
-
path:
|
|
25954
|
+
language: d,
|
|
25955
|
+
path: u,
|
|
25804
25956
|
nodeType: e.nodeType,
|
|
25805
25957
|
hidden: a || !s ? 1 : 0,
|
|
25806
25958
|
summary: r.summary || ""
|
|
25807
25959
|
};
|
|
25808
|
-
e.nodeType === "external-link" && (r.url && (
|
|
25809
|
-
let
|
|
25810
|
-
return
|
|
25960
|
+
e.nodeType === "external-link" && (r.url && (p.url = r.url), r.target && (p.target = r.target));
|
|
25961
|
+
let m = u === "/" ? "" : u;
|
|
25962
|
+
return p.children = x(e.id, m), p;
|
|
25811
25963
|
}).filter((e) => o || !e.hidden);
|
|
25812
25964
|
}
|
|
25813
|
-
let
|
|
25814
|
-
treeId:
|
|
25815
|
-
key:
|
|
25965
|
+
let S = {
|
|
25966
|
+
treeId: u?.id || g,
|
|
25967
|
+
key: u?.key || n,
|
|
25816
25968
|
channelId: String(i),
|
|
25817
|
-
language:
|
|
25818
|
-
label:
|
|
25819
|
-
...
|
|
25820
|
-
items:
|
|
25969
|
+
language: f,
|
|
25970
|
+
label: u?.label || n,
|
|
25971
|
+
..._,
|
|
25972
|
+
items: x(null)
|
|
25821
25973
|
};
|
|
25822
|
-
return !o && !
|
|
25974
|
+
return !o && !h && (e.header("X-Cache", "MISS"), await DS(p, m, S, 300)), e.json(S, 200);
|
|
25823
25975
|
} catch (t) {
|
|
25824
25976
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
25825
25977
|
error: "Failed to fetch public tree",
|
|
@@ -25827,19 +25979,19 @@ DS.openapi(FS, async (e) => {
|
|
|
25827
25979
|
}, 500);
|
|
25828
25980
|
}
|
|
25829
25981
|
});
|
|
25830
|
-
var
|
|
25831
|
-
function
|
|
25982
|
+
var PS = new $y();
|
|
25983
|
+
function FS(e) {
|
|
25832
25984
|
let t = Number(e?.env?.CMS_CHANNEL_CACHE_TTL);
|
|
25833
25985
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
25834
25986
|
}
|
|
25835
|
-
async function
|
|
25987
|
+
async function IS(e, t, n, r) {
|
|
25836
25988
|
try {
|
|
25837
25989
|
await e.set(t, n, r);
|
|
25838
25990
|
} catch (e) {
|
|
25839
25991
|
console.warn("[CMS Cache] Failed to write channel response to cache:", e);
|
|
25840
25992
|
}
|
|
25841
25993
|
}
|
|
25842
|
-
function
|
|
25994
|
+
function LS(e, t) {
|
|
25843
25995
|
let n = {}, r = (e) => {
|
|
25844
25996
|
if (!e || typeof e != "string") return;
|
|
25845
25997
|
let n = t?.fieldSets?.[e] || t?.fieldsets?.[e] || t?.definitions?.[e] || t?.channels?.[e] || t?.[e];
|
|
@@ -25850,7 +26002,7 @@ function zS(e, t) {
|
|
|
25850
26002
|
if (e?.fieldSets && Array.isArray(e.fieldSets) && e.fieldSets.forEach((e) => r(e)), e?.fields && i(e.fields), e?.tabs && typeof e.tabs == "object") for (let t of Object.values(e.tabs)) t?.fields && i(t.fields);
|
|
25851
26003
|
return n;
|
|
25852
26004
|
}
|
|
25853
|
-
function
|
|
26005
|
+
function RS(e, t = {}) {
|
|
25854
26006
|
let n = {}, r = Object.keys(t).length > 0;
|
|
25855
26007
|
for (let [i, a] of Object.entries(e)) {
|
|
25856
26008
|
if (i.endsWith("_meta") || [
|
|
@@ -25869,14 +26021,14 @@ function BS(e, t = {}) {
|
|
|
25869
26021
|
}
|
|
25870
26022
|
return n;
|
|
25871
26023
|
}
|
|
25872
|
-
function
|
|
25873
|
-
if (Array.isArray(e)) return e.map(
|
|
26024
|
+
function zS(e) {
|
|
26025
|
+
if (Array.isArray(e)) return e.map(zS);
|
|
25874
26026
|
if (!e || typeof e != "object") return e;
|
|
25875
26027
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
25876
26028
|
let t = e.metadataOverrides || {}, n = e.variants && typeof e.variants == "object" ? e.variants : {}, r = Object.entries(n).find(([, t]) => t?.id === e.id)?.[0], i = r ? {
|
|
25877
26029
|
...t,
|
|
25878
26030
|
...t.crops?.[r] || {}
|
|
25879
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
26031
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, zS({
|
|
25880
26032
|
...n,
|
|
25881
26033
|
title: n?.title ?? e.title ?? "",
|
|
25882
26034
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -25890,77 +26042,80 @@ function VS(e) {
|
|
|
25890
26042
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
25891
26043
|
};
|
|
25892
26044
|
}
|
|
25893
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
26045
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, zS(t)]));
|
|
25894
26046
|
}
|
|
25895
|
-
async function
|
|
26047
|
+
async function BS(e, t, n) {
|
|
25896
26048
|
if (typeof t == "string") {
|
|
25897
26049
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
25898
|
-
let
|
|
25899
|
-
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi))
|
|
25900
|
-
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi))
|
|
25901
|
-
if (
|
|
25902
|
-
let
|
|
25903
|
-
|
|
25904
|
-
|
|
25905
|
-
|
|
26050
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
|
|
26051
|
+
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi)) r.add(e[1]);
|
|
26052
|
+
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi)) i.add(e[1]);
|
|
26053
|
+
if (r.size === 0 && i.size === 0) return t;
|
|
26054
|
+
let a = /* @__PURE__ */ new Map();
|
|
26055
|
+
if (r.size > 0) {
|
|
26056
|
+
let t = Array.from(r).map(() => "?").join(","), i = await e.prepare(`SELECT nodeId, path FROM node_routes WHERE channelId = ? AND nodeId IN (${t}) AND isCanonical = 1`).all(n, ...r);
|
|
26057
|
+
(Array.isArray(i) ? i : i?.results || []).forEach((e) => a.set(String(e.nodeId), e.path));
|
|
26058
|
+
}
|
|
26059
|
+
let o = Array.from(i).map(() => "?").join(","), s = i.size > 0 ? await e.prepare(`SELECT id, cdnUrl, storageKeyPrivate FROM assets WHERE id IN (${o})`).all(...i) : [], c = /* @__PURE__ */ new Map();
|
|
26060
|
+
return (Array.isArray(s) ? s : s?.results || []).forEach((e) => c.set(String(e.id), e.cdnUrl || (e.storageKeyPrivate ? `/media/${e.storageKeyPrivate}` : ""))), t.replace(/<a\s+([^>]+)>/gi, (e, t) => {
|
|
25906
26061
|
let n = (e, t) => {
|
|
25907
26062
|
let n = e.match(RegExp(`\\b${t}\\s*=\\s*(["'])(.*?)\\1`, "i"));
|
|
25908
26063
|
return n ? n[2] : void 0;
|
|
25909
|
-
}, r = n(t, "data-node-id"), i = n(t, "data-asset-id"),
|
|
25910
|
-
if (
|
|
25911
|
-
let s = i ||
|
|
25912
|
-
if (!
|
|
25913
|
-
if (s && !
|
|
25914
|
-
let n =
|
|
26064
|
+
}, r = n(t, "data-node-id"), i = n(t, "data-asset-id"), o = n(t, "href") || "";
|
|
26065
|
+
if (o.startsWith("mailto:")) return `<a ${t.replace(/\s+target\s*=\s*["'][^"']*["']/i, "")}>`;
|
|
26066
|
+
let s = i || o.match(/^#asset:(.+)$/i)?.[1], l = r || o.match(/^#node:(.+)$/i)?.[1];
|
|
26067
|
+
if (!l && !s) return e;
|
|
26068
|
+
if (s && !l) {
|
|
26069
|
+
let n = c.get(s);
|
|
25915
26070
|
if (n) {
|
|
25916
26071
|
let e = t;
|
|
25917
26072
|
return /href\s*=\s*["'][^"']*["']/i.test(e) ? e = e.replace(/href\s*=\s*["'][^"']*["']/i, `href="${n}"`) : e += ` href="${n}"`, `<a ${e}>`;
|
|
25918
26073
|
}
|
|
25919
26074
|
return e;
|
|
25920
26075
|
}
|
|
25921
|
-
let u =
|
|
25922
|
-
return /href\s*=\s*["'][^"']*["']/i.test(
|
|
26076
|
+
let u = a.get(l) || "#", d = t;
|
|
26077
|
+
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
25923
26078
|
});
|
|
25924
26079
|
}
|
|
25925
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
26080
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => BS(e, t, n)));
|
|
25926
26081
|
if (t && typeof t == "object") {
|
|
25927
|
-
let
|
|
25928
|
-
return Object.fromEntries(
|
|
26082
|
+
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await BS(e, r, n)]));
|
|
26083
|
+
return Object.fromEntries(r);
|
|
25929
26084
|
}
|
|
25930
26085
|
return t;
|
|
25931
26086
|
}
|
|
25932
|
-
var
|
|
26087
|
+
var VS = X({ channelParam: J().openapi({ description: "The ID or key (slug) of the requested channel" }) }), HS = X({ preview: lv(["true", "false"]).optional().openapi({ description: "Set to true to retrieve unpublished draft data" }) }), US = X({
|
|
25933
26088
|
error: J(),
|
|
25934
26089
|
details: J().optional()
|
|
25935
|
-
}).openapi("ErrorResponse"),
|
|
26090
|
+
}).openapi("ErrorResponse"), WS = X({
|
|
25936
26091
|
id: G_([c_(), J()]),
|
|
25937
26092
|
key: J()
|
|
25938
|
-
}).catchall(k_()).openapi("ChannelResponse"),
|
|
26093
|
+
}).catchall(k_()).openapi("ChannelResponse"), GS = eb({
|
|
25939
26094
|
method: "get",
|
|
25940
26095
|
path: "/{channelParam}",
|
|
25941
26096
|
summary: "Fetch CMS Channel Settings",
|
|
25942
26097
|
description: "Retrieves the fully hydrated, public-facing settings and payload for a specific CMS channel.",
|
|
25943
26098
|
tags: ["Public Channel API"],
|
|
25944
26099
|
request: {
|
|
25945
|
-
params:
|
|
25946
|
-
query:
|
|
26100
|
+
params: VS,
|
|
26101
|
+
query: HS
|
|
25947
26102
|
},
|
|
25948
26103
|
responses: {
|
|
25949
26104
|
200: {
|
|
25950
26105
|
description: "Fully hydrated CMS Channel payload",
|
|
25951
|
-
content: { "application/json": { schema:
|
|
26106
|
+
content: { "application/json": { schema: WS } }
|
|
25952
26107
|
},
|
|
25953
26108
|
404: {
|
|
25954
26109
|
description: "Channel not found or inactive",
|
|
25955
|
-
content: { "application/json": { schema:
|
|
26110
|
+
content: { "application/json": { schema: US } }
|
|
25956
26111
|
},
|
|
25957
26112
|
500: {
|
|
25958
26113
|
description: "Server error during hydration",
|
|
25959
|
-
content: { "application/json": { schema:
|
|
26114
|
+
content: { "application/json": { schema: US } }
|
|
25960
26115
|
}
|
|
25961
26116
|
}
|
|
25962
26117
|
});
|
|
25963
|
-
|
|
26118
|
+
PS.openapi(GS, async (e) => {
|
|
25964
26119
|
try {
|
|
25965
26120
|
let t = e.get("db"), { channelParam: n } = e.req.valid("param"), { preview: r } = e.req.valid("query"), i = r === "true", a = e.req.header("x-bypass-cache") === "true", o = `channel:${n}:${i ? "preview" : "live"}`, s = $b(e);
|
|
25966
26121
|
if (!i && !a) {
|
|
@@ -25971,23 +26126,23 @@ IS.openapi(qS, async (e) => {
|
|
|
25971
26126
|
if (!c) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
25972
26127
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
25973
26128
|
if (!i && l) return e.json({ error: `Channel '${c.key || n}' is currently inactive` }, 404);
|
|
25974
|
-
let u = e.env?.BUNDLED_DEFINITIONS,
|
|
25975
|
-
if (
|
|
25976
|
-
|
|
26129
|
+
let u = Number(c.id), d = e.env?.BUNDLED_DEFINITIONS, f = dx(d), p = c.channelType || c.key || "website", m = LS(f.channels?.[p] || f.channels?.[c.key] || f.channels?.website || f.definitions?.["channel-base"] || {}, f), h = {}, g = i && c.draftDataJson || c.dataJson;
|
|
26130
|
+
if (g) try {
|
|
26131
|
+
h = typeof g == "string" ? JSON.parse(g) : g;
|
|
25977
26132
|
} catch (e) {
|
|
25978
26133
|
console.warn("[CMS Public Channel API] Failed to parse channel dataJson:", e);
|
|
25979
26134
|
}
|
|
25980
|
-
let
|
|
25981
|
-
...
|
|
26135
|
+
let _ = RS({
|
|
26136
|
+
...h,
|
|
25982
26137
|
...c
|
|
25983
|
-
},
|
|
25984
|
-
|
|
25985
|
-
let
|
|
26138
|
+
}, m);
|
|
26139
|
+
_ = await ux(t, _), _ = zS(_), _ = await BS(t, _, u);
|
|
26140
|
+
let v = {
|
|
25986
26141
|
id: c.id,
|
|
25987
26142
|
key: c.key,
|
|
25988
|
-
...
|
|
26143
|
+
..._
|
|
25989
26144
|
};
|
|
25990
|
-
return !i && !a && (e.header("X-Cache", "MISS"), await
|
|
26145
|
+
return !i && !a && (e.header("X-Cache", "MISS"), await IS(s, o, v, FS(e))), e.json(v, 200);
|
|
25991
26146
|
} catch (t) {
|
|
25992
26147
|
return console.error("[CMS Public Channel API] Error:", t), e.json({
|
|
25993
26148
|
error: "Failed to fetch public channel",
|
|
@@ -25995,8 +26150,8 @@ IS.openapi(qS, async (e) => {
|
|
|
25995
26150
|
}, 500);
|
|
25996
26151
|
}
|
|
25997
26152
|
});
|
|
25998
|
-
var
|
|
25999
|
-
function
|
|
26153
|
+
var KS = new $y();
|
|
26154
|
+
function qS(e, t) {
|
|
26000
26155
|
if (t === "webp") return "image/webp";
|
|
26001
26156
|
if (t === "avif") return "image/avif";
|
|
26002
26157
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -26005,7 +26160,7 @@ function YS(e, t) {
|
|
|
26005
26160
|
let n = e.toLowerCase();
|
|
26006
26161
|
return n.endsWith(".jpg") || n.endsWith(".jpeg") ? "image/jpeg" : n.endsWith(".png") ? "image/png" : n.endsWith(".webp") ? "image/webp" : n.endsWith(".gif") ? "image/gif" : n.endsWith(".svg") ? "image/svg+xml" : n.endsWith(".pdf") ? "application/pdf" : n.endsWith(".mp4") ? "video/mp4" : "application/octet-stream";
|
|
26007
26162
|
}
|
|
26008
|
-
var
|
|
26163
|
+
var JS = eb({
|
|
26009
26164
|
method: "get",
|
|
26010
26165
|
path: "/*",
|
|
26011
26166
|
summary: "Serve & Optimize Media Assets",
|
|
@@ -26062,7 +26217,7 @@ var XS = eb({
|
|
|
26062
26217
|
}
|
|
26063
26218
|
}
|
|
26064
26219
|
});
|
|
26065
|
-
|
|
26220
|
+
KS.openapi(JS, async (e) => {
|
|
26066
26221
|
try {
|
|
26067
26222
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
26068
26223
|
if (!t) return e.text("Asset key missing", 400);
|
|
@@ -26082,7 +26237,7 @@ JS.openapi(XS, async (e) => {
|
|
|
26082
26237
|
if (!m) return e.text(`Asset not found: ${t}`, 404);
|
|
26083
26238
|
if (!o) {
|
|
26084
26239
|
let n = e.body(m, 200, {
|
|
26085
|
-
"Content-Type":
|
|
26240
|
+
"Content-Type": qS(t),
|
|
26086
26241
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
26087
26242
|
});
|
|
26088
26243
|
return l && d && e.executionCtx?.waitUntil && e.executionCtx.waitUntil(l.put(d, n.clone())), n;
|
|
@@ -26096,7 +26251,7 @@ JS.openapi(XS, async (e) => {
|
|
|
26096
26251
|
key: t,
|
|
26097
26252
|
env: e.env,
|
|
26098
26253
|
req: e.req.raw
|
|
26099
|
-
}), _ =
|
|
26254
|
+
}), _ = qS(t, c), v = e.body(g, 200, {
|
|
26100
26255
|
"Content-Type": _,
|
|
26101
26256
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
26102
26257
|
});
|
|
@@ -26105,8 +26260,8 @@ JS.openapi(XS, async (e) => {
|
|
|
26105
26260
|
return console.error("❌ [Public Assets Error]:", t), e.text("Internal Server Error", 500);
|
|
26106
26261
|
}
|
|
26107
26262
|
});
|
|
26108
|
-
var
|
|
26109
|
-
function
|
|
26263
|
+
var YS = new $y();
|
|
26264
|
+
function XS(e, t) {
|
|
26110
26265
|
let n = /* @__PURE__ */ new Date();
|
|
26111
26266
|
if (e && String(e).trim() !== "") {
|
|
26112
26267
|
let t = new Date(e);
|
|
@@ -26118,71 +26273,71 @@ function QS(e, t) {
|
|
|
26118
26273
|
}
|
|
26119
26274
|
return !0;
|
|
26120
26275
|
}
|
|
26121
|
-
var
|
|
26276
|
+
var ZS = X({
|
|
26277
|
+
channelId: J().optional().openapi({ description: "Optional channel ID/key to filter and resolve root paths for" }),
|
|
26278
|
+
channel: J().optional().openapi({ description: "Legacy alias for channelId" })
|
|
26279
|
+
}), QS = z_(J()).openapi("PathsResponse"), $S = X({
|
|
26122
26280
|
error: J(),
|
|
26123
26281
|
details: J().optional()
|
|
26124
|
-
}).openapi("ErrorResponse"),
|
|
26282
|
+
}).openapi("ErrorResponse"), eC = eb({
|
|
26125
26283
|
method: "get",
|
|
26126
26284
|
path: "/",
|
|
26127
26285
|
summary: "Fetch All Public Paths",
|
|
26128
|
-
description: "Retrieves a deduplicated array of all active, published node paths
|
|
26286
|
+
description: "Retrieves a deduplicated array of all active, published node paths leveraging the $O(1)$ node_routes table. Includes both tree-bound and standalone pages.",
|
|
26129
26287
|
tags: ["Public Paths API"],
|
|
26288
|
+
request: { query: ZS },
|
|
26130
26289
|
responses: {
|
|
26131
26290
|
200: {
|
|
26132
26291
|
description: "Array of valid public URL paths",
|
|
26133
|
-
content: { "application/json": { schema:
|
|
26292
|
+
content: { "application/json": { schema: QS } }
|
|
26134
26293
|
},
|
|
26135
26294
|
500: {
|
|
26136
26295
|
description: "Server error fetching paths",
|
|
26137
|
-
content: { "application/json": { schema:
|
|
26296
|
+
content: { "application/json": { schema: $S } }
|
|
26138
26297
|
}
|
|
26139
26298
|
}
|
|
26140
26299
|
});
|
|
26141
|
-
|
|
26300
|
+
YS.openapi(eC, async (e) => {
|
|
26142
26301
|
try {
|
|
26143
|
-
let t =
|
|
26144
|
-
|
|
26145
|
-
let
|
|
26146
|
-
|
|
26147
|
-
}
|
|
26148
|
-
let
|
|
26149
|
-
|
|
26150
|
-
|
|
26151
|
-
|
|
26152
|
-
|
|
26153
|
-
|
|
26154
|
-
|
|
26155
|
-
|
|
26302
|
+
let t = e.get("db"), n = e.req.valid("query"), r = n.channelId || n.channel, i = "", a = [];
|
|
26303
|
+
if (r && r !== "all") {
|
|
26304
|
+
let e = isNaN(Number(r)) ? await t.prepare("SELECT id FROM channels WHERE key = ?").get(r) : await t.prepare("SELECT id FROM channels WHERE id = ?").get(Number(r));
|
|
26305
|
+
e && (i = "AND nr.channelId = ?", a.push(Number(e.id)));
|
|
26306
|
+
}
|
|
26307
|
+
let o = await t.prepare(`
|
|
26308
|
+
SELECT
|
|
26309
|
+
nr.path,
|
|
26310
|
+
cn.contentType as nodeType,
|
|
26311
|
+
cn.dataJson
|
|
26312
|
+
FROM node_routes nr
|
|
26313
|
+
INNER JOIN content_nodes cn ON nr.nodeId = cn.id
|
|
26314
|
+
WHERE nr.isCanonical = 1
|
|
26315
|
+
AND (cn.status = 'published' OR cn.status = 'active')
|
|
26316
|
+
AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
26317
|
+
${i}
|
|
26318
|
+
ORDER BY nr.path ASC
|
|
26319
|
+
`).all(...a), s = Array.isArray(o) ? o : o?.results || [], c = [];
|
|
26320
|
+
for (let e of s) {
|
|
26321
|
+
if (e.nodeType === "external-link" || !e.path) continue;
|
|
26322
|
+
let t = !0;
|
|
26323
|
+
if (e.dataJson) try {
|
|
26156
26324
|
let n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
26157
|
-
|
|
26158
|
-
} catch {
|
|
26159
|
-
|
|
26160
|
-
}
|
|
26161
|
-
}
|
|
26162
|
-
function o(e = null, t = "") {
|
|
26163
|
-
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
|
|
26164
|
-
for (let e of s) {
|
|
26165
|
-
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = QS(n.startShowingAt, n.stopShowingAt);
|
|
26166
|
-
if (!i || !s) continue;
|
|
26167
|
-
let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
|
|
26168
|
-
e.nodeType !== "external-link" && r.push(l);
|
|
26169
|
-
let u = l === "/" ? "" : l;
|
|
26170
|
-
o(e.treeNodeId, u);
|
|
26171
|
-
}
|
|
26325
|
+
t = XS(n?.startShowingAt, n?.stopShowingAt);
|
|
26326
|
+
} catch {}
|
|
26327
|
+
t && c.push(e.path);
|
|
26172
26328
|
}
|
|
26173
|
-
|
|
26174
|
-
|
|
26175
|
-
return e.json(s, 200);
|
|
26329
|
+
let l = [...new Set(c)];
|
|
26330
|
+
return e.json(l, 200);
|
|
26176
26331
|
} catch (t) {
|
|
26177
26332
|
return console.error("[CMS Paths API] Error:", t), e.json({ error: "Failed to fetch paths" }, 500);
|
|
26178
26333
|
}
|
|
26179
26334
|
});
|
|
26180
|
-
var
|
|
26181
|
-
function
|
|
26335
|
+
var tC = new $y();
|
|
26336
|
+
function nC(e) {
|
|
26182
26337
|
let t = (e || "").trim().toLowerCase(), n = dx()?.taxonomies || {};
|
|
26183
26338
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
26184
26339
|
}
|
|
26185
|
-
var
|
|
26340
|
+
var rC = X({
|
|
26186
26341
|
id: c_(),
|
|
26187
26342
|
taxonomy: J(),
|
|
26188
26343
|
key: J(),
|
|
@@ -26192,14 +26347,14 @@ var iC = X({
|
|
|
26192
26347
|
data: tv(k_()),
|
|
26193
26348
|
createdAt: J(),
|
|
26194
26349
|
updatedAt: J()
|
|
26195
|
-
}),
|
|
26350
|
+
}), iC = X({
|
|
26196
26351
|
taxonomy: J(),
|
|
26197
|
-
items: z_(
|
|
26352
|
+
items: z_(rC),
|
|
26198
26353
|
total: c_()
|
|
26199
|
-
}).openapi("TaxonomyResponse"),
|
|
26354
|
+
}).openapi("TaxonomyResponse"), aC = X({
|
|
26200
26355
|
error: J(),
|
|
26201
26356
|
details: J().optional()
|
|
26202
|
-
}).openapi("ErrorResponse"),
|
|
26357
|
+
}).openapi("ErrorResponse"), oC = eb({
|
|
26203
26358
|
method: "get",
|
|
26204
26359
|
path: "/{taxonomy}",
|
|
26205
26360
|
summary: "Fetch Public Taxonomy Terms",
|
|
@@ -26209,17 +26364,17 @@ var iC = X({
|
|
|
26209
26364
|
responses: {
|
|
26210
26365
|
200: {
|
|
26211
26366
|
description: "List of taxonomy terms",
|
|
26212
|
-
content: { "application/json": { schema:
|
|
26367
|
+
content: { "application/json": { schema: iC } }
|
|
26213
26368
|
},
|
|
26214
26369
|
500: {
|
|
26215
26370
|
description: "Server error",
|
|
26216
|
-
content: { "application/json": { schema:
|
|
26371
|
+
content: { "application/json": { schema: aC } }
|
|
26217
26372
|
}
|
|
26218
26373
|
}
|
|
26219
26374
|
});
|
|
26220
|
-
|
|
26375
|
+
tC.openapi(oC, async (e) => {
|
|
26221
26376
|
try {
|
|
26222
|
-
let t = e.get("db"), n = $b(e), r = e.req.valid("param").taxonomy, i =
|
|
26377
|
+
let t = e.get("db"), n = $b(e), r = e.req.valid("param").taxonomy, i = nC(r), a = `taxonomy:public:${i}`, o = e.req.header("x-bypass-cache") === "true";
|
|
26223
26378
|
if (!o) {
|
|
26224
26379
|
let t = await n.get(a);
|
|
26225
26380
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
@@ -26253,7 +26408,7 @@ nC.openapi(sC, async (e) => {
|
|
|
26253
26408
|
return console.error("[Public Taxonomy API] Error fetching terms:", t), e.json({ error: "Failed to fetch taxonomy terms" }, 500);
|
|
26254
26409
|
}
|
|
26255
26410
|
});
|
|
26256
|
-
var $ = new $y(),
|
|
26411
|
+
var $ = new $y(), sC = !1;
|
|
26257
26412
|
$.use("*", t()), $.use("/media/*", t({
|
|
26258
26413
|
origin: "*",
|
|
26259
26414
|
allowMethods: [
|
|
@@ -26274,13 +26429,13 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
26274
26429
|
let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
|
|
26275
26430
|
e.set("currentDomain", r);
|
|
26276
26431
|
let i = wb(e);
|
|
26277
|
-
if (e.set("db", i), !
|
|
26278
|
-
await Mb(i),
|
|
26432
|
+
if (e.set("db", i), !sC) try {
|
|
26433
|
+
await Mb(i), sC = !0;
|
|
26279
26434
|
} catch (e) {
|
|
26280
26435
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
26281
26436
|
}
|
|
26282
26437
|
await t();
|
|
26283
|
-
}), $.route("/media",
|
|
26438
|
+
}), $.route("/media", KS), $.use("/media/*", Pb()), $.route("/api/cms/nodes", mx), $.route("/api/cms/nodes.json", mx), $.route("/api/cms/formcsv", mx), $.route("/api/cms/formcsv.json", mx), $.route("/api/cms/stats", tS), $.route("/api/cms/stats.json", tS), $.route("/api/cms", Tx), $.route("/api/cms/trees.json", Tx), $.route("/api/cms/channels", kx), $.route("/api/cms/channels.json", kx), $.route("/api/cms/taxonomies", Ax), $.route("/api/cms/taxonomies.json", Ax), $.route("/api/cms/schemas", Xx), $.route("/api/cms/schemas.json", Xx), $.route("/api/cms", Qx), $.route("/api/admin/assets", nS), $.route("/api/v1/node", oS), $.route("/api/v1/tree", TS), $.route("/api/v1/channel", PS), $.route("/api/v1/all-paths", YS), $.route("/api/v1/taxonomies", tC), $.doc("/api/openapi.json", {
|
|
26284
26439
|
openapi: "3.0.0",
|
|
26285
26440
|
info: {
|
|
26286
26441
|
title: "KAMA Engine Public API",
|
|
@@ -26299,4 +26454,4 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
26299
26454
|
return t();
|
|
26300
26455
|
});
|
|
26301
26456
|
//#endregion
|
|
26302
|
-
export {
|
|
26457
|
+
export { qx as compileDefinitions };
|