@brightsideoy/kama 1.0.0-alpha.2 → 1.0.0-alpha.4
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-CiW_gEtr.js +164 -0
- package/dist/assets/index-DHKk9t5r.css +1 -0
- package/dist/{dist-Dy7-HUEG.js → dist-rKCoLpZH.js} +958 -788
- package/dist/index.html +2 -2
- package/dist/index.js +1000 -826
- 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/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
package/dist/index.js
CHANGED
|
@@ -185,13 +185,13 @@ function C(e) {
|
|
|
185
185
|
let t = new g();
|
|
186
186
|
return e.forEach((e) => t.put(e)), [...t.values()];
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function ee(e) {
|
|
189
189
|
return typeof e == "string";
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function w(e) {
|
|
192
192
|
return Object.fromEntries(Object.entries(e).sort(([e], [t]) => e.localeCompare(t)));
|
|
193
193
|
}
|
|
194
|
-
var
|
|
194
|
+
var T = m(), E = class {
|
|
195
195
|
static collectMetadata(e, t) {
|
|
196
196
|
let n = this.getMetadataFromRegistry(e), r = Object.assign(Object.assign({}, n?._internal), t?._internal), i = Object.assign(Object.assign({}, n?.param), t?.param), a = Object.assign(Object.assign(Object.assign(Object.assign({}, Object.keys(r).length > 0 ? { _internal: r } : {}), n), t), Object.keys(i).length > 0 ? { param: i } : {});
|
|
197
197
|
if (l(e, [
|
|
@@ -259,7 +259,7 @@ var ee = m(), E = class {
|
|
|
259
259
|
return t ? void 0 : e;
|
|
260
260
|
}
|
|
261
261
|
static getMetadataFromInternalRegistry(e) {
|
|
262
|
-
return
|
|
262
|
+
return T.get(e);
|
|
263
263
|
}
|
|
264
264
|
static getMetadataFromRegistry(e) {
|
|
265
265
|
let t = this.getMetadataFromInternalRegistry(e), n = e.meta();
|
|
@@ -268,7 +268,7 @@ var ee = m(), E = class {
|
|
|
268
268
|
return Object.assign(Object.assign(Object.assign({ _internal: Object.assign(Object.assign({}, o ? { refId: o } : {}), r) }, i), c ? { description: c } : {}), l);
|
|
269
269
|
}
|
|
270
270
|
static setMetadataInRegistry(e, t) {
|
|
271
|
-
|
|
271
|
+
T.add(e, t);
|
|
272
272
|
}
|
|
273
273
|
};
|
|
274
274
|
function D(e, t) {
|
|
@@ -280,7 +280,7 @@ function D(e, t) {
|
|
|
280
280
|
}
|
|
281
281
|
function te(e) {
|
|
282
282
|
e.ZodType.prototype.openapi === void 0 && (e.ZodType.prototype.openapi = function(...e) {
|
|
283
|
-
let { refId: t, metadata: n, options: r } =
|
|
283
|
+
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);
|
|
284
284
|
function h(e) {
|
|
285
285
|
E.setMetadataInRegistry(e, Object.assign(Object.assign({}, Object.keys(f).length > 0 ? { _internal: f } : void 0), p));
|
|
286
286
|
}
|
|
@@ -306,7 +306,7 @@ function te(e) {
|
|
|
306
306
|
}, m;
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function ne(e, t, n) {
|
|
310
310
|
return typeof e == "string" ? {
|
|
311
311
|
refId: e,
|
|
312
312
|
metadata: t,
|
|
@@ -317,10 +317,10 @@ function O(e, t, n) {
|
|
|
317
317
|
options: t
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function O(e) {
|
|
321
321
|
return b(E.getOpenApiMetadata(e) ?? {}, _);
|
|
322
322
|
}
|
|
323
|
-
var
|
|
323
|
+
var k = class {
|
|
324
324
|
constructor(e) {
|
|
325
325
|
this.parents = e, this._definitions = [];
|
|
326
326
|
}
|
|
@@ -367,31 +367,31 @@ var A = class {
|
|
|
367
367
|
schemaWithRefId(e, t) {
|
|
368
368
|
return t.openapi(e);
|
|
369
369
|
}
|
|
370
|
-
},
|
|
370
|
+
}, A = class {
|
|
371
371
|
constructor(e) {
|
|
372
372
|
this.message = e;
|
|
373
373
|
}
|
|
374
|
-
},
|
|
374
|
+
}, re = class extends A {
|
|
375
375
|
constructor(e, t) {
|
|
376
376
|
super(e), this.data = t;
|
|
377
377
|
}
|
|
378
|
-
},
|
|
378
|
+
}, ie = class extends A {
|
|
379
379
|
constructor(e) {
|
|
380
380
|
super(`Missing parameter data, please specify \`${e.missingField}\` and other OpenAPI parameter props using the \`param\` field of \`schema.openapi\``), this.data = e;
|
|
381
381
|
}
|
|
382
382
|
};
|
|
383
|
-
function
|
|
383
|
+
function ae(e, t) {
|
|
384
384
|
try {
|
|
385
385
|
return e();
|
|
386
386
|
} catch (e) {
|
|
387
|
-
throw e instanceof
|
|
387
|
+
throw e instanceof ie ? new ie(Object.assign(Object.assign({}, e.data), t)) : e;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
var
|
|
390
|
+
var oe = class extends A {
|
|
391
391
|
constructor(e) {
|
|
392
392
|
super("Unknown zod object type, please specify `type` and other OpenAPI props using `schema.openapi`."), this.data = e;
|
|
393
393
|
}
|
|
394
|
-
},
|
|
394
|
+
}, se = class {
|
|
395
395
|
transform(e, t, n) {
|
|
396
396
|
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;
|
|
397
397
|
return Object.assign(Object.assign({}, t("array")), {
|
|
@@ -400,11 +400,11 @@ var ae = class extends j {
|
|
|
400
400
|
maxItems: a
|
|
401
401
|
});
|
|
402
402
|
}
|
|
403
|
-
},
|
|
403
|
+
}, ce = class {
|
|
404
404
|
transform(e) {
|
|
405
405
|
return Object.assign(Object.assign({}, e("string")), { pattern: "^\\d+$" });
|
|
406
406
|
}
|
|
407
|
-
},
|
|
407
|
+
}, le = class {
|
|
408
408
|
transform(e, t, n, r, i) {
|
|
409
409
|
let a = e.def.options.filter(u), o = a.map(r);
|
|
410
410
|
if (t) return { oneOf: n(o, t) };
|
|
@@ -429,7 +429,7 @@ var ae = class extends j {
|
|
|
429
429
|
getDiscriminatorValues(e, t) {
|
|
430
430
|
if (l(e, "ZodObject")) {
|
|
431
431
|
let n = e.def.shape?.[t];
|
|
432
|
-
return n ? l(n, "ZodEnum") ? Object.values(n._zod.def.entries).filter(
|
|
432
|
+
return n ? l(n, "ZodEnum") ? Object.values(n._zod.def.entries).filter(ee) : l(n, "ZodLiteral") ? n.def.values.filter(ee) : [] : [];
|
|
433
433
|
}
|
|
434
434
|
if (l(e, "ZodDiscriminatedUnion")) {
|
|
435
435
|
let n = e.def.options.filter(u);
|
|
@@ -438,7 +438,7 @@ var ae = class extends j {
|
|
|
438
438
|
return [];
|
|
439
439
|
}
|
|
440
440
|
};
|
|
441
|
-
function
|
|
441
|
+
function j(e) {
|
|
442
442
|
let t = Object.keys(e).filter((t) => typeof e[e[t]] != "number").map((t) => e[t]), n = t.filter((e) => typeof e == "number").length;
|
|
443
443
|
return {
|
|
444
444
|
values: t,
|
|
@@ -447,8 +447,8 @@ function le(e) {
|
|
|
447
447
|
}
|
|
448
448
|
var ue = class {
|
|
449
449
|
transform(e, t, n) {
|
|
450
|
-
let { type: r, values: i } =
|
|
451
|
-
if (r === "mixed") throw new
|
|
450
|
+
let { type: r, values: i } = j(e._zod.def.entries);
|
|
451
|
+
if (r === "mixed") throw new A("Enum has mixed string and number values, please specify the OpenAPI type manually");
|
|
452
452
|
return Object.assign(Object.assign({}, n(r === "numeric" ? "integer" : "string")), { enum: t ? [...i, null] : i });
|
|
453
453
|
}
|
|
454
454
|
}, de = class {
|
|
@@ -463,7 +463,7 @@ var ue = class {
|
|
|
463
463
|
}
|
|
464
464
|
}, fe = class {
|
|
465
465
|
constructor() {
|
|
466
|
-
this.bigIntTransformer = new
|
|
466
|
+
this.bigIntTransformer = new ce();
|
|
467
467
|
}
|
|
468
468
|
transform(e, t) {
|
|
469
469
|
let n = typeof e.def.values[0];
|
|
@@ -499,7 +499,7 @@ var ue = class {
|
|
|
499
499
|
transform(e, t, n) {
|
|
500
500
|
let r = e.valueType, i = e.keyType, a = u(r) ? n(r) : {};
|
|
501
501
|
if (l(i, "ZodEnum")) {
|
|
502
|
-
let e = Object.values(i._zod.def.entries).filter(
|
|
502
|
+
let e = Object.values(i._zod.def.entries).filter(ee).reduce((e, t) => Object.assign(Object.assign({}, e), { [t]: a }), {});
|
|
503
503
|
return Object.assign(Object.assign({}, t("object")), { properties: e });
|
|
504
504
|
}
|
|
505
505
|
return Object.assign(Object.assign({}, t("object")), { additionalProperties: a });
|
|
@@ -590,7 +590,7 @@ var ve = class {
|
|
|
590
590
|
if (l(e, "ZodNumber")) return "[+-]?\\d+(\\.\\d+)?";
|
|
591
591
|
if (l(e, "ZodBoolean")) return "(true|false)";
|
|
592
592
|
if (l(e, "ZodEnum")) {
|
|
593
|
-
let { values: t } =
|
|
593
|
+
let { values: t } = j(e.def.entries);
|
|
594
594
|
return `(${t.map((e) => this.escapeRegex(String(e))).join("|")})`;
|
|
595
595
|
}
|
|
596
596
|
return ".*";
|
|
@@ -600,7 +600,7 @@ var ve = class {
|
|
|
600
600
|
}
|
|
601
601
|
}, we = class {
|
|
602
602
|
constructor(e, t) {
|
|
603
|
-
this.versionSpecifics = e, this.objectTransformer = new me(), this.stringTransformer = new ve(), this.numberTransformer = new pe(), this.bigIntTransformer = new
|
|
603
|
+
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);
|
|
604
604
|
}
|
|
605
605
|
transform(e, t, n, r, i) {
|
|
606
606
|
if (l(e, "ZodNull")) return this.versionSpecifics.nullType;
|
|
@@ -627,7 +627,7 @@ var ve = class {
|
|
|
627
627
|
if (l(e, "ZodRecord")) return this.recordTransformer.transform(e, (e) => this.versionSpecifics.mapNullableType(e, t), n);
|
|
628
628
|
if (l(e, "ZodDate")) return this.dateTransformer.transform((e) => this.versionSpecifics.mapNullableType(e, t));
|
|
629
629
|
let i = E.getRefId(e);
|
|
630
|
-
throw new
|
|
630
|
+
throw new oe({
|
|
631
631
|
currentSchema: e.def,
|
|
632
632
|
schemaName: i
|
|
633
633
|
});
|
|
@@ -650,7 +650,7 @@ var ve = class {
|
|
|
650
650
|
this.rawComponents.forEach(({ componentType: t, name: n, component: r }) => {
|
|
651
651
|
e[t] ?? (e[t] = {}), e[t][n] = r;
|
|
652
652
|
});
|
|
653
|
-
let t = e.schemas ?? {}, n = Object.assign(Object.assign({}, t), this.filteredSchemaRefs), r = this.options?.sortComponents === "alphabetically" ?
|
|
653
|
+
let t = e.schemas ?? {}, n = Object.assign(Object.assign({}, t), this.filteredSchemaRefs), r = this.options?.sortComponents === "alphabetically" ? w(n) : n, i = e.parameters ?? {}, a = Object.assign(Object.assign({}, i), this.paramRefs), o = this.options?.sortComponents === "alphabetically" ? w(a) : a;
|
|
654
654
|
return Object.assign(Object.assign({}, e), {
|
|
655
655
|
schemas: r,
|
|
656
656
|
parameters: o
|
|
@@ -700,7 +700,7 @@ var ve = class {
|
|
|
700
700
|
getParameterRef(e, t) {
|
|
701
701
|
let n = E.getOpenApiMetadata(e), r = E.getInternalMetadata(e), i = n?.param, a = r?.refId ? this.paramRefs[r.refId] : void 0;
|
|
702
702
|
if (!(!r?.refId || !a)) {
|
|
703
|
-
if (i && a.in !== i.in || t?.in && a.in !== t.in) throw new
|
|
703
|
+
if (i && a.in !== i.in || t?.in && a.in !== t.in) throw new re(`Conflicting location for parameter ${a.name}`, {
|
|
704
704
|
key: "in",
|
|
705
705
|
values: x([
|
|
706
706
|
a.in,
|
|
@@ -708,7 +708,7 @@ var ve = class {
|
|
|
708
708
|
i?.in
|
|
709
709
|
])
|
|
710
710
|
});
|
|
711
|
-
if (i && a.name !== i.name || t?.name && a.name !== t?.name) throw new
|
|
711
|
+
if (i && a.name !== i.name || t?.name && a.name !== t?.name) throw new re("Conflicting names for parameter", {
|
|
712
712
|
key: "name",
|
|
713
713
|
values: x([
|
|
714
714
|
a.name,
|
|
@@ -731,11 +731,11 @@ var ve = class {
|
|
|
731
731
|
});
|
|
732
732
|
if (i) return i;
|
|
733
733
|
let a = r?.param;
|
|
734
|
-
if (a?.name && a.name !== e) throw new
|
|
734
|
+
if (a?.name && a.name !== e) throw new re("Conflicting names for parameter", {
|
|
735
735
|
key: "name",
|
|
736
736
|
values: [e, a.name]
|
|
737
737
|
});
|
|
738
|
-
if (a?.in && a.in !== t) throw new
|
|
738
|
+
if (a?.in && a.in !== t) throw new re(`Conflicting location for parameter ${a.name ?? e}`, {
|
|
739
739
|
key: "in",
|
|
740
740
|
values: [t, a.in]
|
|
741
741
|
});
|
|
@@ -745,7 +745,7 @@ var ve = class {
|
|
|
745
745
|
});
|
|
746
746
|
});
|
|
747
747
|
}
|
|
748
|
-
if (n?.in && n.in !== t) throw new
|
|
748
|
+
if (n?.in && n.in !== t) throw new re(`Conflicting location for parameter ${n.name}`, {
|
|
749
749
|
key: "in",
|
|
750
750
|
values: [t, n.in]
|
|
751
751
|
});
|
|
@@ -760,8 +760,8 @@ var ve = class {
|
|
|
760
760
|
}
|
|
761
761
|
generateParameter(e, t) {
|
|
762
762
|
let n = E.getOpenApiMetadata(e)?.param, r = t?.name ?? n?.name, i = t?.in ?? n?.in;
|
|
763
|
-
if (!r) throw new
|
|
764
|
-
if (!i) throw new
|
|
763
|
+
if (!r) throw new ie({ missingField: "name" });
|
|
764
|
+
if (!i) throw new ie({
|
|
765
765
|
missingField: "in",
|
|
766
766
|
paramName: r
|
|
767
767
|
});
|
|
@@ -817,7 +817,7 @@ var ve = class {
|
|
|
817
817
|
}
|
|
818
818
|
getParameters(e) {
|
|
819
819
|
if (!e) return [];
|
|
820
|
-
let { headers: t } = e, n = this.cleanParameter(e.query), r = this.cleanParameter(e.params), i = this.cleanParameter(e.cookies), a =
|
|
820
|
+
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(() => {
|
|
821
821
|
if (Array.isArray(t)) return t.flatMap((e) => this.generateInlineParameters(e, "header"));
|
|
822
822
|
let e = this.cleanParameter(t);
|
|
823
823
|
return e ? this.generateInlineParameters(e, "header") : [];
|
|
@@ -844,7 +844,7 @@ var ve = class {
|
|
|
844
844
|
"path",
|
|
845
845
|
"request",
|
|
846
846
|
"responses"
|
|
847
|
-
]), o = v(i, (e) => this.getResponse(e)), c =
|
|
847
|
+
]), o = v(i, (e) => this.getResponse(e)), c = ae(() => this.getParameters(r), { route: `${t} ${n}` }), l = this.getRequestBody(r?.body);
|
|
848
848
|
return { [t]: Object.assign(Object.assign(Object.assign(Object.assign({}, a), c.length > 0 ? { parameters: [...a.parameters || [], ...c] } : {}), l ? { requestBody: l } : {}), { responses: o }) };
|
|
849
849
|
}
|
|
850
850
|
generateSingleRoute(e) {
|
|
@@ -16567,7 +16567,7 @@ var $y = class t extends e {
|
|
|
16567
16567
|
defaultHook;
|
|
16568
16568
|
#e;
|
|
16569
16569
|
constructor(e) {
|
|
16570
|
-
super(e), this.openAPIRegistry = new
|
|
16570
|
+
super(e), this.openAPIRegistry = new k(), this.defaultHook = e?.defaultHook;
|
|
16571
16571
|
}
|
|
16572
16572
|
#t() {
|
|
16573
16573
|
if (this.defaultHook) return this.defaultHook;
|
|
@@ -16682,8 +16682,8 @@ var $y = class t extends e {
|
|
|
16682
16682
|
path: Me(r, n._basePath.replaceAll(/:([^\/]+)/g, "{$1}"), e.webhook.path)
|
|
16683
16683
|
});
|
|
16684
16684
|
return;
|
|
16685
|
-
case "schema": return this.openAPIRegistry.register(
|
|
16686
|
-
case "parameter": return this.openAPIRegistry.registerParameter(
|
|
16685
|
+
case "schema": return this.openAPIRegistry.register(O(e.schema)._internal?.refId, e.schema);
|
|
16686
|
+
case "parameter": return this.openAPIRegistry.registerParameter(O(e.schema)._internal?.refId, e.schema);
|
|
16687
16687
|
default: throw Error(`Unknown registry type: ${e}`);
|
|
16688
16688
|
}
|
|
16689
16689
|
}), this) : this;
|
|
@@ -20030,6 +20030,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20030
20030
|
public: !0,
|
|
20031
20031
|
rules: {}
|
|
20032
20032
|
},
|
|
20033
|
+
channelRoot: {
|
|
20034
|
+
label: "Channel Root",
|
|
20035
|
+
type: "link",
|
|
20036
|
+
public: !0,
|
|
20037
|
+
allowedLinkTypes: ["node"],
|
|
20038
|
+
rules: {}
|
|
20039
|
+
},
|
|
20033
20040
|
currency: {
|
|
20034
20041
|
label: "Default Currency",
|
|
20035
20042
|
type: "select",
|
|
@@ -20159,6 +20166,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20159
20166
|
public: !0,
|
|
20160
20167
|
rules: {}
|
|
20161
20168
|
},
|
|
20169
|
+
channelRoot: {
|
|
20170
|
+
label: "Channel Root",
|
|
20171
|
+
type: "link",
|
|
20172
|
+
public: !0,
|
|
20173
|
+
allowedLinkTypes: ["node"],
|
|
20174
|
+
rules: {}
|
|
20175
|
+
},
|
|
20162
20176
|
currency: {
|
|
20163
20177
|
label: "Default Currency",
|
|
20164
20178
|
type: "select",
|
|
@@ -20282,6 +20296,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20282
20296
|
dbType: "json",
|
|
20283
20297
|
public: !0,
|
|
20284
20298
|
rules: {}
|
|
20299
|
+
},
|
|
20300
|
+
channelRoot: {
|
|
20301
|
+
label: "Channel Root",
|
|
20302
|
+
type: "link",
|
|
20303
|
+
public: !0,
|
|
20304
|
+
allowedLinkTypes: ["node"],
|
|
20305
|
+
rules: {}
|
|
20285
20306
|
}
|
|
20286
20307
|
}
|
|
20287
20308
|
},
|
|
@@ -20424,6 +20445,13 @@ var Tb = /* @__PURE__ */ o({
|
|
|
20424
20445
|
public: !0,
|
|
20425
20446
|
rules: {}
|
|
20426
20447
|
},
|
|
20448
|
+
channelRoot: {
|
|
20449
|
+
label: "Channel Root",
|
|
20450
|
+
type: "link",
|
|
20451
|
+
public: !0,
|
|
20452
|
+
allowedLinkTypes: ["node"],
|
|
20453
|
+
rules: {}
|
|
20454
|
+
},
|
|
20427
20455
|
favicon: {
|
|
20428
20456
|
label: "Favicon",
|
|
20429
20457
|
type: "image",
|
|
@@ -21330,6 +21358,12 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21330
21358
|
multiple: !0,
|
|
21331
21359
|
dbType: "json",
|
|
21332
21360
|
public: !0
|
|
21361
|
+
},
|
|
21362
|
+
channelRoot: {
|
|
21363
|
+
label: "Channel Root",
|
|
21364
|
+
type: "link",
|
|
21365
|
+
public: !0,
|
|
21366
|
+
allowedLinkTypes: ["node"]
|
|
21333
21367
|
}
|
|
21334
21368
|
}
|
|
21335
21369
|
},
|
|
@@ -21775,7 +21809,7 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21775
21809
|
userTemplate: null
|
|
21776
21810
|
}, Db = Eb, Ob = {
|
|
21777
21811
|
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 ",
|
|
21778
|
-
users: "\n id TEXT PRIMARY KEY,\n email
|
|
21812
|
+
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 ",
|
|
21779
21813
|
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 ",
|
|
21780
21814
|
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 ",
|
|
21781
21815
|
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 ",
|
|
@@ -21789,8 +21823,9 @@ var Tb = /* @__PURE__ */ o({
|
|
|
21789
21823
|
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 ",
|
|
21790
21824
|
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 ",
|
|
21791
21825
|
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 ",
|
|
21792
|
-
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 "
|
|
21793
|
-
|
|
21826
|
+
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 ",
|
|
21827
|
+
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 "
|
|
21828
|
+
}, 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(".");
|
|
21794
21829
|
function Ab(e) {
|
|
21795
21830
|
let t = /* @__PURE__ */ new Set();
|
|
21796
21831
|
function n(e) {
|
|
@@ -22025,18 +22060,18 @@ var Fb = { hasSubscribers: !1 }, Ib = Fb, Lb = Fb, Rb = typeof performance == "o
|
|
|
22025
22060
|
return this.#i;
|
|
22026
22061
|
}
|
|
22027
22062
|
constructor(t) {
|
|
22028
|
-
let { max: n = 0, ttl: r, ttlResolution: i = 1, ttlAutopurge: a, updateAgeOnGet: o, updateAgeOnHas: s, allowStale: c, dispose: l, onInsert: u, disposeAfter: d, noDisposeOnSet: f, noUpdateTTL: p, maxSize: m = 0, maxEntrySize: h = 0, sizeCalculation: g, fetchMethod: _, memoMethod: v, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: x, allowStaleOnFetchAbort: S, ignoreFetchAbort: C, backgroundFetchSize:
|
|
22029
|
-
if (this.backgroundFetchSize =
|
|
22030
|
-
if (this.#s =
|
|
22031
|
-
let
|
|
22032
|
-
if (!
|
|
22063
|
+
let { max: n = 0, ttl: r, ttlResolution: i = 1, ttlAutopurge: a, updateAgeOnGet: o, updateAgeOnHas: s, allowStale: c, dispose: l, onInsert: u, disposeAfter: d, noDisposeOnSet: f, noUpdateTTL: p, maxSize: m = 0, maxEntrySize: h = 0, sizeCalculation: g, fetchMethod: _, memoMethod: v, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: x, allowStaleOnFetchAbort: S, ignoreFetchAbort: C, backgroundFetchSize: ee = 1, perf: w } = t;
|
|
22064
|
+
if (this.backgroundFetchSize = ee, w !== void 0 && typeof w?.now != "function") throw TypeError("perf option must have a now() method if specified");
|
|
22065
|
+
if (this.#s = w ?? Rb, n !== 0 && !Wb(n)) throw TypeError("max option must be a nonnegative integer");
|
|
22066
|
+
let T = n ? Gb(n) : Array;
|
|
22067
|
+
if (!T) throw Error("invalid max value: " + n);
|
|
22033
22068
|
if (this.#e = n, this.#t = m, this.maxEntrySize = h || this.#t, this.sizeCalculation = g, this.sizeCalculation) {
|
|
22034
22069
|
if (!this.#t && !this.maxEntrySize) throw TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
22035
22070
|
if (typeof this.sizeCalculation != "function") throw TypeError("sizeCalculation set to non-function");
|
|
22036
22071
|
}
|
|
22037
22072
|
if (v !== void 0 && typeof v != "function") throw TypeError("memoMethod must be a function if defined");
|
|
22038
22073
|
if (this.#o = v, _ !== void 0 && typeof _ != "function") throw TypeError("fetchMethod must be a function if specified");
|
|
22039
|
-
if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new
|
|
22074
|
+
if (this.#a = _, this.#w = !!_, this.#u = /* @__PURE__ */ new Map(), this.#d = Array.from({ length: n }).fill(void 0), this.#f = Array.from({ length: n }).fill(void 0), this.#p = new T(n), this.#m = new T(n), this.#h = 0, this.#g = 0, this.#_ = qb.create(n), this.#c = 0, this.#l = 0, typeof l == "function" && (this.#n = l), typeof u == "function" && (this.#r = u), typeof d == "function" ? (this.#i = d, this.#v = []) : (this.#i = void 0, this.#v = void 0), this.#C = !!this.#n, this.#E = !!this.#r, this.#T = !!this.#i, this.noDisposeOnSet = !!f, this.noUpdateTTL = !!p, this.noDeleteOnFetchRejection = !!y, this.allowStaleOnFetchRejection = !!x, this.allowStaleOnFetchAbort = !!S, this.ignoreFetchAbort = !!C, this.maxEntrySize !== 0) {
|
|
22040
22075
|
if (this.#t !== 0 && !Wb(this.#t)) throw TypeError("maxSize must be a positive integer if specified");
|
|
22041
22076
|
if (!Wb(this.maxEntrySize)) throw TypeError("maxEntrySize must be a positive integer if specified");
|
|
22042
22077
|
this.#M();
|
|
@@ -22782,7 +22817,7 @@ function ax(e) {
|
|
|
22782
22817
|
assetRefs: [],
|
|
22783
22818
|
termRefs: []
|
|
22784
22819
|
};
|
|
22785
|
-
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) => {
|
|
22820
|
+
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) => {
|
|
22786
22821
|
if (!e) return null;
|
|
22787
22822
|
if (typeof e == "string" && e.startsWith("trm_")) {
|
|
22788
22823
|
let t = Number(e.replace("trm_", ""));
|
|
@@ -22797,17 +22832,29 @@ function ax(e) {
|
|
|
22797
22832
|
if (!e || typeof e != "object") return e;
|
|
22798
22833
|
if (Array.isArray(e)) return e.map((e, s) => {
|
|
22799
22834
|
let c = r(e);
|
|
22800
|
-
if (c
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
}), typeof e == "object" && e && e.variants && typeof e.variants == "object")) for (let [n, i] of Object.entries(e.variants)) {
|
|
22805
|
-
let e = r(i);
|
|
22806
|
-
e && t.push({
|
|
22807
|
-
assetId: e,
|
|
22808
|
-
fieldKey: `${o}[${s}].variants.${n}`,
|
|
22835
|
+
if (c) {
|
|
22836
|
+
if (t.push({
|
|
22837
|
+
assetId: c,
|
|
22838
|
+
fieldKey: o,
|
|
22809
22839
|
sortOrder: s
|
|
22810
|
-
})
|
|
22840
|
+
}), typeof e == "object" && e && e.variants && typeof e.variants == "object") for (let [n, i] of Object.entries(e.variants)) {
|
|
22841
|
+
let e = r(i);
|
|
22842
|
+
e && t.push({
|
|
22843
|
+
assetId: e,
|
|
22844
|
+
fieldKey: `${o}[${s}].variants.${n}`,
|
|
22845
|
+
sortOrder: s
|
|
22846
|
+
});
|
|
22847
|
+
}
|
|
22848
|
+
} else if (typeof e == "string") {
|
|
22849
|
+
let n = e.match(/ast_[a-zA-Z0-9-]+/g);
|
|
22850
|
+
if (n) {
|
|
22851
|
+
let e = Array.from(new Set(n));
|
|
22852
|
+
for (let n of e) n !== c && t.push({
|
|
22853
|
+
assetId: n,
|
|
22854
|
+
fieldKey: o,
|
|
22855
|
+
sortOrder: s
|
|
22856
|
+
});
|
|
22857
|
+
}
|
|
22811
22858
|
}
|
|
22812
22859
|
let l = i(e);
|
|
22813
22860
|
return l ? (n.push({
|
|
@@ -22843,11 +22890,39 @@ function ax(e) {
|
|
|
22843
22890
|
filename: l.filename || void 0,
|
|
22844
22891
|
mimeType: l.mimeType || void 0
|
|
22845
22892
|
} : d;
|
|
22846
|
-
} else f
|
|
22893
|
+
} else if (f) n.push({
|
|
22847
22894
|
termId: f,
|
|
22848
22895
|
fieldKey: u,
|
|
22849
22896
|
sortOrder: 0
|
|
22850
|
-
}), s[c] = `trm_${f}
|
|
22897
|
+
}), s[c] = `trm_${f}`;
|
|
22898
|
+
else if (Array.isArray(l)) s[c] = a(l, u);
|
|
22899
|
+
else if (l && typeof l == "object") s[c] = a(l, u);
|
|
22900
|
+
else {
|
|
22901
|
+
if (typeof l == "string") {
|
|
22902
|
+
let e = l.match(/ast_[a-zA-Z0-9-]+/g);
|
|
22903
|
+
if (e) {
|
|
22904
|
+
let n = Array.from(new Set(e));
|
|
22905
|
+
for (let e of n) t.push({
|
|
22906
|
+
assetId: e,
|
|
22907
|
+
fieldKey: u,
|
|
22908
|
+
sortOrder: 0
|
|
22909
|
+
});
|
|
22910
|
+
}
|
|
22911
|
+
let r = l.match(/trm_\d+/g);
|
|
22912
|
+
if (r) {
|
|
22913
|
+
let e = Array.from(new Set(r));
|
|
22914
|
+
for (let t of e) {
|
|
22915
|
+
let e = Number(t.replace("trm_", ""));
|
|
22916
|
+
isNaN(e) || n.push({
|
|
22917
|
+
termId: e,
|
|
22918
|
+
fieldKey: u,
|
|
22919
|
+
sortOrder: 0
|
|
22920
|
+
});
|
|
22921
|
+
}
|
|
22922
|
+
}
|
|
22923
|
+
}
|
|
22924
|
+
s[c] = l;
|
|
22925
|
+
}
|
|
22851
22926
|
}
|
|
22852
22927
|
return s;
|
|
22853
22928
|
};
|
|
@@ -22859,18 +22934,20 @@ function ax(e) {
|
|
|
22859
22934
|
}
|
|
22860
22935
|
async function ox(e, t, n) {
|
|
22861
22936
|
if (await e.prepare("DELETE FROM node_assets WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
22862
|
-
let r = /* @__PURE__ */ new Set();
|
|
22863
|
-
for (let
|
|
22864
|
-
|
|
22865
|
-
|
|
22937
|
+
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();
|
|
22938
|
+
for (let r of n) {
|
|
22939
|
+
if (!s.has(r.assetId)) continue;
|
|
22940
|
+
let n = `${t}:${r.assetId}:${r.fieldKey}`;
|
|
22941
|
+
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));
|
|
22866
22942
|
}
|
|
22867
22943
|
}
|
|
22868
22944
|
async function sx(e, t, n) {
|
|
22869
22945
|
if (await e.prepare("DELETE FROM node_terms WHERE nodeId = ?").run(t), n.length === 0) return;
|
|
22870
|
-
let r = /* @__PURE__ */ new Set();
|
|
22871
|
-
for (let
|
|
22872
|
-
|
|
22873
|
-
|
|
22946
|
+
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();
|
|
22947
|
+
for (let r of n) {
|
|
22948
|
+
if (!s.has(r.termId)) continue;
|
|
22949
|
+
let n = `${t}:${r.termId}:${r.fieldKey}`;
|
|
22950
|
+
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));
|
|
22874
22951
|
}
|
|
22875
22952
|
}
|
|
22876
22953
|
//#endregion
|
|
@@ -23261,8 +23338,122 @@ var fx = class {
|
|
|
23261
23338
|
console.warn("⚠️ [CacheWarmer] Tree-wide warming failed:", e);
|
|
23262
23339
|
}
|
|
23263
23340
|
}
|
|
23264
|
-
}
|
|
23265
|
-
|
|
23341
|
+
};
|
|
23342
|
+
//#endregion
|
|
23343
|
+
//#region server/utils/route-generator.ts
|
|
23344
|
+
async function px(e) {
|
|
23345
|
+
try {
|
|
23346
|
+
console.log("[Route Generator] Rebuilding enterprise routing table...");
|
|
23347
|
+
let t = await e.prepare("SELECT id, key, dataJson FROM channels").all(), n = Array.isArray(t) ? t : t?.results || [], r = /* @__PURE__ */ new Map();
|
|
23348
|
+
for (let e of n) if (e.dataJson) try {
|
|
23349
|
+
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
23350
|
+
typeof t == "string" && (t = JSON.parse(t));
|
|
23351
|
+
let n = t?.channelRoot;
|
|
23352
|
+
if (typeof n == "string") try {
|
|
23353
|
+
n = JSON.parse(n);
|
|
23354
|
+
} catch {}
|
|
23355
|
+
let i = n?.nodeId ?? n?.id ?? t?.channelRootNodeId ?? t?.homeNodeId;
|
|
23356
|
+
i != null && !isNaN(Number(i)) && r.set(Number(e.id), Number(i));
|
|
23357
|
+
} catch (t) {
|
|
23358
|
+
console.error(`[Route Generator] Failed to parse channel ${e.id} dataJson:`, t);
|
|
23359
|
+
}
|
|
23360
|
+
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();
|
|
23361
|
+
for (let e of a) e.slug && o.set(Number(e.id), String(e.slug).replace(/^\/+|\/+$/g, ""));
|
|
23362
|
+
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();
|
|
23363
|
+
for (let e of n) {
|
|
23364
|
+
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));
|
|
23365
|
+
if (n && o.has(n)) {
|
|
23366
|
+
p.set(`/:${t}`, {
|
|
23367
|
+
path: "/",
|
|
23368
|
+
channelId: t,
|
|
23369
|
+
nodeId: n,
|
|
23370
|
+
treeId: null,
|
|
23371
|
+
isCanonical: 1,
|
|
23372
|
+
redirectUrl: null
|
|
23373
|
+
}), m.add(`${t}:${n}`);
|
|
23374
|
+
let e = o.get(n);
|
|
23375
|
+
e && e !== "index" && p.set(`/${e}:${t}`, {
|
|
23376
|
+
path: `/${e}`,
|
|
23377
|
+
channelId: t,
|
|
23378
|
+
nodeId: n,
|
|
23379
|
+
treeId: null,
|
|
23380
|
+
isCanonical: 0,
|
|
23381
|
+
redirectUrl: "/"
|
|
23382
|
+
});
|
|
23383
|
+
}
|
|
23384
|
+
for (let e of i) {
|
|
23385
|
+
let r = u.filter((t) => Number(t.treeId) === e), i = /* @__PURE__ */ new Map();
|
|
23386
|
+
for (let e of r) {
|
|
23387
|
+
let t = e.parentId ? Number(e.parentId) : null;
|
|
23388
|
+
i.has(t) || i.set(t, []), i.get(t).push(e);
|
|
23389
|
+
}
|
|
23390
|
+
let a = (r, s) => {
|
|
23391
|
+
let c = i.get(r) || [];
|
|
23392
|
+
for (let r of c) {
|
|
23393
|
+
let i = Number(r.contentId), c = o.get(i);
|
|
23394
|
+
if (!c) continue;
|
|
23395
|
+
let l = n !== void 0 && i === n, u = [...s];
|
|
23396
|
+
!l && c !== "index" && u.push(c);
|
|
23397
|
+
let d = l || u.length === 0 ? "/" : "/" + u.join("/"), f = `${d}:${t}`;
|
|
23398
|
+
if (!p.has(f) || l) {
|
|
23399
|
+
let n = `${t}:${i}`, r = l ? 1 : +!m.has(n);
|
|
23400
|
+
r && m.add(n), p.set(f, {
|
|
23401
|
+
path: d,
|
|
23402
|
+
channelId: t,
|
|
23403
|
+
nodeId: i,
|
|
23404
|
+
treeId: e,
|
|
23405
|
+
isCanonical: r,
|
|
23406
|
+
redirectUrl: null
|
|
23407
|
+
});
|
|
23408
|
+
}
|
|
23409
|
+
a(i, l ? [] : u);
|
|
23410
|
+
}
|
|
23411
|
+
};
|
|
23412
|
+
a(null, []);
|
|
23413
|
+
}
|
|
23414
|
+
for (let e of a) {
|
|
23415
|
+
let r = o.get(e);
|
|
23416
|
+
if (!r) continue;
|
|
23417
|
+
let i = `${t}:${e}`;
|
|
23418
|
+
if (!m.has(i)) {
|
|
23419
|
+
let a = n !== void 0 && e === n ? "/" : `/${r}`, o = `${a}:${t}`;
|
|
23420
|
+
p.has(o) || (p.set(o, {
|
|
23421
|
+
path: a,
|
|
23422
|
+
channelId: t,
|
|
23423
|
+
nodeId: e,
|
|
23424
|
+
treeId: null,
|
|
23425
|
+
isCanonical: 1,
|
|
23426
|
+
redirectUrl: null
|
|
23427
|
+
}), m.add(i));
|
|
23428
|
+
}
|
|
23429
|
+
}
|
|
23430
|
+
}
|
|
23431
|
+
await e.prepare("DELETE FROM node_routes").run();
|
|
23432
|
+
let h = Array.from(p.values());
|
|
23433
|
+
if (h.length === 0) return;
|
|
23434
|
+
for (let t = 0; t < h.length; t += 50) {
|
|
23435
|
+
let n = h.slice(t, t + 50), r = n.map(() => "(?, ?, ?, ?, ?, ?)").join(","), i = n.flatMap((e) => [
|
|
23436
|
+
e.path,
|
|
23437
|
+
e.channelId,
|
|
23438
|
+
e.nodeId,
|
|
23439
|
+
e.treeId,
|
|
23440
|
+
e.isCanonical,
|
|
23441
|
+
e.redirectUrl ?? null
|
|
23442
|
+
]);
|
|
23443
|
+
await e.prepare(`
|
|
23444
|
+
INSERT INTO node_routes (path, channelId, nodeId, treeId, isCanonical, redirectUrl)
|
|
23445
|
+
VALUES ${r}
|
|
23446
|
+
`).run(...i);
|
|
23447
|
+
}
|
|
23448
|
+
console.log(`[Route Generator] Successfully built ${h.length} enterprise routes.`);
|
|
23449
|
+
} catch (e) {
|
|
23450
|
+
console.error("[Route Generator] Fatal error rebuilding routes:", e);
|
|
23451
|
+
}
|
|
23452
|
+
}
|
|
23453
|
+
//#endregion
|
|
23454
|
+
//#region server/routes/admin/nodes.ts
|
|
23455
|
+
var mx = new e();
|
|
23456
|
+
async function hx(e, t, n = []) {
|
|
23266
23457
|
let r = e.prepare(t);
|
|
23267
23458
|
if (typeof r.bind == "function") {
|
|
23268
23459
|
let e = await r.bind(...n).all();
|
|
@@ -23274,23 +23465,23 @@ async function mx(e, t, n = []) {
|
|
|
23274
23465
|
}
|
|
23275
23466
|
return [];
|
|
23276
23467
|
}
|
|
23277
|
-
async function
|
|
23468
|
+
async function gx(e, t, n = []) {
|
|
23278
23469
|
let r = e.prepare(t);
|
|
23279
23470
|
if (typeof r.bind == "function") return r.bind(...n).run();
|
|
23280
23471
|
if (typeof r.run == "function") return r.run(...n);
|
|
23281
23472
|
}
|
|
23282
|
-
function
|
|
23473
|
+
function _x(e) {
|
|
23283
23474
|
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;
|
|
23284
23475
|
}
|
|
23285
|
-
function
|
|
23476
|
+
function vx(e) {
|
|
23286
23477
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
23287
23478
|
}
|
|
23288
|
-
function
|
|
23479
|
+
function yx(e) {
|
|
23289
23480
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
23290
23481
|
let t = Number(e);
|
|
23291
23482
|
return isNaN(t) ? null : t;
|
|
23292
23483
|
}
|
|
23293
|
-
function
|
|
23484
|
+
function bx(e) {
|
|
23294
23485
|
let t = { ...e };
|
|
23295
23486
|
delete t.language, delete t.defaultLanguage;
|
|
23296
23487
|
for (let e of [
|
|
@@ -23303,6 +23494,8 @@ function yx(e) {
|
|
|
23303
23494
|
"contentType",
|
|
23304
23495
|
"title",
|
|
23305
23496
|
"slug",
|
|
23497
|
+
"path",
|
|
23498
|
+
"routePath",
|
|
23306
23499
|
"hidden",
|
|
23307
23500
|
"is_hidden",
|
|
23308
23501
|
"isHidden",
|
|
@@ -23319,34 +23512,28 @@ function yx(e) {
|
|
|
23319
23512
|
]) delete t[e];
|
|
23320
23513
|
return t;
|
|
23321
23514
|
}
|
|
23322
|
-
function
|
|
23323
|
-
return e ? typeof e == "string" ? (e.startsWith("ast_") && t.add(e), t) : Array.isArray(e) ? (e.forEach((e) =>
|
|
23515
|
+
function xx(e, t = /* @__PURE__ */ new Set()) {
|
|
23516
|
+
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;
|
|
23324
23517
|
}
|
|
23325
|
-
function
|
|
23518
|
+
function Sx(e, t) {
|
|
23326
23519
|
if (!e) return !0;
|
|
23327
|
-
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 &&
|
|
23520
|
+
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;
|
|
23328
23521
|
return n || r || i || a || c;
|
|
23329
23522
|
}
|
|
23330
|
-
async function
|
|
23523
|
+
async function Cx(e, t, n) {
|
|
23331
23524
|
for (let r of n) {
|
|
23332
|
-
let n = (await
|
|
23333
|
-
if (
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
for (let e of i) if (e.storageKeyPrivate) try {
|
|
23341
|
-
await t.delete(e.storageKeyPrivate);
|
|
23342
|
-
} catch (t) {
|
|
23343
|
-
console.warn(`[Asset Cleanup] Failed to delete ${e.storageKeyPrivate}:`, t);
|
|
23525
|
+
let n = (await hx(e, "\n SELECT id, storageKeyPrivate, isSystemVariant, parentAssetId, filename\n FROM assets WHERE id = ?\n ", [r]))[0];
|
|
23526
|
+
if (n && n.isSystemVariant && !((await hx(e, "SELECT 1 FROM node_assets WHERE assetId = ? LIMIT 1", [n.id])).length > 0)) {
|
|
23527
|
+
if (n.storageKeyPrivate) try {
|
|
23528
|
+
await t.delete(n.storageKeyPrivate);
|
|
23529
|
+
} catch (e) {
|
|
23530
|
+
console.warn(`[Asset Cleanup] Failed to delete crop ${n.storageKeyPrivate}:`, e);
|
|
23531
|
+
}
|
|
23532
|
+
await gx(e, "DELETE FROM node_assets WHERE assetId = ?", [n.id]), await gx(e, "DELETE FROM assets WHERE id = ?", [n.id]);
|
|
23344
23533
|
}
|
|
23345
|
-
let a = i.map((e) => e.id), o = a.map(() => "?").join(",");
|
|
23346
|
-
await hx(e, `DELETE FROM node_assets WHERE assetId IN (${o})`, a), await hx(e, `DELETE FROM assets WHERE id IN (${o})`, a);
|
|
23347
23534
|
}
|
|
23348
23535
|
}
|
|
23349
|
-
async function
|
|
23536
|
+
async function wx(e, t, n) {
|
|
23350
23537
|
let r = {}, i = null;
|
|
23351
23538
|
if (t) {
|
|
23352
23539
|
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 || [];
|
|
@@ -23371,56 +23558,65 @@ async function Cx(e, t, n) {
|
|
|
23371
23558
|
inheritedFields: r
|
|
23372
23559
|
};
|
|
23373
23560
|
}
|
|
23374
|
-
|
|
23561
|
+
mx.get("/", async (e) => {
|
|
23375
23562
|
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));
|
|
23376
23563
|
if (n) {
|
|
23377
23564
|
let r = Number(n);
|
|
23378
23565
|
if (isNaN(r)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
23379
23566
|
let i = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(r);
|
|
23380
23567
|
if (!i) return e.json({ error: "Node not found" }, 404);
|
|
23381
|
-
let
|
|
23568
|
+
let o = null;
|
|
23569
|
+
if (a && a !== "all") {
|
|
23570
|
+
let e = await t.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND channelId = ? AND isCanonical = 1 LIMIT 1").get(r, Number(a));
|
|
23571
|
+
e && (o = e.path);
|
|
23572
|
+
} else {
|
|
23573
|
+
let e = await t.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND isCanonical = 1 LIMIT 1").get(r);
|
|
23574
|
+
e && (o = e.path);
|
|
23575
|
+
}
|
|
23576
|
+
let s = i.status === "draft" || !!i.hasUnpublishedChanges, c = {
|
|
23382
23577
|
id: i.id,
|
|
23383
23578
|
title: i.title,
|
|
23384
23579
|
slug: i.slug,
|
|
23580
|
+
path: o,
|
|
23385
23581
|
language: i.language || null,
|
|
23386
23582
|
nodeType: i.contentType,
|
|
23387
23583
|
contentType: i.contentType,
|
|
23388
23584
|
isHidden: !!i.isHidden,
|
|
23389
23585
|
status: i.status || "draft",
|
|
23390
23586
|
publishedAt: i.publishedAt || null,
|
|
23391
|
-
hasUnpublishedChanges:
|
|
23587
|
+
hasUnpublishedChanges: s,
|
|
23392
23588
|
deletedAt: i.deletedAt || null,
|
|
23393
23589
|
createdById: i.createdById || null,
|
|
23394
23590
|
updatedById: i.updatedById || null,
|
|
23395
23591
|
createdAt: i.createdAt,
|
|
23396
23592
|
updatedAt: i.updatedAt
|
|
23397
|
-
},
|
|
23398
|
-
if (
|
|
23399
|
-
let n = typeof
|
|
23593
|
+
}, l = i.draftDataJson || i.dataJson;
|
|
23594
|
+
if (l) try {
|
|
23595
|
+
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;
|
|
23400
23596
|
if (a) {
|
|
23401
|
-
let { resolvedLayoutId: e, inheritedFields: r } = await
|
|
23402
|
-
(
|
|
23597
|
+
let { resolvedLayoutId: e, inheritedFields: r } = await wx(t, a.parentId, a.treeId);
|
|
23598
|
+
(s === "inherit" || !s) && (s = e);
|
|
23403
23599
|
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);
|
|
23404
23600
|
}
|
|
23405
|
-
|
|
23406
|
-
if (!
|
|
23601
|
+
s && s !== "inherit" && !((e) => {
|
|
23602
|
+
if (!o || Object.keys(o).length === 0 || e === o.defaultLayout) return !0;
|
|
23407
23603
|
let t = null, n = (e) => {
|
|
23408
23604
|
e && (Array.isArray(e) ? e.forEach((e) => {
|
|
23409
23605
|
e.layoutId && (t = e.layoutId);
|
|
23410
23606
|
}) : e.layoutId && (t = e.layoutId));
|
|
23411
23607
|
};
|
|
23412
|
-
if (n(
|
|
23608
|
+
if (n(o.fields), !t && o.tabs && Object.values(o.tabs).forEach((e) => n(e.fields)), !t) return !1;
|
|
23413
23609
|
let r = t.allowedLayouts;
|
|
23414
23610
|
return r ? typeof r == "string" ? r === e : !Array.isArray(r) || r.length === 0 || r.includes(e) : !0;
|
|
23415
|
-
})(
|
|
23416
|
-
let u = await ux(t,
|
|
23417
|
-
Object.assign(
|
|
23611
|
+
})(s) && (s = null), (s === "inherit" || !s) && (s = o.defaultLayout || null);
|
|
23612
|
+
let u = await ux(t, bx(n));
|
|
23613
|
+
Object.assign(c, u), c.resolvedLayoutId = s;
|
|
23418
23614
|
} catch {}
|
|
23419
|
-
let
|
|
23420
|
-
|
|
23421
|
-
let
|
|
23422
|
-
|
|
23423
|
-
let
|
|
23615
|
+
let u = await t.prepare("SELECT channelId FROM node_channels WHERE nodeId = ?").all(r);
|
|
23616
|
+
c.channels = (Array.isArray(u) ? u : u?.results || []).map((e) => e.channelId);
|
|
23617
|
+
let d = await t.prepare("SELECT treeId, parentId, sortOrder FROM tree_nodes WHERE contentId = ?").all(r);
|
|
23618
|
+
c.trees = Array.isArray(d) ? d : d?.results || [];
|
|
23619
|
+
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) => {
|
|
23424
23620
|
let n = {};
|
|
23425
23621
|
try {
|
|
23426
23622
|
n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson || "{}") : e.dataJson || {}, n && typeof n == "object" && (n = await ux(t, n));
|
|
@@ -23437,8 +23633,8 @@ px.get("/", async (e) => {
|
|
|
23437
23633
|
};
|
|
23438
23634
|
}));
|
|
23439
23635
|
return e.json({
|
|
23440
|
-
node:
|
|
23441
|
-
blocks:
|
|
23636
|
+
node: c,
|
|
23637
|
+
blocks: m
|
|
23442
23638
|
});
|
|
23443
23639
|
}
|
|
23444
23640
|
let m = [], h = [o ? "(cn.deletedAt IS NOT NULL AND cn.deletedAt != '')" : "(cn.deletedAt IS NULL OR cn.deletedAt = '')"];
|
|
@@ -23465,35 +23661,55 @@ px.get("/", async (e) => {
|
|
|
23465
23661
|
let x = `
|
|
23466
23662
|
WITH filtered_nodes AS (
|
|
23467
23663
|
SELECT cn.* FROM content_nodes cn ${g} ORDER BY ${y} ${l} LIMIT ? OFFSET ?
|
|
23664
|
+
),
|
|
23665
|
+
node_asset_counts AS (
|
|
23666
|
+
SELECT
|
|
23667
|
+
na.nodeId,
|
|
23668
|
+
COUNT(DISTINCT CASE WHEN a.mimeType LIKE 'image/%' THEN COALESCE(a.parentAssetId, a.id) END) as imageCount,
|
|
23669
|
+
COUNT(DISTINCT CASE WHEN a.mimeType LIKE 'video/%' OR a.mimeType LIKE 'audio/%' THEN COALESCE(a.parentAssetId, a.id) END) as videoCount,
|
|
23670
|
+
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,
|
|
23671
|
+
COUNT(DISTINCT CASE WHEN 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,
|
|
23672
|
+
COUNT(DISTINCT COALESCE(a.parentAssetId, a.id)) as assetCount
|
|
23673
|
+
FROM node_assets na
|
|
23674
|
+
JOIN assets a ON na.assetId = a.id
|
|
23675
|
+
GROUP BY na.nodeId
|
|
23468
23676
|
)
|
|
23469
|
-
SELECT
|
|
23677
|
+
SELECT
|
|
23678
|
+
fn.*,
|
|
23679
|
+
COALESCE(nac.imageCount, 0) as imageCount,
|
|
23680
|
+
COALESCE(nac.videoCount, 0) as videoCount,
|
|
23681
|
+
COALESCE(nac.documentCount, 0) as documentCount,
|
|
23682
|
+
COALESCE(nac.otherCount, 0) as otherCount,
|
|
23683
|
+
COALESCE(nac.assetCount, 0) as assetCount,
|
|
23684
|
+
(SELECT path FROM node_routes nr WHERE nr.nodeId = fn.id AND isCanonical = 1 LIMIT 1) as routePath
|
|
23470
23685
|
FROM filtered_nodes fn
|
|
23471
|
-
LEFT JOIN
|
|
23472
|
-
|
|
23686
|
+
LEFT JOIN node_asset_counts nac ON fn.id = nac.nodeId
|
|
23687
|
+
ORDER BY ${y.replace("cn.", "fn.")} ${l}
|
|
23473
23688
|
`, S = [
|
|
23474
23689
|
...m,
|
|
23475
23690
|
f,
|
|
23476
23691
|
p
|
|
23477
|
-
], C = await t.prepare(x).all(...S),
|
|
23478
|
-
if (
|
|
23479
|
-
let e =
|
|
23692
|
+
], C = await t.prepare(x).all(...S), ee = Array.isArray(C) ? C : C?.results || [], w = ee.map((e) => e.id), T = {}, E = {};
|
|
23693
|
+
if (w.length > 0) {
|
|
23694
|
+
let e = w.map(() => "?").join(","), n = await t.prepare(`
|
|
23480
23695
|
SELECT nc.nodeId, c.label FROM node_channels nc JOIN channels c ON nc.channelId = c.id WHERE nc.nodeId IN (${e})
|
|
23481
|
-
`).all(...
|
|
23696
|
+
`).all(...w);
|
|
23482
23697
|
(Array.isArray(n) ? n : n?.results || []).forEach((e) => {
|
|
23483
|
-
|
|
23698
|
+
T[e.nodeId] || (T[e.nodeId] = []), T[e.nodeId].push(e.label);
|
|
23484
23699
|
});
|
|
23485
23700
|
let r = await t.prepare(`
|
|
23486
23701
|
SELECT tn.contentId as nodeId, t.label FROM tree_nodes tn JOIN trees t ON tn.treeId = t.id WHERE tn.contentId IN (${e})
|
|
23487
|
-
`).all(...
|
|
23702
|
+
`).all(...w);
|
|
23488
23703
|
(Array.isArray(r) ? r : r?.results || []).forEach((e) => {
|
|
23489
23704
|
E[e.nodeId] || (E[e.nodeId] = []), E[e.nodeId].includes(e.label) || E[e.nodeId].push(e.label);
|
|
23490
23705
|
});
|
|
23491
23706
|
}
|
|
23492
|
-
let D = await Promise.all(
|
|
23707
|
+
let D = await Promise.all(ee.map(async (e) => {
|
|
23493
23708
|
let n = e.status === "draft" || !!e.hasUnpublishedChanges, r = {
|
|
23494
23709
|
id: e.id,
|
|
23495
23710
|
title: e.title,
|
|
23496
23711
|
slug: e.slug,
|
|
23712
|
+
path: e.routePath || null,
|
|
23497
23713
|
language: e.language || null,
|
|
23498
23714
|
contentType: e.contentType,
|
|
23499
23715
|
nodeType: e.contentType,
|
|
@@ -23506,12 +23722,16 @@ px.get("/", async (e) => {
|
|
|
23506
23722
|
updatedById: e.updatedById || null,
|
|
23507
23723
|
createdAt: e.createdAt,
|
|
23508
23724
|
updatedAt: e.updatedAt,
|
|
23509
|
-
channelNames:
|
|
23725
|
+
channelNames: T[e.id] || [],
|
|
23510
23726
|
treeNames: E[e.id] || [],
|
|
23511
|
-
assetCount: e.assetCount || 0
|
|
23727
|
+
assetCount: e.assetCount || 0,
|
|
23728
|
+
imageCount: e.imageCount || 0,
|
|
23729
|
+
videoCount: e.videoCount || 0,
|
|
23730
|
+
documentCount: e.documentCount || 0,
|
|
23731
|
+
otherCount: e.otherCount || 0
|
|
23512
23732
|
}, i = e.draftDataJson || e.dataJson;
|
|
23513
23733
|
if (i) try {
|
|
23514
|
-
let e = typeof i == "string" ? JSON.parse(i) : i, n = await ux(t,
|
|
23734
|
+
let e = typeof i == "string" ? JSON.parse(i) : i, n = await ux(t, bx(e));
|
|
23515
23735
|
Object.assign(r, n);
|
|
23516
23736
|
} catch {}
|
|
23517
23737
|
return r;
|
|
@@ -23523,10 +23743,10 @@ px.get("/", async (e) => {
|
|
|
23523
23743
|
offset: p,
|
|
23524
23744
|
limit: f
|
|
23525
23745
|
});
|
|
23526
|
-
}),
|
|
23527
|
-
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(
|
|
23528
|
-
if (
|
|
23529
|
-
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(
|
|
23746
|
+
}), mx.post("/", async (e) => {
|
|
23747
|
+
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;
|
|
23748
|
+
if (T) {
|
|
23749
|
+
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(T) || -1, String(T));
|
|
23530
23750
|
if (e?.dataJson) try {
|
|
23531
23751
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
23532
23752
|
E = t.defaultLanguage?.trim() || t.language?.trim() || null;
|
|
@@ -23545,13 +23765,13 @@ px.get("/", async (e) => {
|
|
|
23545
23765
|
}
|
|
23546
23766
|
}
|
|
23547
23767
|
}
|
|
23548
|
-
|
|
23549
|
-
let D = a, te = /* @__PURE__ */ new Set(),
|
|
23550
|
-
if (
|
|
23768
|
+
ee && E && ee === E && (ee = null);
|
|
23769
|
+
let D = a, te = /* @__PURE__ */ new Set(), ne = !1, O = "draft", k = 0, A = s === void 0 ? null : _x(s);
|
|
23770
|
+
if (A) {
|
|
23551
23771
|
let n = [];
|
|
23552
23772
|
if (g !== void 0 && Array.isArray(g) && g.length > 0) for (let e of g) n.push({
|
|
23553
23773
|
treeId: Number(e.treeId),
|
|
23554
|
-
parentId:
|
|
23774
|
+
parentId: yx(e.parentId ?? e._draftParentId ?? null)
|
|
23555
23775
|
});
|
|
23556
23776
|
else if (a) {
|
|
23557
23777
|
let e = await t.prepare("SELECT treeId, parentId FROM tree_nodes WHERE contentId = ?").all(a), r = Array.isArray(e) ? e : e?.results || [];
|
|
@@ -23561,32 +23781,32 @@ px.get("/", async (e) => {
|
|
|
23561
23781
|
});
|
|
23562
23782
|
}
|
|
23563
23783
|
for (let r of n) {
|
|
23564
|
-
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId,
|
|
23784
|
+
let n = r.parentId === null ? "tn.parentId IS NULL" : "tn.parentId = ?", i = r.parentId === null ? [r.treeId, A] : [
|
|
23565
23785
|
r.treeId,
|
|
23566
23786
|
r.parentId,
|
|
23567
|
-
|
|
23787
|
+
A
|
|
23568
23788
|
], o = `
|
|
23569
23789
|
SELECT cn.id FROM tree_nodes tn
|
|
23570
23790
|
INNER JOIN content_nodes cn ON tn.contentId = cn.id
|
|
23571
23791
|
WHERE tn.treeId = ? AND ${n} AND cn.slug = ? AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
23572
23792
|
`;
|
|
23573
23793
|
if (a && (o += " AND cn.id != ?", i.push(a)), o += " LIMIT 1", await t.prepare(o).get(...i)) return e.json({
|
|
23574
|
-
error: `The slug '${
|
|
23794
|
+
error: `The slug '${A}' is already in use by another page in this section.`,
|
|
23575
23795
|
field: "slug"
|
|
23576
23796
|
}, 409);
|
|
23577
23797
|
}
|
|
23578
23798
|
}
|
|
23579
23799
|
if (a) {
|
|
23580
23800
|
let e = await t.prepare("SELECT title, slug, language, contentType, isHidden, draftDataJson, dataJson, publishedAt, status, hasUnpublishedChanges FROM content_nodes WHERE id = ?").get(a);
|
|
23581
|
-
|
|
23801
|
+
ne = Sx(e, {
|
|
23582
23802
|
title: o,
|
|
23583
|
-
slug:
|
|
23803
|
+
slug: A,
|
|
23584
23804
|
isHidden: x,
|
|
23585
23805
|
sanitizedFields: v
|
|
23586
23806
|
});
|
|
23587
23807
|
let n = e?.draftDataJson || e?.dataJson || "{}";
|
|
23588
23808
|
try {
|
|
23589
|
-
|
|
23809
|
+
xx(typeof n == "string" ? JSON.parse(n) : n, te);
|
|
23590
23810
|
} catch {}
|
|
23591
23811
|
let r = {};
|
|
23592
23812
|
try {
|
|
@@ -23596,7 +23816,7 @@ px.get("/", async (e) => {
|
|
|
23596
23816
|
...r,
|
|
23597
23817
|
...v
|
|
23598
23818
|
}), l = !1;
|
|
23599
|
-
if (o !== void 0 && o.trim() !== (e?.title || "Untitled") && (l = !0), s !== void 0 &&
|
|
23819
|
+
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) {
|
|
23600
23820
|
for (let e of Object.keys(v)) if (JSON.stringify(v[e]) !== JSON.stringify(r[e])) {
|
|
23601
23821
|
l = !0;
|
|
23602
23822
|
break;
|
|
@@ -23618,13 +23838,13 @@ px.get("/", async (e) => {
|
|
|
23618
23838
|
}
|
|
23619
23839
|
}
|
|
23620
23840
|
}
|
|
23621
|
-
let u = o === void 0 ? e?.title || "Untitled" : o, d =
|
|
23622
|
-
|
|
23841
|
+
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;
|
|
23842
|
+
O = e?.status === "published" || e?.publishedAt ? "published" : "draft";
|
|
23623
23843
|
let h = e?.hasUnpublishedChanges === 1 || e?.hasUnpublishedChanges === !0;
|
|
23624
|
-
|
|
23844
|
+
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);
|
|
23625
23845
|
} else {
|
|
23626
|
-
|
|
23627
|
-
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",
|
|
23846
|
+
ne = !0;
|
|
23847
|
+
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);
|
|
23628
23848
|
D = Number(e.lastInsertRowid);
|
|
23629
23849
|
}
|
|
23630
23850
|
if (h !== void 0 && Array.isArray(h) && D) {
|
|
@@ -23637,10 +23857,10 @@ px.get("/", async (e) => {
|
|
|
23637
23857
|
}
|
|
23638
23858
|
if (g !== void 0 && Array.isArray(g) && g.length > 0 && D) for (let e of g) {
|
|
23639
23859
|
if (!e || !e.treeId) continue;
|
|
23640
|
-
let n = Number(e.treeId) || e.treeId, r =
|
|
23641
|
-
a ? ((a.parentId !== r || a.sortOrder !== i) && (
|
|
23860
|
+
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);
|
|
23861
|
+
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));
|
|
23642
23862
|
}
|
|
23643
|
-
let
|
|
23863
|
+
let re = [], ie = [];
|
|
23644
23864
|
if (m !== void 0 && Array.isArray(m) && D) {
|
|
23645
23865
|
await t.prepare("DELETE FROM content_blocks WHERE contentId = ? AND isDraft = 1").run(D);
|
|
23646
23866
|
let e = [], n = [];
|
|
@@ -23650,10 +23870,10 @@ px.get("/", async (e) => {
|
|
|
23650
23870
|
blockId: o,
|
|
23651
23871
|
_instanceId: o
|
|
23652
23872
|
});
|
|
23653
|
-
c.forEach((e) =>
|
|
23873
|
+
c.forEach((e) => re.push({
|
|
23654
23874
|
...e,
|
|
23655
23875
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
23656
|
-
})), l.forEach((e) =>
|
|
23876
|
+
})), l.forEach((e) => ie.push({
|
|
23657
23877
|
...e,
|
|
23658
23878
|
fieldKey: `blocks[${t}].${e.fieldKey}`
|
|
23659
23879
|
}));
|
|
@@ -23663,22 +23883,22 @@ px.get("/", async (e) => {
|
|
|
23663
23883
|
e.length > 0 && await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...n);
|
|
23664
23884
|
}
|
|
23665
23885
|
if (D) {
|
|
23666
|
-
let n = [...y, ...
|
|
23886
|
+
let n = [...y, ...re], r = [...b, ...ie];
|
|
23667
23887
|
await ox(t, D, n), await sx(t, D, r);
|
|
23668
23888
|
let i = new Set(n.map((e) => e.assetId)), a = new Set([...te].filter((e) => !i.has(e)));
|
|
23669
23889
|
if (a.size > 0) {
|
|
23670
23890
|
let { storage: n } = ix(e.env);
|
|
23671
|
-
await
|
|
23891
|
+
await Cx(t, n, a);
|
|
23672
23892
|
}
|
|
23673
23893
|
}
|
|
23674
|
-
return await $b(e).clear(), e.json({
|
|
23894
|
+
return await $b(e).clear(), ne && await px(t), e.json({
|
|
23675
23895
|
success: !0,
|
|
23676
23896
|
id: D,
|
|
23677
|
-
status:
|
|
23678
|
-
hasUnpublishedChanges:
|
|
23679
|
-
isStructuralChange:
|
|
23897
|
+
status: O,
|
|
23898
|
+
hasUnpublishedChanges: k === 1 || O === "draft",
|
|
23899
|
+
isStructuralChange: ne
|
|
23680
23900
|
});
|
|
23681
|
-
}),
|
|
23901
|
+
}), mx.post("/publish", async (e) => {
|
|
23682
23902
|
let t = e.get("db"), n = await e.req.json(), r = n.id || n.nodeId;
|
|
23683
23903
|
if (!r || isNaN(Number(r))) return e.json({ error: "Node ID required for publishing" }, 400);
|
|
23684
23904
|
let i = Number(r), a = e.get("user")?.id || null, o = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(i);
|
|
@@ -23711,7 +23931,7 @@ px.get("/", async (e) => {
|
|
|
23711
23931
|
},
|
|
23712
23932
|
blocks: v
|
|
23713
23933
|
};
|
|
23714
|
-
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({
|
|
23934
|
+
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({
|
|
23715
23935
|
success: !0,
|
|
23716
23936
|
id: i,
|
|
23717
23937
|
status: "published",
|
|
@@ -23720,29 +23940,29 @@ px.get("/", async (e) => {
|
|
|
23720
23940
|
hasUnpublishedChanges: !1,
|
|
23721
23941
|
isStructuralChange: h
|
|
23722
23942
|
});
|
|
23723
|
-
}),
|
|
23943
|
+
}), mx.delete("/", async (e) => {
|
|
23724
23944
|
let t = e.get("db"), n = e.req.query("id");
|
|
23725
23945
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
23726
23946
|
let r = Number(n);
|
|
23727
|
-
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({
|
|
23947
|
+
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({
|
|
23728
23948
|
success: !0,
|
|
23729
23949
|
deletedNodeId: r
|
|
23730
23950
|
});
|
|
23731
|
-
}),
|
|
23951
|
+
}), mx.post("/restore", async (e) => {
|
|
23732
23952
|
let t = e.get("db"), n = await e.req.json(), r = Number(n.id);
|
|
23733
|
-
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({
|
|
23953
|
+
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({
|
|
23734
23954
|
success: !0,
|
|
23735
23955
|
restoredNodeId: r
|
|
23736
23956
|
})) : e.json({ error: "Node not found" }, 404) : e.json({ error: "Node ID required" }, 400);
|
|
23737
|
-
}),
|
|
23957
|
+
}), mx.delete("/purge", async (e) => {
|
|
23738
23958
|
let t = e.get("db"), n = e.req.query("id");
|
|
23739
23959
|
if (!n) return e.json({ error: "Node ID required" }, 400);
|
|
23740
23960
|
let r = Number(n);
|
|
23741
|
-
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({
|
|
23961
|
+
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({
|
|
23742
23962
|
success: !0,
|
|
23743
23963
|
purgedNodeId: r
|
|
23744
23964
|
});
|
|
23745
|
-
}),
|
|
23965
|
+
}), mx.get("/:id/revisions", async (e) => {
|
|
23746
23966
|
let t = e.get("db"), n = Number(e.req.param("id"));
|
|
23747
23967
|
if (isNaN(n)) return e.json({ error: "Invalid Node ID" }, 400);
|
|
23748
23968
|
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) => {
|
|
@@ -23758,7 +23978,7 @@ px.get("/", async (e) => {
|
|
|
23758
23978
|
};
|
|
23759
23979
|
});
|
|
23760
23980
|
return e.json({ revisions: i });
|
|
23761
|
-
}),
|
|
23981
|
+
}), mx.get("/:id/revisions/:version", async (e) => {
|
|
23762
23982
|
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);
|
|
23763
23983
|
if (!i) return e.json({ error: "Snapshot not found" }, 404);
|
|
23764
23984
|
let a = {};
|
|
@@ -23768,7 +23988,7 @@ px.get("/", async (e) => {
|
|
|
23768
23988
|
return e.json({ error: "Corrupt snapshot data" }, 500);
|
|
23769
23989
|
}
|
|
23770
23990
|
return e.json({ snapshot: a });
|
|
23771
|
-
}),
|
|
23991
|
+
}), mx.post("/:id/revisions/:version/restore", async (e) => {
|
|
23772
23992
|
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);
|
|
23773
23993
|
if (!a) return e.json({ error: "Snapshot not found" }, 404);
|
|
23774
23994
|
let o = {};
|
|
@@ -23782,15 +24002,15 @@ px.get("/", async (e) => {
|
|
|
23782
24002
|
for (let t of o.blocks) e.push("(?, ?, ?, ?, ?, 1)"), r.push(n, t.sortOrder, t.elementType, t.dataJson, t.region || "content");
|
|
23783
24003
|
await t.prepare(`INSERT INTO content_blocks (contentId, sortOrder, elementType, dataJson, region, isDraft) VALUES ${e.join(", ")}`).run(...r);
|
|
23784
24004
|
}
|
|
23785
|
-
return await $b(e).clear(), e.json({
|
|
24005
|
+
return await $b(e).clear(), await px(t), e.json({
|
|
23786
24006
|
success: !0,
|
|
23787
24007
|
restoredVersion: r
|
|
23788
24008
|
});
|
|
23789
24009
|
});
|
|
23790
24010
|
//#endregion
|
|
23791
24011
|
//#region server/routes/admin/trees.ts
|
|
23792
|
-
var
|
|
23793
|
-
function
|
|
24012
|
+
var Tx = new e();
|
|
24013
|
+
function Ex(e, t = null) {
|
|
23794
24014
|
let n = [];
|
|
23795
24015
|
for (let r = 0; r < e.length; r++) {
|
|
23796
24016
|
let i = e[r];
|
|
@@ -23802,19 +24022,19 @@ function Tx(e, t = null) {
|
|
|
23802
24022
|
id: o,
|
|
23803
24023
|
parentId: t,
|
|
23804
24024
|
sortOrder: r
|
|
23805
|
-
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...
|
|
24025
|
+
}), i.children && Array.isArray(i.children) && i.children.length > 0 && n.push(...Ex(i.children, o)));
|
|
23806
24026
|
}
|
|
23807
24027
|
return n;
|
|
23808
24028
|
}
|
|
23809
|
-
function
|
|
24029
|
+
function Dx(e) {
|
|
23810
24030
|
if (e == null || e === "null" || e === "" || typeof e == "string" && e.startsWith("draft-")) return null;
|
|
23811
24031
|
let t = Number(e);
|
|
23812
24032
|
return isNaN(t) ? null : t;
|
|
23813
24033
|
}
|
|
23814
|
-
function
|
|
24034
|
+
function Ox(e) {
|
|
23815
24035
|
return +(e === !0 || e === 1 || e === "1" || e === "true");
|
|
23816
24036
|
}
|
|
23817
|
-
|
|
24037
|
+
Tx.get("/tree.json", async (e) => {
|
|
23818
24038
|
try {
|
|
23819
24039
|
let t = e.get("db"), n = e.req.query("treeId") || "main-nav", r = e.req.query("preview") === "true", i = 1;
|
|
23820
24040
|
if (isNaN(Number(n))) {
|
|
@@ -23867,7 +24087,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23867
24087
|
} catch (t) {
|
|
23868
24088
|
return console.error("[CMS Tree API] GET Error:", t), e.json({ error: t.message || "Failed to fetch tree" }, 500);
|
|
23869
24089
|
}
|
|
23870
|
-
}),
|
|
24090
|
+
}), Tx.post("/tree.json", async (e) => {
|
|
23871
24091
|
try {
|
|
23872
24092
|
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;
|
|
23873
24093
|
if (isNaN(Number(r))) {
|
|
@@ -23879,7 +24099,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23879
24099
|
}
|
|
23880
24100
|
} else o = Number(r);
|
|
23881
24101
|
if (n.tree && Array.isArray(n.tree)) {
|
|
23882
|
-
let r =
|
|
24102
|
+
let r = Ex(n.tree, null);
|
|
23883
24103
|
if (r.length > 0) for (let e = 0; e < r.length; e += 50) {
|
|
23884
24104
|
let n = r.slice(e, e + 50), i = n.map((e) => e.id), a = i.map(() => "?").join(","), s = "UPDATE tree_nodes SET \n";
|
|
23885
24105
|
s += "parentId = CASE contentId \n", n.forEach(() => {
|
|
@@ -23894,14 +24114,14 @@ wx.get("/tree.json", async (e) => {
|
|
|
23894
24114
|
c.push(e.id, e.sortOrder);
|
|
23895
24115
|
}), c.push(...i), c.push(o), await t.prepare(s).run(...c);
|
|
23896
24116
|
}
|
|
23897
|
-
return await i.clear(), r.length > 0 && a.purgeNode(e, t, r[0].id, !0), e.json({
|
|
24117
|
+
return await i.clear(), r.length > 0 && a.purgeNode(e, t, r[0].id, !0), await px(t), e.json({
|
|
23898
24118
|
success: !0,
|
|
23899
24119
|
reorderedCount: r.length
|
|
23900
24120
|
});
|
|
23901
24121
|
}
|
|
23902
|
-
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 =
|
|
24122
|
+
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);
|
|
23903
24123
|
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;
|
|
23904
|
-
let g =
|
|
24124
|
+
let g = Dx(u), _ = e.get("user")?.id || null;
|
|
23905
24125
|
if (s === "create") {
|
|
23906
24126
|
let r = m.slug || n.slug || c, a = r ? String(r).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "") : null;
|
|
23907
24127
|
if (a) {
|
|
@@ -23956,7 +24176,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
23956
24176
|
let e = x.map(() => "(?, ?)").join(", "), n = x.flatMap((e) => [f, e]);
|
|
23957
24177
|
await t.prepare(`INSERT OR IGNORE INTO node_channels (nodeId, channelId) VALUES ${e}`).run(...n);
|
|
23958
24178
|
}
|
|
23959
|
-
return await i.clear(), e.json({
|
|
24179
|
+
return await i.clear(), await px(t), e.json({
|
|
23960
24180
|
success: !0,
|
|
23961
24181
|
id: f,
|
|
23962
24182
|
treeNodeId: f,
|
|
@@ -23993,14 +24213,14 @@ wx.get("/tree.json", async (e) => {
|
|
|
23993
24213
|
field: "slug"
|
|
23994
24214
|
}, 409);
|
|
23995
24215
|
}
|
|
23996
|
-
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({
|
|
24216
|
+
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({
|
|
23997
24217
|
success: !0,
|
|
23998
24218
|
treeNodeId: d
|
|
23999
24219
|
});
|
|
24000
24220
|
}
|
|
24001
24221
|
if (s === "detach") {
|
|
24002
24222
|
let r = n.contentId || n.id || n.treeNodeId;
|
|
24003
|
-
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);
|
|
24223
|
+
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);
|
|
24004
24224
|
}
|
|
24005
24225
|
return e.json({ error: "Invalid payload or action" }, 400);
|
|
24006
24226
|
} catch (t) {
|
|
@@ -24009,7 +24229,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
24009
24229
|
details: t.message
|
|
24010
24230
|
}, 500);
|
|
24011
24231
|
}
|
|
24012
|
-
}),
|
|
24232
|
+
}), Tx.get("/trees.json", async (e) => {
|
|
24013
24233
|
try {
|
|
24014
24234
|
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) => {
|
|
24015
24235
|
let n = Number(t.treeId), r = Number(t.channelId);
|
|
@@ -24039,7 +24259,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
24039
24259
|
} catch {
|
|
24040
24260
|
return e.json([]);
|
|
24041
24261
|
}
|
|
24042
|
-
}),
|
|
24262
|
+
}), Tx.post("/trees.json", async (e) => {
|
|
24043
24263
|
try {
|
|
24044
24264
|
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 };
|
|
24045
24265
|
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({
|
|
@@ -24064,7 +24284,7 @@ wx.get("/tree.json", async (e) => {
|
|
|
24064
24284
|
await t.prepare(`INSERT OR IGNORE INTO channel_trees (channelId, treeId, key) VALUES ${n}`).run(...r);
|
|
24065
24285
|
}
|
|
24066
24286
|
}
|
|
24067
|
-
return await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), e.json({
|
|
24287
|
+
return await $b(e).clear(), new fx(e.env).purgeGlobalCache(e, t), await px(t), e.json({
|
|
24068
24288
|
success: !0,
|
|
24069
24289
|
id: p,
|
|
24070
24290
|
key: o,
|
|
@@ -24078,12 +24298,12 @@ wx.get("/tree.json", async (e) => {
|
|
|
24078
24298
|
} catch (t) {
|
|
24079
24299
|
return console.error("[API Trees] Error saving tree:", t), e.json({ error: t.message || "Failed to save tree" }, 500);
|
|
24080
24300
|
}
|
|
24081
|
-
}),
|
|
24301
|
+
}), Tx.delete("/trees.json", async (e) => {
|
|
24082
24302
|
let t = e.get("db"), n = e.req.query("id");
|
|
24083
24303
|
if (!n) return e.json({ error: "Tree ID required" }, 400);
|
|
24084
24304
|
let r = Number(n);
|
|
24085
24305
|
try {
|
|
24086
|
-
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({
|
|
24306
|
+
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({
|
|
24087
24307
|
success: !0,
|
|
24088
24308
|
deletedTreeId: r
|
|
24089
24309
|
});
|
|
@@ -24093,8 +24313,8 @@ wx.get("/tree.json", async (e) => {
|
|
|
24093
24313
|
});
|
|
24094
24314
|
//#endregion
|
|
24095
24315
|
//#region server/routes/admin/channels.ts
|
|
24096
|
-
var
|
|
24097
|
-
|
|
24316
|
+
var kx = new e();
|
|
24317
|
+
kx.get("/", async (e) => {
|
|
24098
24318
|
try {
|
|
24099
24319
|
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) => {
|
|
24100
24320
|
e[t.channelId] || (e[t.channelId] = []);
|
|
@@ -24160,26 +24380,26 @@ Ox.get("/", async (e) => {
|
|
|
24160
24380
|
error: t.message
|
|
24161
24381
|
}, 500);
|
|
24162
24382
|
}
|
|
24163
|
-
}),
|
|
24383
|
+
}), kx.post("/", async (e) => {
|
|
24164
24384
|
try {
|
|
24165
|
-
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",
|
|
24166
|
-
typeof
|
|
24167
|
-
let
|
|
24385
|
+
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 || "";
|
|
24386
|
+
typeof w == "object" && w && (w = w.value || w.id || ""), w = String(w).trim();
|
|
24387
|
+
let T = m === !0 || m === "true" || m === 1 || h === !0 || h === "true" || h === 1, E = Array.isArray(g) ? g : [], D = JSON.stringify(S || {}), te = e.get("user")?.id || v || _ || null;
|
|
24168
24388
|
if (await t.prepare("SELECT id FROM channels WHERE key = ? AND id != ? LIMIT 1").get(C, a ?? -1)) return e.json({
|
|
24169
24389
|
error: `Channel API key "${C}" is already in use.`,
|
|
24170
24390
|
field: "key"
|
|
24171
24391
|
}, 409);
|
|
24172
|
-
let
|
|
24173
|
-
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,
|
|
24392
|
+
let ne = a;
|
|
24393
|
+
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);
|
|
24174
24394
|
else {
|
|
24175
|
-
let e = await t.prepare("\n INSERT INTO channels (key, label, channelType, domain, baseUrl, defaultLanguage, isHidden, dataJson, createdById, updatedById)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ").run(C,
|
|
24176
|
-
|
|
24177
|
-
}
|
|
24178
|
-
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(
|
|
24179
|
-
let
|
|
24180
|
-
if (
|
|
24181
|
-
let e =
|
|
24182
|
-
|
|
24395
|
+
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);
|
|
24396
|
+
ne = Number(e.lastInsertRowid);
|
|
24397
|
+
}
|
|
24398
|
+
await t.prepare("DELETE FROM channel_trees WHERE channelId = ?").run(ne);
|
|
24399
|
+
let O = E.filter((e) => e && e.treeId && e.key);
|
|
24400
|
+
if (O.length > 0) {
|
|
24401
|
+
let e = O.map(() => "(?, ?, ?, ?)").join(", "), n = O.flatMap((e) => [
|
|
24402
|
+
ne,
|
|
24183
24403
|
Number(e.treeId) || e.treeId,
|
|
24184
24404
|
String(e.key).trim(),
|
|
24185
24405
|
JSON.stringify(e.meta || {})
|
|
@@ -24189,10 +24409,10 @@ Ox.get("/", async (e) => {
|
|
|
24189
24409
|
VALUES ${e}
|
|
24190
24410
|
`).run(...n);
|
|
24191
24411
|
}
|
|
24192
|
-
let
|
|
24193
|
-
return await
|
|
24412
|
+
let k = $b(e);
|
|
24413
|
+
return await k.delete(`channel:${C}`), await k.delete(`channel:${ne}`), await k.clear(), new fx(e.env).purgeGlobalCache(e, t), e.json({
|
|
24194
24414
|
success: !0,
|
|
24195
|
-
id:
|
|
24415
|
+
id: ne
|
|
24196
24416
|
});
|
|
24197
24417
|
} catch (t) {
|
|
24198
24418
|
return console.error("[API Channels] Error saving channel:", t), e.json({
|
|
@@ -24200,7 +24420,7 @@ Ox.get("/", async (e) => {
|
|
|
24200
24420
|
details: t.message
|
|
24201
24421
|
}, 500);
|
|
24202
24422
|
}
|
|
24203
|
-
}),
|
|
24423
|
+
}), kx.delete("/", async (e) => {
|
|
24204
24424
|
let t = e.get("db"), n = e.req.query("id");
|
|
24205
24425
|
if (!n) return e.json({ error: "Channel ID required" }, 400);
|
|
24206
24426
|
let r = Number(n);
|
|
@@ -24220,15 +24440,15 @@ Ox.get("/", async (e) => {
|
|
|
24220
24440
|
});
|
|
24221
24441
|
//#endregion
|
|
24222
24442
|
//#region server/routes/admin/taxonomies.ts
|
|
24223
|
-
var
|
|
24224
|
-
function
|
|
24443
|
+
var Ax = new e();
|
|
24444
|
+
function jx(e) {
|
|
24225
24445
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
24226
24446
|
}
|
|
24227
|
-
function
|
|
24447
|
+
function Mx(e) {
|
|
24228
24448
|
let t = (e || "").trim().toLowerCase(), n = dx()?.taxonomies || {};
|
|
24229
24449
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
24230
24450
|
}
|
|
24231
|
-
async function
|
|
24451
|
+
async function Nx(e, t, n = []) {
|
|
24232
24452
|
let r = e.prepare(t);
|
|
24233
24453
|
if (typeof r.bind == "function") {
|
|
24234
24454
|
let e = await r.bind(...n).all();
|
|
@@ -24240,10 +24460,10 @@ async function Mx(e, t, n = []) {
|
|
|
24240
24460
|
}
|
|
24241
24461
|
return [];
|
|
24242
24462
|
}
|
|
24243
|
-
|
|
24244
|
-
let t = e.get("db"), n =
|
|
24463
|
+
Ax.get("/:taxonomy", async (e) => {
|
|
24464
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy"));
|
|
24245
24465
|
try {
|
|
24246
|
-
let r = (await
|
|
24466
|
+
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) => ({
|
|
24247
24467
|
...e,
|
|
24248
24468
|
data: e.dataJson ? JSON.parse(e.dataJson) : {}
|
|
24249
24469
|
}));
|
|
@@ -24254,12 +24474,12 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24254
24474
|
} catch (t) {
|
|
24255
24475
|
return console.error("[Taxonomy API] Error fetching terms:", t), e.json({ error: "Failed to fetch taxonomy terms" }, 500);
|
|
24256
24476
|
}
|
|
24257
|
-
}),
|
|
24258
|
-
let t = e.get("db"), n =
|
|
24477
|
+
}), Ax.post("/:taxonomy", async (e) => {
|
|
24478
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = await e.req.json(), i = r.label?.trim();
|
|
24259
24479
|
if (!i) return e.json({ error: "Label is required" }, 400);
|
|
24260
|
-
let a = r.key?.trim() ||
|
|
24480
|
+
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) : "{}";
|
|
24261
24481
|
try {
|
|
24262
|
-
if ((await
|
|
24482
|
+
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);
|
|
24263
24483
|
let r = t.prepare("\n INSERT INTO taxonomy_terms (taxonomy, key, label, parentId, sortOrder, dataJson)\n VALUES (?, ?, ?, ?, ?, ?)\n "), l;
|
|
24264
24484
|
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({
|
|
24265
24485
|
success: !0,
|
|
@@ -24268,12 +24488,12 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24268
24488
|
} catch (t) {
|
|
24269
24489
|
return console.error("[Taxonomy API] Error creating term:", t), e.json({ error: "Failed to create taxonomy term" }, 500);
|
|
24270
24490
|
}
|
|
24271
|
-
}),
|
|
24272
|
-
let t = e.get("db"), n =
|
|
24491
|
+
}), Ax.put("/:taxonomy/:id", async (e) => {
|
|
24492
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
24273
24493
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
24274
24494
|
let i = await e.req.json();
|
|
24275
24495
|
try {
|
|
24276
|
-
let a = await
|
|
24496
|
+
let a = await Nx(t, "SELECT * FROM taxonomy_terms WHERE id = ? AND taxonomy = ?", [r, n]);
|
|
24277
24497
|
if (a.length === 0) return e.json({ error: "Term not found" }, 404);
|
|
24278
24498
|
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;
|
|
24279
24499
|
if (i.data) {
|
|
@@ -24283,14 +24503,14 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24283
24503
|
...i.data
|
|
24284
24504
|
});
|
|
24285
24505
|
}
|
|
24286
|
-
if (c !== o.key && (await
|
|
24506
|
+
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);
|
|
24287
24507
|
let f = t.prepare("\n UPDATE taxonomy_terms \n SET label = ?, key = ?, parentId = ?, sortOrder = ?, dataJson = ?, updatedAt = CURRENT_TIMESTAMP\n WHERE id = ?\n ");
|
|
24288
24508
|
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 });
|
|
24289
24509
|
} catch (t) {
|
|
24290
24510
|
return console.error("[Taxonomy API] Error updating term:", t), e.json({ error: "Failed to update taxonomy term" }, 500);
|
|
24291
24511
|
}
|
|
24292
|
-
}),
|
|
24293
|
-
let t = e.get("db"), n =
|
|
24512
|
+
}), Ax.delete("/:taxonomy/:id", async (e) => {
|
|
24513
|
+
let t = e.get("db"), n = Mx(e.req.param("taxonomy")), r = Number(e.req.param("id"));
|
|
24294
24514
|
if (isNaN(r)) return e.json({ error: "Invalid term ID" }, 400);
|
|
24295
24515
|
try {
|
|
24296
24516
|
let i = t.prepare("DELETE FROM taxonomy_terms WHERE id = ? AND taxonomy = ?");
|
|
@@ -24301,20 +24521,20 @@ kx.get("/:taxonomy", async (e) => {
|
|
|
24301
24521
|
});
|
|
24302
24522
|
//#endregion
|
|
24303
24523
|
//#region server/schema/engine.ts
|
|
24304
|
-
var
|
|
24524
|
+
var Px = null, Fx = null;
|
|
24305
24525
|
if (typeof process < "u" && process?.versions?.node) try {
|
|
24306
24526
|
let e = i(import.meta.url);
|
|
24307
|
-
|
|
24527
|
+
Px = e("node:fs"), Fx = e("node:path");
|
|
24308
24528
|
} catch {}
|
|
24309
|
-
function
|
|
24529
|
+
function Ix(e, t = "") {
|
|
24310
24530
|
let n = e.split(/[\\/]/).pop() || "";
|
|
24311
24531
|
return t && n.endsWith(t) ? n.slice(0, -t.length) : n;
|
|
24312
24532
|
}
|
|
24313
|
-
function
|
|
24533
|
+
function Lx(e) {
|
|
24314
24534
|
let t = e.match(/\.[^.\\/]+$/);
|
|
24315
24535
|
return t ? t[0] : "";
|
|
24316
24536
|
}
|
|
24317
|
-
var
|
|
24537
|
+
var Rx = {
|
|
24318
24538
|
nodes: {},
|
|
24319
24539
|
trees: {},
|
|
24320
24540
|
blocks: {},
|
|
@@ -24324,10 +24544,10 @@ var Lx = {
|
|
|
24324
24544
|
nodeLayouts: {},
|
|
24325
24545
|
blockLayouts: {}
|
|
24326
24546
|
};
|
|
24327
|
-
function
|
|
24547
|
+
function zx(e) {
|
|
24328
24548
|
return e ? typeof e == "string" ? e.trim() : Array.isArray(e) ? e.includes("*") ? "*" : e : "*" : "*";
|
|
24329
24549
|
}
|
|
24330
|
-
function
|
|
24550
|
+
function Bx(e = {}, t = {}) {
|
|
24331
24551
|
let n = {
|
|
24332
24552
|
...e,
|
|
24333
24553
|
...t,
|
|
@@ -24339,62 +24559,62 @@ function zx(e = {}, t = {}) {
|
|
|
24339
24559
|
};
|
|
24340
24560
|
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;
|
|
24341
24561
|
}
|
|
24342
|
-
function
|
|
24562
|
+
function Vx(e) {
|
|
24343
24563
|
if (!e || typeof e != "object") return e;
|
|
24344
|
-
if (Array.isArray(e)) return e.map(
|
|
24564
|
+
if (Array.isArray(e)) return e.map(Vx);
|
|
24345
24565
|
let t = {};
|
|
24346
24566
|
for (let [n, r] of Object.entries(e)) if (n === "<<" || n === "<<:") {
|
|
24347
|
-
let e =
|
|
24567
|
+
let e = Vx(r);
|
|
24348
24568
|
if (typeof e == "object" && e) {
|
|
24349
24569
|
if (Array.isArray(e)) for (let n of e) Object.assign(t, n);
|
|
24350
24570
|
else Object.assign(t, e);
|
|
24351
24571
|
}
|
|
24352
|
-
} else t[n] =
|
|
24572
|
+
} else t[n] = Vx(r);
|
|
24353
24573
|
return t;
|
|
24354
24574
|
}
|
|
24355
|
-
function
|
|
24356
|
-
return e ?
|
|
24575
|
+
function Hx(e, t) {
|
|
24576
|
+
return e ? Vx(n.parseDocument(e, { customTags: [{
|
|
24357
24577
|
tag: "!include",
|
|
24358
24578
|
resolve(e) {
|
|
24359
|
-
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r =
|
|
24579
|
+
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim(), r = Ix(n);
|
|
24360
24580
|
if (!r) return n;
|
|
24361
24581
|
if (t && t.fieldSets) {
|
|
24362
24582
|
let e = Object.keys(t.fieldSets).find((e) => e.endsWith("/" + r) || e === r);
|
|
24363
|
-
if (e) return
|
|
24583
|
+
if (e) return Hx(t.fieldSets[e], t);
|
|
24364
24584
|
}
|
|
24365
24585
|
return n;
|
|
24366
24586
|
}
|
|
24367
24587
|
}] }).toJS() || {}) : {};
|
|
24368
24588
|
}
|
|
24369
|
-
function
|
|
24370
|
-
if (!
|
|
24371
|
-
let r =
|
|
24372
|
-
if (t.has(r) || (t.add(r), !
|
|
24373
|
-
let i =
|
|
24374
|
-
return
|
|
24589
|
+
function Ux(e, t = /* @__PURE__ */ new Set()) {
|
|
24590
|
+
if (!Px || !Fx) return {};
|
|
24591
|
+
let r = Fx.resolve(e);
|
|
24592
|
+
if (t.has(r) || (t.add(r), !Px.existsSync(r))) return {};
|
|
24593
|
+
let i = Px.readFileSync(r, "utf-8");
|
|
24594
|
+
return Vx(n.parseDocument(i, { customTags: [{
|
|
24375
24595
|
tag: "!include",
|
|
24376
24596
|
resolve(e) {
|
|
24377
24597
|
let n = (typeof e == "string" ? e : String(e?.strValue || e?.value || "")).trim();
|
|
24378
|
-
return n ?
|
|
24598
|
+
return n ? Ux(Fx.resolve(Fx.dirname(r), n), new Set(t)) : {};
|
|
24379
24599
|
}
|
|
24380
24600
|
}] }).toJS() || {});
|
|
24381
24601
|
}
|
|
24382
|
-
function
|
|
24383
|
-
if (!
|
|
24602
|
+
function Wx() {
|
|
24603
|
+
if (!Px || !Fx || typeof process > "u" || !process?.versions?.node) return null;
|
|
24384
24604
|
try {
|
|
24385
24605
|
let e = process.cwd(), t = "", n = [
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
|
|
24606
|
+
Fx.resolve(e, "content/definitions"),
|
|
24607
|
+
Fx.resolve(e, "content"),
|
|
24608
|
+
Fx.resolve(e, "definitions"),
|
|
24609
|
+
Fx.resolve(e, "kama-worker/content/definitions")
|
|
24390
24610
|
];
|
|
24391
24611
|
try {
|
|
24392
24612
|
if (import.meta.url) {
|
|
24393
|
-
let e =
|
|
24394
|
-
n.push(
|
|
24613
|
+
let e = Fx.dirname(r(import.meta.url));
|
|
24614
|
+
n.push(Fx.resolve(e, "../../content/definitions")), n.push(Fx.resolve(e, "../content/definitions"));
|
|
24395
24615
|
}
|
|
24396
24616
|
} catch {}
|
|
24397
|
-
for (let e of n) if (
|
|
24617
|
+
for (let e of n) if (Px.existsSync(e)) {
|
|
24398
24618
|
t = e;
|
|
24399
24619
|
break;
|
|
24400
24620
|
}
|
|
@@ -24402,19 +24622,19 @@ function Ux() {
|
|
|
24402
24622
|
let i = (e) => {
|
|
24403
24623
|
let n = "";
|
|
24404
24624
|
for (let r of e) {
|
|
24405
|
-
let e =
|
|
24406
|
-
if (
|
|
24625
|
+
let e = Fx.join(t, r);
|
|
24626
|
+
if (Px.existsSync(e)) {
|
|
24407
24627
|
n = e;
|
|
24408
24628
|
break;
|
|
24409
24629
|
}
|
|
24410
24630
|
}
|
|
24411
24631
|
if (!n) return {};
|
|
24412
|
-
let r = {}, i =
|
|
24632
|
+
let r = {}, i = Px.readdirSync(n);
|
|
24413
24633
|
for (let e of i) {
|
|
24414
24634
|
if (!e.endsWith(".yaml") && !e.endsWith(".yml")) continue;
|
|
24415
|
-
let t =
|
|
24635
|
+
let t = Fx.join(n, e), i = Ix(e, Lx(e));
|
|
24416
24636
|
try {
|
|
24417
|
-
r[i] =
|
|
24637
|
+
r[i] = Ux(t);
|
|
24418
24638
|
} catch (t) {
|
|
24419
24639
|
console.error(`❌ Error parsing ${e}:`, t.message);
|
|
24420
24640
|
}
|
|
@@ -24443,59 +24663,59 @@ function Ux() {
|
|
|
24443
24663
|
return console.error("❌ Exception inside readLocalFsBundle:", e), null;
|
|
24444
24664
|
}
|
|
24445
24665
|
}
|
|
24446
|
-
var
|
|
24447
|
-
function Kx(e) {
|
|
24448
|
-
if (!e) Wx = null, Gx = null;
|
|
24449
|
-
else if (Wx && Gx === e) return Wx;
|
|
24450
|
-
let t = qx(e);
|
|
24451
|
-
return Wx = t, Gx = e, t;
|
|
24452
|
-
}
|
|
24666
|
+
var Gx = null, Kx = null;
|
|
24453
24667
|
function qx(e) {
|
|
24668
|
+
if (!e) Gx = null, Kx = null;
|
|
24669
|
+
else if (Gx && Kx === e) return Gx;
|
|
24670
|
+
let t = Jx(e);
|
|
24671
|
+
return Gx = t, Kx = e, t;
|
|
24672
|
+
}
|
|
24673
|
+
function Jx(e) {
|
|
24454
24674
|
if (e) {
|
|
24455
24675
|
let t = {
|
|
24456
24676
|
nodes: {
|
|
24457
24677
|
...e.nodes || e.rawNodes || {},
|
|
24458
|
-
...
|
|
24678
|
+
...Rx.nodes
|
|
24459
24679
|
},
|
|
24460
24680
|
trees: {
|
|
24461
24681
|
...e.trees || e.rawTrees || {},
|
|
24462
|
-
...
|
|
24682
|
+
...Rx.trees
|
|
24463
24683
|
},
|
|
24464
24684
|
channels: {
|
|
24465
24685
|
...e.channels || e.rawChannels || {},
|
|
24466
|
-
...
|
|
24686
|
+
...Rx.channels
|
|
24467
24687
|
},
|
|
24468
24688
|
taxonomies: {
|
|
24469
24689
|
...e.taxonomies || e.rawTaxonomies || {},
|
|
24470
|
-
...
|
|
24690
|
+
...Rx.taxonomies
|
|
24471
24691
|
},
|
|
24472
24692
|
blocks: {
|
|
24473
24693
|
...e.blocks || e.rawBlocks || {},
|
|
24474
|
-
...
|
|
24694
|
+
...Rx.blocks
|
|
24475
24695
|
},
|
|
24476
24696
|
nodeLayouts: {
|
|
24477
24697
|
...e.nodeLayouts || e.rawNodeLayouts || {},
|
|
24478
|
-
...
|
|
24698
|
+
...Rx.nodeLayouts
|
|
24479
24699
|
},
|
|
24480
24700
|
blockLayouts: {
|
|
24481
24701
|
...e.blockLayouts || e.rawBlockLayouts || {},
|
|
24482
|
-
...
|
|
24702
|
+
...Rx.blockLayouts
|
|
24483
24703
|
},
|
|
24484
24704
|
fieldSets: {
|
|
24485
24705
|
...e.fieldSets || e.rawFieldSets || {},
|
|
24486
|
-
...
|
|
24706
|
+
...Rx.fieldSets
|
|
24487
24707
|
}
|
|
24488
24708
|
};
|
|
24489
24709
|
if (typeof Object.values(t.nodes)[0] == "string") {
|
|
24490
24710
|
let e = (e) => {
|
|
24491
24711
|
let n = {};
|
|
24492
24712
|
for (let [r, i] of Object.entries(e || {})) {
|
|
24493
|
-
let e =
|
|
24494
|
-
n[e] =
|
|
24713
|
+
let e = Ix(r, Lx(r));
|
|
24714
|
+
n[e] = Hx(i, t);
|
|
24495
24715
|
}
|
|
24496
24716
|
return n;
|
|
24497
24717
|
};
|
|
24498
|
-
return
|
|
24718
|
+
return Yx({
|
|
24499
24719
|
rawNodes: e(t.nodes),
|
|
24500
24720
|
rawTrees: e(t.trees),
|
|
24501
24721
|
rawChannels: e(t.channels),
|
|
@@ -24506,12 +24726,12 @@ function qx(e) {
|
|
|
24506
24726
|
rawFieldSets: e(t.fieldSets)
|
|
24507
24727
|
});
|
|
24508
24728
|
}
|
|
24509
|
-
return
|
|
24729
|
+
return Yx(t);
|
|
24510
24730
|
}
|
|
24511
|
-
let t =
|
|
24512
|
-
return t && Object.keys(t.rawNodes || {}).length > 0 ?
|
|
24731
|
+
let t = Wx();
|
|
24732
|
+
return t && Object.keys(t.rawNodes || {}).length > 0 ? Yx(t) : Yx(null);
|
|
24513
24733
|
}
|
|
24514
|
-
function
|
|
24734
|
+
function Yx(e) {
|
|
24515
24735
|
if (!e) return {
|
|
24516
24736
|
nodes: {},
|
|
24517
24737
|
trees: {},
|
|
@@ -24526,16 +24746,16 @@ function Jx(e) {
|
|
|
24526
24746
|
channelTemplate: null,
|
|
24527
24747
|
userTemplate: null
|
|
24528
24748
|
};
|
|
24529
|
-
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,
|
|
24749
|
+
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 = {
|
|
24530
24750
|
...p,
|
|
24531
24751
|
...f
|
|
24532
|
-
},
|
|
24752
|
+
}, k = (e, t = "settings", n, r) => {
|
|
24533
24753
|
let i = {};
|
|
24534
24754
|
if (!e) return i;
|
|
24535
24755
|
let a = (e) => {
|
|
24536
|
-
let a =
|
|
24756
|
+
let a = O[e] || O[`${e}-base`] || {};
|
|
24537
24757
|
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));
|
|
24538
|
-
let o = a.fields || a, s =
|
|
24758
|
+
let o = a.fields || a, s = k(o, t, n, r);
|
|
24539
24759
|
if (a.tab && n) {
|
|
24540
24760
|
let t = a.tab.id || e, r = a.tab.label || a.label || t;
|
|
24541
24761
|
n[t] || (n[t] = {
|
|
@@ -24543,11 +24763,11 @@ function Jx(e) {
|
|
|
24543
24763
|
fields: {}
|
|
24544
24764
|
}), Object.entries(s).forEach(([e, r]) => {
|
|
24545
24765
|
let i = n[t].fields[e] || {};
|
|
24546
|
-
n[t].fields[e] =
|
|
24766
|
+
n[t].fields[e] = Bx(i, r);
|
|
24547
24767
|
});
|
|
24548
24768
|
} else Object.entries(s).forEach(([e, t]) => {
|
|
24549
24769
|
let n = i[e] || {};
|
|
24550
|
-
i[e] =
|
|
24770
|
+
i[e] = Bx(n, t);
|
|
24551
24771
|
});
|
|
24552
24772
|
};
|
|
24553
24773
|
return !Array.isArray(e) && typeof e == "object" && e ? (Object.entries(e).forEach(([e, t]) => {
|
|
@@ -24556,15 +24776,15 @@ function Jx(e) {
|
|
|
24556
24776
|
a(String(t));
|
|
24557
24777
|
return;
|
|
24558
24778
|
}
|
|
24559
|
-
let n = i[e] ||
|
|
24560
|
-
i[e] =
|
|
24779
|
+
let n = i[e] || ne[e] || {};
|
|
24780
|
+
i[e] = Bx(n, typeof t == "object" && t ? t : { label: String(t) });
|
|
24561
24781
|
}), i) : (Array.isArray(e) && e.forEach((e) => {
|
|
24562
24782
|
if (typeof e == "string") {
|
|
24563
24783
|
if (e.includes("/") || e.endsWith(".yaml") || e.endsWith(".yml")) return;
|
|
24564
24784
|
if (e.startsWith("fieldSet:")) a(e.replace("fieldSet:", "").trim());
|
|
24565
24785
|
else {
|
|
24566
|
-
let t = i[e] ||
|
|
24567
|
-
i[e] =
|
|
24786
|
+
let t = i[e] || ne[e] || {};
|
|
24787
|
+
i[e] = Bx(t, {
|
|
24568
24788
|
type: "text",
|
|
24569
24789
|
label: e
|
|
24570
24790
|
});
|
|
@@ -24572,26 +24792,26 @@ function Jx(e) {
|
|
|
24572
24792
|
} else typeof e == "object" && e && Object.entries(e).forEach(([e, t]) => {
|
|
24573
24793
|
if (e === "fieldSet") a(String(t));
|
|
24574
24794
|
else if (e !== "<<" && e !== "<<:") {
|
|
24575
|
-
let n = i[e] ||
|
|
24576
|
-
i[e] =
|
|
24795
|
+
let n = i[e] || ne[e] || {};
|
|
24796
|
+
i[e] = Bx(n, typeof t == "object" && t ? t : {});
|
|
24577
24797
|
}
|
|
24578
24798
|
});
|
|
24579
24799
|
}), i);
|
|
24580
|
-
},
|
|
24800
|
+
}, A = (e, t) => {
|
|
24581
24801
|
let n = {};
|
|
24582
24802
|
return !e || typeof e != "object" ? n : Array.isArray(e) ? (e.forEach((e) => {
|
|
24583
24803
|
if (typeof e == "object" && e.fieldSet) {
|
|
24584
|
-
let r = String(e.fieldSet), i =
|
|
24804
|
+
let r = String(e.fieldSet), i = O[r] || O[`${r}-base`] || {};
|
|
24585
24805
|
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));
|
|
24586
24806
|
let a = i.tab?.id || r, o = i.tab?.label || i.label || a;
|
|
24587
24807
|
n[a] || (n[a] = {
|
|
24588
24808
|
label: o,
|
|
24589
24809
|
fields: {}
|
|
24590
24810
|
});
|
|
24591
|
-
let s =
|
|
24811
|
+
let s = k(i.fields || i, a, n, t);
|
|
24592
24812
|
Object.entries(s).forEach(([e, t]) => {
|
|
24593
24813
|
let r = n[a].fields[e] || {};
|
|
24594
|
-
n[a].fields[e] =
|
|
24814
|
+
n[a].fields[e] = Bx(r, t);
|
|
24595
24815
|
});
|
|
24596
24816
|
}
|
|
24597
24817
|
}), n) : (Object.entries(e).forEach(([e, r]) => {
|
|
@@ -24603,21 +24823,21 @@ function Jx(e) {
|
|
|
24603
24823
|
label: i,
|
|
24604
24824
|
fields: {}
|
|
24605
24825
|
});
|
|
24606
|
-
let s =
|
|
24826
|
+
let s = k(o, e, n, t);
|
|
24607
24827
|
Object.entries(s).forEach(([t, r]) => {
|
|
24608
24828
|
if (t === "<<" || t === "<<:" || t === "label") return;
|
|
24609
24829
|
let i = n[e].fields[t] || {};
|
|
24610
|
-
n[e].fields[t] =
|
|
24830
|
+
n[e].fields[t] = Bx(i, r);
|
|
24611
24831
|
});
|
|
24612
24832
|
}), n);
|
|
24613
|
-
},
|
|
24833
|
+
}, re = {};
|
|
24614
24834
|
Object.entries(C).forEach(([e, t]) => {
|
|
24615
24835
|
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));
|
|
24616
|
-
let n =
|
|
24836
|
+
let n = A(t.tabs, t), r = k(t.fields || [], "settings", n, t);
|
|
24617
24837
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24618
|
-
let i =
|
|
24838
|
+
let i = O[e] || O[`${e}-base`] || {};
|
|
24619
24839
|
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);
|
|
24620
|
-
let a = i.fields || i, o =
|
|
24840
|
+
let a = i.fields || i, o = k(a, "settings", n, t);
|
|
24621
24841
|
if (i.tab) {
|
|
24622
24842
|
let t = i.tab.id || e, r = i.tab.label || i.label || t;
|
|
24623
24843
|
n[t] || (n[t] = {
|
|
@@ -24625,21 +24845,21 @@ function Jx(e) {
|
|
|
24625
24845
|
fields: {}
|
|
24626
24846
|
}), Object.entries(o).forEach(([e, r]) => {
|
|
24627
24847
|
let i = n[t].fields[e] || {};
|
|
24628
|
-
n[t].fields[e] =
|
|
24848
|
+
n[t].fields[e] = Bx(i, r);
|
|
24629
24849
|
});
|
|
24630
24850
|
} else Object.entries(o).forEach(([e, t]) => {
|
|
24631
|
-
let n = r[e] ||
|
|
24632
|
-
r[e] =
|
|
24851
|
+
let n = r[e] || ne[e] || {};
|
|
24852
|
+
r[e] = Bx(n, t);
|
|
24633
24853
|
});
|
|
24634
24854
|
}), Object.values(n).forEach((e) => {
|
|
24635
24855
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24636
24856
|
let n = r[e] || {};
|
|
24637
|
-
r[e] =
|
|
24857
|
+
r[e] = Bx(n, t);
|
|
24638
24858
|
});
|
|
24639
24859
|
}), Object.keys(n).length === 0 && Object.keys(r).length > 0 && (n.settings = {
|
|
24640
24860
|
label: t.label || "Settings",
|
|
24641
24861
|
fields: r
|
|
24642
|
-
}),
|
|
24862
|
+
}), re[e] = {
|
|
24643
24863
|
...t,
|
|
24644
24864
|
id: t.id || e,
|
|
24645
24865
|
label: t.label || e,
|
|
@@ -24647,25 +24867,25 @@ function Jx(e) {
|
|
|
24647
24867
|
inVault: t.inVault !== !1,
|
|
24648
24868
|
hasCanvas: t.hasCanvas === !0,
|
|
24649
24869
|
defaultLayout: t.defaultLayout,
|
|
24650
|
-
allowedBlocks:
|
|
24651
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24870
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24871
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0,
|
|
24652
24872
|
tabs: n,
|
|
24653
24873
|
fields: r
|
|
24654
24874
|
};
|
|
24655
24875
|
});
|
|
24656
|
-
let
|
|
24657
|
-
Object.entries(
|
|
24658
|
-
let n =
|
|
24876
|
+
let ie = {};
|
|
24877
|
+
Object.entries(ee).forEach(([e, t]) => {
|
|
24878
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24659
24879
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24660
|
-
let t =
|
|
24880
|
+
let t = O[e] || {}, i = t.fields || t, a = k(i, "settings", n);
|
|
24661
24881
|
Object.entries(a).forEach(([e, t]) => {
|
|
24662
|
-
r[e] =
|
|
24882
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24663
24883
|
});
|
|
24664
24884
|
}), Object.values(n).forEach((e) => {
|
|
24665
24885
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24666
|
-
r[e] =
|
|
24886
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24667
24887
|
});
|
|
24668
|
-
}),
|
|
24888
|
+
}), ie[e] = {
|
|
24669
24889
|
...t,
|
|
24670
24890
|
id: t.id || e,
|
|
24671
24891
|
label: t.label || e,
|
|
@@ -24673,19 +24893,19 @@ function Jx(e) {
|
|
|
24673
24893
|
fields: r
|
|
24674
24894
|
};
|
|
24675
24895
|
});
|
|
24676
|
-
let
|
|
24677
|
-
Object.entries(
|
|
24678
|
-
let n =
|
|
24896
|
+
let ae = {};
|
|
24897
|
+
Object.entries(w).forEach(([e, t]) => {
|
|
24898
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24679
24899
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24680
|
-
let t =
|
|
24900
|
+
let t = O[e] || {}, n = t.fields || t, i = k(n);
|
|
24681
24901
|
Object.entries(i).forEach(([e, t]) => {
|
|
24682
|
-
r[e] =
|
|
24902
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24683
24903
|
});
|
|
24684
24904
|
}), Object.values(n).forEach((e) => {
|
|
24685
24905
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24686
|
-
r[e] =
|
|
24906
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24687
24907
|
});
|
|
24688
|
-
}),
|
|
24908
|
+
}), ae[e] = {
|
|
24689
24909
|
...t,
|
|
24690
24910
|
id: t.id || e,
|
|
24691
24911
|
label: t.label || e,
|
|
@@ -24694,19 +24914,19 @@ function Jx(e) {
|
|
|
24694
24914
|
fields: r
|
|
24695
24915
|
};
|
|
24696
24916
|
});
|
|
24697
|
-
let
|
|
24698
|
-
Object.entries(
|
|
24699
|
-
let n =
|
|
24917
|
+
let oe = {};
|
|
24918
|
+
Object.entries(T).forEach(([e, t]) => {
|
|
24919
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n);
|
|
24700
24920
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24701
|
-
let t =
|
|
24921
|
+
let t = O[e] || {}, i = t.fields || t, a = k(i, "settings", n);
|
|
24702
24922
|
Object.entries(a).forEach(([e, t]) => {
|
|
24703
|
-
r[e] =
|
|
24923
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24704
24924
|
});
|
|
24705
24925
|
}), Object.values(n).forEach((e) => {
|
|
24706
24926
|
Object.entries(e.fields).forEach(([e, t]) => {
|
|
24707
|
-
r[e] =
|
|
24927
|
+
r[e] = Bx(r[e] || {}, t);
|
|
24708
24928
|
});
|
|
24709
|
-
}),
|
|
24929
|
+
}), oe[e] = {
|
|
24710
24930
|
...t,
|
|
24711
24931
|
id: t.id || e,
|
|
24712
24932
|
label: t.label || e,
|
|
@@ -24715,15 +24935,15 @@ function Jx(e) {
|
|
|
24715
24935
|
fields: r
|
|
24716
24936
|
};
|
|
24717
24937
|
});
|
|
24718
|
-
let
|
|
24938
|
+
let se = {};
|
|
24719
24939
|
Object.entries(E).forEach(([e, t]) => {
|
|
24720
|
-
let n =
|
|
24940
|
+
let n = k(t.fields || []);
|
|
24721
24941
|
Array.isArray(t.fieldSets) && t.fieldSets.forEach((e) => {
|
|
24722
|
-
let t =
|
|
24942
|
+
let t = O[e] || {}, r = t.fields || t, i = k(r);
|
|
24723
24943
|
Object.entries(i).forEach(([e, t]) => {
|
|
24724
|
-
n[e] =
|
|
24944
|
+
n[e] = Bx(n[e] || {}, t);
|
|
24725
24945
|
});
|
|
24726
|
-
}),
|
|
24946
|
+
}), se[e] = {
|
|
24727
24947
|
...t,
|
|
24728
24948
|
id: t.id || e,
|
|
24729
24949
|
label: t.label || e,
|
|
@@ -24731,17 +24951,17 @@ function Jx(e) {
|
|
|
24731
24951
|
fields: n
|
|
24732
24952
|
};
|
|
24733
24953
|
});
|
|
24734
|
-
let
|
|
24954
|
+
let ce = {};
|
|
24735
24955
|
Object.entries(D).forEach(([e, t]) => {
|
|
24736
|
-
let n =
|
|
24956
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { content: { label: "Content" } };
|
|
24737
24957
|
Object.entries(a).forEach(([e, t]) => {
|
|
24738
24958
|
i[e] = {
|
|
24739
24959
|
...t,
|
|
24740
24960
|
label: t.label || e,
|
|
24741
|
-
allowedBlocks:
|
|
24742
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24961
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24962
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0
|
|
24743
24963
|
};
|
|
24744
|
-
}),
|
|
24964
|
+
}), ce[e] = {
|
|
24745
24965
|
...t,
|
|
24746
24966
|
id: t.id || e,
|
|
24747
24967
|
label: t.label || e,
|
|
@@ -24754,17 +24974,17 @@ function Jx(e) {
|
|
|
24754
24974
|
tabs: n
|
|
24755
24975
|
};
|
|
24756
24976
|
});
|
|
24757
|
-
let
|
|
24977
|
+
let le = {};
|
|
24758
24978
|
Object.entries(te).forEach(([e, t]) => {
|
|
24759
|
-
let n =
|
|
24979
|
+
let n = A(t.tabs), r = k(t.fields || [], "settings", n), i = {}, a = t.regions || { main: { label: "Main Content" } };
|
|
24760
24980
|
Object.entries(a).forEach(([e, t]) => {
|
|
24761
24981
|
i[e] = {
|
|
24762
24982
|
...t,
|
|
24763
24983
|
label: t.label || e,
|
|
24764
|
-
allowedBlocks:
|
|
24765
|
-
disallowedBlocks: t.disallowedBlocks ?
|
|
24984
|
+
allowedBlocks: zx(t.allowedBlocks),
|
|
24985
|
+
disallowedBlocks: t.disallowedBlocks ? zx(t.disallowedBlocks) : void 0
|
|
24766
24986
|
};
|
|
24767
|
-
}),
|
|
24987
|
+
}), le[e] = {
|
|
24768
24988
|
...t,
|
|
24769
24989
|
id: t.id || e,
|
|
24770
24990
|
label: t.label || e,
|
|
@@ -24777,21 +24997,21 @@ function Jx(e) {
|
|
|
24777
24997
|
tabs: n
|
|
24778
24998
|
};
|
|
24779
24999
|
});
|
|
24780
|
-
let
|
|
25000
|
+
let j = g?.fields || {};
|
|
24781
25001
|
Array.isArray(g?.fieldSets) && g?.fieldSets.forEach((e) => {
|
|
24782
|
-
let t =
|
|
25002
|
+
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
24783
25003
|
Object.entries(r).forEach(([e, t]) => {
|
|
24784
|
-
|
|
25004
|
+
j[e] = Bx(j[e] || {}, t);
|
|
24785
25005
|
});
|
|
24786
25006
|
});
|
|
24787
25007
|
let ue = g ? {
|
|
24788
25008
|
...g,
|
|
24789
|
-
fields:
|
|
25009
|
+
fields: j
|
|
24790
25010
|
} : null, de = _?.fields || {};
|
|
24791
25011
|
Array.isArray(_?.fieldSets) && _?.fieldSets.forEach((e) => {
|
|
24792
|
-
let t =
|
|
25012
|
+
let t = O[e] || {}, n = t.fields || t, r = k(n);
|
|
24793
25013
|
Object.entries(r).forEach(([e, t]) => {
|
|
24794
|
-
de[e] =
|
|
25014
|
+
de[e] = Bx(de[e] || {}, t);
|
|
24795
25015
|
});
|
|
24796
25016
|
});
|
|
24797
25017
|
let fe = _ ? {
|
|
@@ -24799,14 +25019,14 @@ function Jx(e) {
|
|
|
24799
25019
|
fields: de
|
|
24800
25020
|
} : null;
|
|
24801
25021
|
return {
|
|
24802
|
-
nodes:
|
|
24803
|
-
trees:
|
|
24804
|
-
channels:
|
|
24805
|
-
taxonomies:
|
|
24806
|
-
blocks:
|
|
24807
|
-
nodeLayouts:
|
|
24808
|
-
blockLayouts:
|
|
24809
|
-
fieldSets:
|
|
25022
|
+
nodes: re,
|
|
25023
|
+
trees: ie,
|
|
25024
|
+
channels: ae,
|
|
25025
|
+
taxonomies: oe,
|
|
25026
|
+
blocks: se,
|
|
25027
|
+
nodeLayouts: ce,
|
|
25028
|
+
blockLayouts: le,
|
|
25029
|
+
fieldSets: O,
|
|
24810
25030
|
nodeTemplate: m || null,
|
|
24811
25031
|
treeTemplate: h || null,
|
|
24812
25032
|
channelTemplate: ue,
|
|
@@ -24815,11 +25035,11 @@ function Jx(e) {
|
|
|
24815
25035
|
}
|
|
24816
25036
|
//#endregion
|
|
24817
25037
|
//#region server/routes/admin/schemas.ts
|
|
24818
|
-
var
|
|
25038
|
+
var Xx = new e(), Zx = (e) => {
|
|
24819
25039
|
try {
|
|
24820
25040
|
let t = e.env?.BUNDLED_DEFINITIONS;
|
|
24821
25041
|
(!t || Object.keys(t).length === 0) && (t = Db || Eb || Tb);
|
|
24822
|
-
let n =
|
|
25042
|
+
let n = qx(t);
|
|
24823
25043
|
return e.json(n, 200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
24824
25044
|
} catch (t) {
|
|
24825
25045
|
return console.error("[CMS API] Error loading schemas:", t), e.json({
|
|
@@ -24828,10 +25048,10 @@ var Yx = new e(), Xx = (e) => {
|
|
|
24828
25048
|
}, 500);
|
|
24829
25049
|
}
|
|
24830
25050
|
};
|
|
24831
|
-
|
|
25051
|
+
Xx.get("/", Zx), Xx.get("/schemas.json", Zx);
|
|
24832
25052
|
//#endregion
|
|
24833
25053
|
//#region server/routes/admin/validation.ts
|
|
24834
|
-
var
|
|
25054
|
+
var Qx = new e(), $x = {
|
|
24835
25055
|
node: "content_nodes",
|
|
24836
25056
|
nodes: "content_nodes",
|
|
24837
25057
|
content_node: "content_nodes",
|
|
@@ -24843,7 +25063,7 @@ var Zx = new e(), Qx = {
|
|
|
24843
25063
|
user: "users",
|
|
24844
25064
|
users: "users",
|
|
24845
25065
|
user_account: "user_accounts"
|
|
24846
|
-
},
|
|
25066
|
+
}, eS = {
|
|
24847
25067
|
content_nodes: [
|
|
24848
25068
|
"id",
|
|
24849
25069
|
"title",
|
|
@@ -24900,11 +25120,11 @@ var Zx = new e(), Qx = {
|
|
|
24900
25120
|
"createdAt"
|
|
24901
25121
|
]
|
|
24902
25122
|
};
|
|
24903
|
-
|
|
25123
|
+
Qx.post("/validate-unique", async (e) => {
|
|
24904
25124
|
try {
|
|
24905
25125
|
let t = e.get("db"), { entityType: n, field: r, value: i, excludeId: a } = await e.req.json();
|
|
24906
25126
|
if (!r || i == null || String(i).trim() === "") return e.json({ isUnique: !0 });
|
|
24907
|
-
let o =
|
|
25127
|
+
let o = $x[n] || "content_nodes", s = r.replace(/[^a-zA-Z0-9_]/g, ""), c = (eS[o] || eS.content_nodes).includes(s), l = -1;
|
|
24908
25128
|
if (a != null && String(a).trim() !== "") {
|
|
24909
25129
|
let e = Number(a);
|
|
24910
25130
|
l = isNaN(e) ? String(a) : e;
|
|
@@ -24916,11 +25136,11 @@ Zx.post("/validate-unique", async (e) => {
|
|
|
24916
25136
|
} catch (t) {
|
|
24917
25137
|
return console.error("[API Validation] Error validating global uniqueness:", t), e.json({ error: "Failed to validate uniqueness" }, 500);
|
|
24918
25138
|
}
|
|
24919
|
-
}),
|
|
25139
|
+
}), Qx.post("/validate-unique-sibling", async (e) => e.json({ isUnique: !0 }));
|
|
24920
25140
|
//#endregion
|
|
24921
25141
|
//#region server/routes/admin/stats.ts
|
|
24922
|
-
var
|
|
24923
|
-
|
|
25142
|
+
var tS = new e();
|
|
25143
|
+
tS.get("/", async (e) => {
|
|
24924
25144
|
try {
|
|
24925
25145
|
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) => ({
|
|
24926
25146
|
...e,
|
|
@@ -24965,8 +25185,8 @@ eS.get("/", async (e) => {
|
|
|
24965
25185
|
});
|
|
24966
25186
|
//#endregion
|
|
24967
25187
|
//#region server/routes/admin/assets.ts
|
|
24968
|
-
var
|
|
24969
|
-
async function
|
|
25188
|
+
var nS = new e();
|
|
25189
|
+
async function rS(e, t, n = []) {
|
|
24970
25190
|
let r = e.prepare(t);
|
|
24971
25191
|
if (typeof r.bind == "function") {
|
|
24972
25192
|
let e = await r.bind(...n).all();
|
|
@@ -24978,16 +25198,16 @@ async function nS(e, t, n = []) {
|
|
|
24978
25198
|
}
|
|
24979
25199
|
return [];
|
|
24980
25200
|
}
|
|
24981
|
-
async function
|
|
25201
|
+
async function iS(e, t, n = []) {
|
|
24982
25202
|
let r = e.prepare(t);
|
|
24983
25203
|
if (typeof r.bind == "function") return await r.bind(...n).run();
|
|
24984
25204
|
if (typeof r.run == "function") return await r.run(...n);
|
|
24985
25205
|
}
|
|
24986
|
-
function
|
|
25206
|
+
function aS(e, t, n) {
|
|
24987
25207
|
let r = e || (t ? `/media/${t}` : "");
|
|
24988
25208
|
return r && n && r.startsWith(`https://${n}/`) && !r.includes("/media/") && (r = r.replace(`https://${n}/`, `https://${n}/media/`)), r;
|
|
24989
25209
|
}
|
|
24990
|
-
|
|
25210
|
+
nS.get("/", async (e) => {
|
|
24991
25211
|
try {
|
|
24992
25212
|
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 = {
|
|
24993
25213
|
createdAt: "a.createdAt",
|
|
@@ -24997,7 +25217,7 @@ tS.get("/", async (e) => {
|
|
|
24997
25217
|
sizeBytes: "a.sizeBytes"
|
|
24998
25218
|
}[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 = '')"];
|
|
24999
25219
|
if (c) {
|
|
25000
|
-
let e = await
|
|
25220
|
+
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)]);
|
|
25001
25221
|
if (e.length === 0) _.push("1 = 0");
|
|
25002
25222
|
else {
|
|
25003
25223
|
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 ");
|
|
@@ -25011,10 +25231,10 @@ tS.get("/", async (e) => {
|
|
|
25011
25231
|
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/%")));
|
|
25012
25232
|
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 ?`;
|
|
25013
25233
|
g.push(f, p);
|
|
25014
|
-
let y = await
|
|
25234
|
+
let y = await rS(t, v, g), b = y.map((e) => e.id), x = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map();
|
|
25015
25235
|
if (b.length > 0) {
|
|
25016
25236
|
let e = b.map(() => "?").join(",");
|
|
25017
|
-
(await
|
|
25237
|
+
(await rS(t, `
|
|
25018
25238
|
SELECT master.id AS assetId, COUNT(DISTINCT na.nodeId) AS count
|
|
25019
25239
|
FROM assets master
|
|
25020
25240
|
INNER JOIN node_assets na ON (
|
|
@@ -25022,7 +25242,7 @@ tS.get("/", async (e) => {
|
|
|
25022
25242
|
EXISTS (SELECT 1 FROM assets crop WHERE crop.id = na.assetId AND crop.isSystemVariant = 1 AND crop.parentAssetId = master.id)
|
|
25023
25243
|
)
|
|
25024
25244
|
WHERE master.id IN (${e})
|
|
25025
|
-
GROUP BY master.id`, b)).forEach((e) => x.set(String(e.assetId), e.count || 0)), (await
|
|
25245
|
+
GROUP BY master.id`, b)).forEach((e) => x.set(String(e.assetId), e.count || 0)), (await rS(t, `
|
|
25026
25246
|
SELECT parentAssetId, COUNT(id) AS count
|
|
25027
25247
|
FROM assets
|
|
25028
25248
|
WHERE isSystemVariant = 1 AND parentAssetId IN (${e})
|
|
@@ -25040,7 +25260,7 @@ tS.get("/", async (e) => {
|
|
|
25040
25260
|
...JSON.parse(t.dataJson || "{}")
|
|
25041
25261
|
};
|
|
25042
25262
|
} catch {}
|
|
25043
|
-
let r =
|
|
25263
|
+
let r = aS(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
25044
25264
|
return {
|
|
25045
25265
|
id: t.id,
|
|
25046
25266
|
filename: t.filename || "Untitled Asset",
|
|
@@ -25065,7 +25285,7 @@ tS.get("/", async (e) => {
|
|
|
25065
25285
|
details: t.message || String(t)
|
|
25066
25286
|
}, 500);
|
|
25067
25287
|
}
|
|
25068
|
-
}),
|
|
25288
|
+
}), nS.post("/upload", async (e) => {
|
|
25069
25289
|
try {
|
|
25070
25290
|
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;
|
|
25071
25291
|
if (!i || !(i instanceof File)) return e.json({ error: "No file uploaded" }, 400);
|
|
@@ -25080,14 +25300,14 @@ tS.get("/", async (e) => {
|
|
|
25080
25300
|
}
|
|
25081
25301
|
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}`;
|
|
25082
25302
|
if (!v) throw Error("Storage provider failed to return a valid storage key");
|
|
25083
|
-
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,
|
|
25084
|
-
|
|
25085
|
-
let
|
|
25303
|
+
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;
|
|
25304
|
+
w && (await rS(t, "SELECT id FROM users WHERE id = ?", [w])).length === 0 && (w = null);
|
|
25305
|
+
let T = new fx(e.env);
|
|
25086
25306
|
if (s) {
|
|
25087
|
-
let r = await
|
|
25307
|
+
let r = await rS(t, "SELECT storageKeyPrivate, isSystemVariant, parentAssetId FROM assets WHERE id = ?", [s]);
|
|
25088
25308
|
if (r.length > 0) {
|
|
25089
25309
|
let a = r[0];
|
|
25090
|
-
if (await
|
|
25310
|
+
if (await iS(t, "UPDATE assets SET filename = ?, mimeType = ?, sizeBytes = ?, storageKeyPrivate = ?, cdnUrl = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?", [
|
|
25091
25311
|
i.name,
|
|
25092
25312
|
S,
|
|
25093
25313
|
C,
|
|
@@ -25099,7 +25319,7 @@ tS.get("/", async (e) => {
|
|
|
25099
25319
|
} catch (e) {
|
|
25100
25320
|
console.warn("Failed to cleanup old asset", e);
|
|
25101
25321
|
}
|
|
25102
|
-
|
|
25322
|
+
T.purgeAsset(e, t, s);
|
|
25103
25323
|
let o = `${x}?v=${Date.now()}`;
|
|
25104
25324
|
return e.json({
|
|
25105
25325
|
id: s,
|
|
@@ -25116,22 +25336,22 @@ tS.get("/", async (e) => {
|
|
|
25116
25336
|
}
|
|
25117
25337
|
}
|
|
25118
25338
|
let E = `ast_${p}`, D = +!!h;
|
|
25119
|
-
await
|
|
25339
|
+
await iS(t, "INSERT INTO assets (id, filename, mimeType, sizeBytes, storageKeyPrivate, cdnUrl, createdById, isSystemVariant, parentAssetId, cropCoordinatesJson) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
25120
25340
|
E,
|
|
25121
25341
|
i.name,
|
|
25122
25342
|
S,
|
|
25123
25343
|
C,
|
|
25124
25344
|
v,
|
|
25125
25345
|
x,
|
|
25126
|
-
|
|
25346
|
+
w,
|
|
25127
25347
|
D,
|
|
25128
25348
|
l,
|
|
25129
25349
|
d
|
|
25130
25350
|
]);
|
|
25131
25351
|
let te = x;
|
|
25132
25352
|
if (l) {
|
|
25133
|
-
let n = await
|
|
25134
|
-
n.length > 0 && (te =
|
|
25353
|
+
let n = await rS(t, "SELECT cdnUrl, storageKeyPrivate FROM assets WHERE id = ?", [l]);
|
|
25354
|
+
n.length > 0 && (te = aS(n[0].cdnUrl, n[0].storageKeyPrivate, y)), T.purgeAsset(e, t, l);
|
|
25135
25355
|
}
|
|
25136
25356
|
return e.json({
|
|
25137
25357
|
id: E,
|
|
@@ -25150,11 +25370,11 @@ tS.get("/", async (e) => {
|
|
|
25150
25370
|
details: t.message || String(t)
|
|
25151
25371
|
}, 500);
|
|
25152
25372
|
}
|
|
25153
|
-
}),
|
|
25373
|
+
}), nS.get("/:id/details", async (e) => {
|
|
25154
25374
|
try {
|
|
25155
|
-
let t = wb(e), n = e.req.param("id"), r = await
|
|
25375
|
+
let t = wb(e), n = e.req.param("id"), r = await rS(t, "SELECT * FROM assets WHERE id = ?", [n]);
|
|
25156
25376
|
if (!r || r.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
25157
|
-
let i = r[0], a = await
|
|
25377
|
+
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 = {
|
|
25158
25378
|
title: "",
|
|
25159
25379
|
alt: "",
|
|
25160
25380
|
description: ""
|
|
@@ -25165,7 +25385,7 @@ tS.get("/", async (e) => {
|
|
|
25165
25385
|
...JSON.parse(i.dataJson || "{}")
|
|
25166
25386
|
};
|
|
25167
25387
|
} catch {}
|
|
25168
|
-
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), l = `${
|
|
25388
|
+
let c = i.updatedAt ? new Date(i.updatedAt).getTime() : Date.now(), l = `${aS(i.cdnUrl, i.storageKeyPrivate, e.env?.CDN_DOMAIN)}?v=${c}`;
|
|
25169
25389
|
return e.json({
|
|
25170
25390
|
id: i.id,
|
|
25171
25391
|
filename: i.filename,
|
|
@@ -25184,7 +25404,7 @@ tS.get("/", async (e) => {
|
|
|
25184
25404
|
if (t.cropCoordinatesJson) try {
|
|
25185
25405
|
n = JSON.parse(t.cropCoordinatesJson);
|
|
25186
25406
|
} catch {}
|
|
25187
|
-
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a =
|
|
25407
|
+
let r = t.updatedAt ? new Date(t.updatedAt).getTime() : c, a = aS(t.cdnUrl, t.storageKeyPrivate, e.env?.CDN_DOMAIN);
|
|
25188
25408
|
return {
|
|
25189
25409
|
id: t.id,
|
|
25190
25410
|
filename: t.filename,
|
|
@@ -25201,15 +25421,15 @@ tS.get("/", async (e) => {
|
|
|
25201
25421
|
} catch {
|
|
25202
25422
|
return e.json({ error: "Failed to load details" }, 500);
|
|
25203
25423
|
}
|
|
25204
|
-
}),
|
|
25424
|
+
}), nS.put("/:id", async (e) => {
|
|
25205
25425
|
try {
|
|
25206
|
-
let t = wb(e), n = e.req.param("id"), r = await e.req.json(), i = await
|
|
25426
|
+
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]);
|
|
25207
25427
|
if (!i || i.length === 0) return e.json({ error: "Asset not found" }, 404);
|
|
25208
25428
|
let a = i[0], o = {};
|
|
25209
25429
|
try {
|
|
25210
25430
|
o = JSON.parse(a.dataJson || "{}");
|
|
25211
25431
|
} catch {}
|
|
25212
|
-
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
|
|
25432
|
+
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 = ?", [
|
|
25213
25433
|
r.filename === void 0 ? a.filename : r.filename,
|
|
25214
25434
|
JSON.stringify(o),
|
|
25215
25435
|
n
|
|
@@ -25217,10 +25437,10 @@ tS.get("/", async (e) => {
|
|
|
25217
25437
|
} catch {
|
|
25218
25438
|
return e.json({ error: "Failed to update asset" }, 500);
|
|
25219
25439
|
}
|
|
25220
|
-
}),
|
|
25440
|
+
}), nS.delete("/:id", async (e) => {
|
|
25221
25441
|
try {
|
|
25222
|
-
let t = wb(e), n = e.req.param("id"), r = (await
|
|
25223
|
-
return r ? (new fx(e.env).purgeAsset(e, t, n), r.isSystemVariant ? await
|
|
25442
|
+
let t = wb(e), n = e.req.param("id"), r = (await rS(t, "SELECT id, filename, isSystemVariant FROM assets WHERE id = ?", [n]))[0];
|
|
25443
|
+
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({
|
|
25224
25444
|
success: !0,
|
|
25225
25445
|
id: n,
|
|
25226
25446
|
trashed: !0
|
|
@@ -25231,10 +25451,10 @@ tS.get("/", async (e) => {
|
|
|
25231
25451
|
details: t.message || String(t)
|
|
25232
25452
|
}, 500);
|
|
25233
25453
|
}
|
|
25234
|
-
}),
|
|
25454
|
+
}), nS.post("/restore", async (e) => {
|
|
25235
25455
|
try {
|
|
25236
25456
|
let t = wb(e), n = await e.req.json(), r = n.id || n.assetId;
|
|
25237
|
-
return r ? (await
|
|
25457
|
+
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({
|
|
25238
25458
|
success: !0,
|
|
25239
25459
|
id: r,
|
|
25240
25460
|
restored: !0
|
|
@@ -25245,13 +25465,13 @@ tS.get("/", async (e) => {
|
|
|
25245
25465
|
details: t.message
|
|
25246
25466
|
}, 500);
|
|
25247
25467
|
}
|
|
25248
|
-
}),
|
|
25468
|
+
}), nS.delete("/purge/:id", async (e) => {
|
|
25249
25469
|
try {
|
|
25250
|
-
let t = wb(e), { storage: n } = ix(e.env), r = e.req.param("id"), i = (await
|
|
25470
|
+
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];
|
|
25251
25471
|
if (!i) return e.json({ error: "Asset not found" }, 404);
|
|
25252
25472
|
new fx(e.env).purgeAsset(e, t, r);
|
|
25253
25473
|
let a = [i];
|
|
25254
|
-
i.isSystemVariant || (a = [i, ...await
|
|
25474
|
+
i.isSystemVariant || (a = [i, ...await rS(t, "SELECT id, storageKeyPrivate FROM assets WHERE isSystemVariant = 1 AND parentAssetId = ?", [r])]);
|
|
25255
25475
|
let o = a.map((e) => e.id);
|
|
25256
25476
|
if (typeof n.delete == "function") {
|
|
25257
25477
|
for (let e of a) if (e.storageKeyPrivate) try {
|
|
@@ -25261,7 +25481,7 @@ tS.get("/", async (e) => {
|
|
|
25261
25481
|
}
|
|
25262
25482
|
}
|
|
25263
25483
|
let s = o.map(() => "?").join(",");
|
|
25264
|
-
return await
|
|
25484
|
+
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({
|
|
25265
25485
|
success: !0,
|
|
25266
25486
|
id: r,
|
|
25267
25487
|
purged: !0,
|
|
@@ -25277,8 +25497,8 @@ tS.get("/", async (e) => {
|
|
|
25277
25497
|
});
|
|
25278
25498
|
//#endregion
|
|
25279
25499
|
//#region server/routes/public/node.ts
|
|
25280
|
-
var
|
|
25281
|
-
function
|
|
25500
|
+
var oS = new $y();
|
|
25501
|
+
function sS() {
|
|
25282
25502
|
return {
|
|
25283
25503
|
fullPath: /* @__PURE__ */ new Map(),
|
|
25284
25504
|
treeEdges: /* @__PURE__ */ new Map(),
|
|
@@ -25286,9 +25506,6 @@ function oS() {
|
|
|
25286
25506
|
assetUrls: /* @__PURE__ */ new Map()
|
|
25287
25507
|
};
|
|
25288
25508
|
}
|
|
25289
|
-
function sS(...e) {
|
|
25290
|
-
return e.map((e) => String(e ?? "")).join(":");
|
|
25291
|
-
}
|
|
25292
25509
|
function cS(e, t) {
|
|
25293
25510
|
let n = Date.now();
|
|
25294
25511
|
if (e && String(e).trim() !== "") {
|
|
@@ -25446,7 +25663,7 @@ function fS(e) {
|
|
|
25446
25663
|
}
|
|
25447
25664
|
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, fS(t)]));
|
|
25448
25665
|
}
|
|
25449
|
-
async function pS(e, t, n) {
|
|
25666
|
+
async function pS(e, t, n, r) {
|
|
25450
25667
|
if (typeof t == "string") {
|
|
25451
25668
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
25452
25669
|
let r = (e, t) => {
|
|
@@ -25456,78 +25673,48 @@ async function pS(e, t, n) {
|
|
|
25456
25673
|
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi)) i.add(e[1]);
|
|
25457
25674
|
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi)) a.add(e[1]);
|
|
25458
25675
|
if (i.size === 0 && a.size === 0) return t;
|
|
25459
|
-
let o =
|
|
25460
|
-
|
|
25461
|
-
|
|
25462
|
-
|
|
25463
|
-
|
|
25464
|
-
|
|
25465
|
-
|
|
25466
|
-
if (!a || !o) return;
|
|
25467
|
-
let s = await hS(e, a, o, n);
|
|
25468
|
-
if (s?.treeNodeId) {
|
|
25469
|
-
let t = await yS(e, String(s.treeNodeId), o, n);
|
|
25470
|
-
f.set(`${a}:${o}`, t);
|
|
25471
|
-
}
|
|
25472
|
-
})), t.replace(p, (e, t) => {
|
|
25676
|
+
let o = /* @__PURE__ */ new Map();
|
|
25677
|
+
if (i.size > 0) {
|
|
25678
|
+
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);
|
|
25679
|
+
(Array.isArray(r) ? r : r?.results || []).forEach((e) => o.set(String(e.nodeId), e.path));
|
|
25680
|
+
}
|
|
25681
|
+
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();
|
|
25682
|
+
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) => {
|
|
25473
25683
|
let n = r(t, "data-node-id"), i = r(t, "data-asset-id"), a = r(t, "href") || "";
|
|
25474
25684
|
if (a.startsWith("mailto:")) return `<a ${t.replace(/\s+target\s*=\s*["'][^"']*["']/i, "")}>`;
|
|
25475
|
-
let
|
|
25476
|
-
if (!
|
|
25477
|
-
if (
|
|
25478
|
-
let n =
|
|
25685
|
+
let s = i || a.match(/^#asset:(.+)$/i)?.[1], c = n || a.match(/^#node:(.+)$/i)?.[1];
|
|
25686
|
+
if (!c && !s) return e;
|
|
25687
|
+
if (s && !c) {
|
|
25688
|
+
let n = l.get(s);
|
|
25479
25689
|
if (n) {
|
|
25480
25690
|
let e = t;
|
|
25481
|
-
return /href\s*=\s*["'][^"']*["']/i.test(e) ? e = e.replace(/href\s*=\s*["'][^"']*["']/i, `href="${n}"`) : e += ` href="${n}"`, i || (e += ` data-asset-id="${
|
|
25691
|
+
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}>`;
|
|
25482
25692
|
}
|
|
25483
25693
|
return e;
|
|
25484
25694
|
}
|
|
25485
|
-
let
|
|
25486
|
-
return /href\s*=\s*["'][^"']*["']/i.test(
|
|
25695
|
+
let u = o.get(c) || "#", d = t;
|
|
25696
|
+
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
25487
25697
|
});
|
|
25488
25698
|
}
|
|
25489
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) => pS(e, t, n)));
|
|
25699
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => pS(e, t, n, r)));
|
|
25490
25700
|
if (t && typeof t == "object") {
|
|
25491
25701
|
if (typeof t.href == "string" && (t.href.startsWith("#node:") || t.href.startsWith("#asset:"))) return {
|
|
25492
25702
|
...t,
|
|
25493
|
-
href: await mS(e, t, n)
|
|
25703
|
+
href: await mS(e, t, n, r)
|
|
25494
25704
|
};
|
|
25495
|
-
let
|
|
25496
|
-
return Object.fromEntries(
|
|
25705
|
+
let i = await Promise.all(Object.entries(t).map(async ([t, i]) => [t, await pS(e, i, n, r)]));
|
|
25706
|
+
return Object.fromEntries(i);
|
|
25497
25707
|
}
|
|
25498
25708
|
return t;
|
|
25499
25709
|
}
|
|
25500
|
-
async function mS(e, t, n) {
|
|
25501
|
-
let
|
|
25502
|
-
if (
|
|
25503
|
-
if (!
|
|
25504
|
-
let
|
|
25505
|
-
|
|
25506
|
-
let r = await hS(e, a, String(t.treeId), n);
|
|
25507
|
-
if (r?.treeNodeId) {
|
|
25508
|
-
let i = await yS(e, String(r.treeNodeId), String(t.treeId), n);
|
|
25509
|
-
if (i) return i;
|
|
25510
|
-
}
|
|
25511
|
-
}
|
|
25512
|
-
let o = await gS(e, a, n);
|
|
25513
|
-
return o === void 0 ? "#" : `/${o}`;
|
|
25514
|
-
}
|
|
25515
|
-
async function hS(e, t, n, r) {
|
|
25516
|
-
let i = sS(t, n), a = r.treeEdges.get(i);
|
|
25517
|
-
if (a) return a;
|
|
25518
|
-
let o = e.prepare("SELECT contentId as treeNodeId FROM tree_nodes WHERE contentId = ? AND treeId = ? LIMIT 1").get(t, n);
|
|
25519
|
-
return r.treeEdges.set(i, Promise.resolve(o)), o;
|
|
25520
|
-
}
|
|
25521
|
-
async function gS(e, t, n) {
|
|
25522
|
-
let r = String(t), i = n.nodeSlugs.get(r);
|
|
25523
|
-
if (i) return i;
|
|
25524
|
-
let a = (async () => {
|
|
25525
|
-
let n = await e.prepare("SELECT slug FROM content_nodes WHERE id = ?").get(t);
|
|
25526
|
-
return n?.slug ? String(n.slug).replace(/^\/+|\/+$/g, "") : void 0;
|
|
25527
|
-
})();
|
|
25528
|
-
return n.nodeSlugs.set(r, a), a;
|
|
25710
|
+
async function mS(e, t, n, r) {
|
|
25711
|
+
let i = t.href.match(/^#node:(.+)$/), a = t.href.match(/^#asset:(.+)$/);
|
|
25712
|
+
if (a) return hS(e, a[1], r);
|
|
25713
|
+
if (!i) return t.href;
|
|
25714
|
+
let o = i[1];
|
|
25715
|
+
return (await e.prepare("SELECT path FROM node_routes WHERE nodeId = ? AND channelId = ? AND isCanonical = 1 LIMIT 1").get(Number(o), n))?.path || "#";
|
|
25529
25716
|
}
|
|
25530
|
-
async function
|
|
25717
|
+
async function hS(e, t, n) {
|
|
25531
25718
|
let r = String(t), i = n.assetUrls.get(r);
|
|
25532
25719
|
if (i) return i;
|
|
25533
25720
|
let a = (async () => {
|
|
@@ -25536,7 +25723,7 @@ async function _S(e, t, n) {
|
|
|
25536
25723
|
})();
|
|
25537
25724
|
return n.assetUrls.set(r, a), a;
|
|
25538
25725
|
}
|
|
25539
|
-
function
|
|
25726
|
+
function gS(e) {
|
|
25540
25727
|
let t = e.socialImage;
|
|
25541
25728
|
if (!t || typeof t != "object") return null;
|
|
25542
25729
|
let n = (e, t) => {
|
|
@@ -25567,24 +25754,7 @@ function vS(e) {
|
|
|
25567
25754
|
])
|
|
25568
25755
|
};
|
|
25569
25756
|
}
|
|
25570
|
-
async function
|
|
25571
|
-
if (!t) return "";
|
|
25572
|
-
let i = sS(t, n);
|
|
25573
|
-
if (r) {
|
|
25574
|
-
let e = r.fullPath.get(i);
|
|
25575
|
-
if (e) return e;
|
|
25576
|
-
}
|
|
25577
|
-
let a = (async () => {
|
|
25578
|
-
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 = [];
|
|
25579
|
-
for (let e of i) {
|
|
25580
|
-
let t = (e.slug || "").replace(/^\/+|\/+$/g, "");
|
|
25581
|
-
t === "home" || t === "homee" ? i.length === 1 && (a.length = 0) : t && a.push(t);
|
|
25582
|
-
}
|
|
25583
|
-
return "/" + a.join("/");
|
|
25584
|
-
})();
|
|
25585
|
-
return r && r.fullPath.set(i, a), a;
|
|
25586
|
-
}
|
|
25587
|
-
async function bS(e, t, n, r, i) {
|
|
25757
|
+
async function _S(e, t, n, r, i) {
|
|
25588
25758
|
let a = {}, o = null;
|
|
25589
25759
|
if (t) {
|
|
25590
25760
|
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([
|
|
@@ -25622,200 +25792,151 @@ async function bS(e, t, n, r, i) {
|
|
|
25622
25792
|
inheritedFields: a
|
|
25623
25793
|
};
|
|
25624
25794
|
}
|
|
25625
|
-
function
|
|
25795
|
+
function vS(e) {
|
|
25626
25796
|
let t = Number(e?.env?.CMS_NODE_CACHE_TTL);
|
|
25627
25797
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
25628
25798
|
}
|
|
25629
|
-
async function
|
|
25799
|
+
async function yS(e, t, n, r) {
|
|
25630
25800
|
try {
|
|
25631
25801
|
await e.set(t, n, r);
|
|
25632
25802
|
} catch (e) {
|
|
25633
25803
|
console.warn("[CMS Cache] Failed to write node response to cache:", e);
|
|
25634
25804
|
}
|
|
25635
25805
|
}
|
|
25636
|
-
|
|
25637
|
-
channelId: J().optional().openapi({ description: "The ID or key of the channel" }),
|
|
25638
|
-
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25639
|
-
lang: J().optional().openapi({ description: "Requested language code" }),
|
|
25640
|
-
preview: lv(["true", "false"]).optional().openapi({ description: "Request unpublished draft data" }),
|
|
25641
|
-
revisionId: J().optional().openapi({ description: "Historical revision version to load" }),
|
|
25642
|
-
treeId: J().optional().openapi({ description: "The ID of the tree to resolve paths against" })
|
|
25643
|
-
}), wS = X({
|
|
25644
|
-
error: J(),
|
|
25645
|
-
details: J().optional()
|
|
25646
|
-
}).openapi("ErrorResponse"), TS = X({
|
|
25647
|
-
channelId: G_([J(), c_()]),
|
|
25648
|
-
treeId: J().nullable(),
|
|
25649
|
-
language: J().nullable(),
|
|
25650
|
-
node: tv(k_()),
|
|
25651
|
-
content: tv(z_(k_())),
|
|
25652
|
-
regionMeta: tv(X({
|
|
25653
|
-
isInherited: g_(),
|
|
25654
|
-
inheritedFromId: J().optional(),
|
|
25655
|
-
inheritedFromTitle: J().optional()
|
|
25656
|
-
}))
|
|
25657
|
-
}).openapi("NodeResponse"), ES = eb({
|
|
25658
|
-
method: "get",
|
|
25659
|
-
path: "/{path+}",
|
|
25660
|
-
summary: "Fetch CMS Node Content",
|
|
25661
|
-
description: "Retrieves a fully hydrated CMS node along with its content blocks and inherited regions.",
|
|
25662
|
-
tags: ["Public Node API"],
|
|
25663
|
-
request: {
|
|
25664
|
-
params: X({ path: J().optional().openapi({ description: "The full URL path or slug of the requested node" }) }),
|
|
25665
|
-
query: CS
|
|
25666
|
-
},
|
|
25667
|
-
responses: {
|
|
25668
|
-
200: {
|
|
25669
|
-
description: "Fully hydrated CMS Node",
|
|
25670
|
-
content: { "application/json": { schema: TS } }
|
|
25671
|
-
},
|
|
25672
|
-
404: {
|
|
25673
|
-
description: "Node or Channel not found",
|
|
25674
|
-
content: { "application/json": { schema: wS } }
|
|
25675
|
-
},
|
|
25676
|
-
500: {
|
|
25677
|
-
description: "Server error during hydration",
|
|
25678
|
-
content: { "application/json": { schema: wS } }
|
|
25679
|
-
}
|
|
25680
|
-
}
|
|
25681
|
-
});
|
|
25682
|
-
aS.openapi(ES, async (e) => {
|
|
25806
|
+
async function bS(e) {
|
|
25683
25807
|
try {
|
|
25684
|
-
let t = e.get("db"), n =
|
|
25685
|
-
|
|
25686
|
-
|
|
25687
|
-
|
|
25688
|
-
|
|
25689
|
-
|
|
25690
|
-
|
|
25691
|
-
|
|
25692
|
-
|
|
25693
|
-
|
|
25694
|
-
|
|
25695
|
-
|
|
25696
|
-
|
|
25697
|
-
|
|
25698
|
-
|
|
25699
|
-
|
|
25700
|
-
|
|
25701
|
-
|
|
25702
|
-
|
|
25703
|
-
|
|
25704
|
-
|
|
25705
|
-
}
|
|
25808
|
+
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 = "";
|
|
25809
|
+
l.includes("/node/") ? u = l.substring(l.indexOf("/node/") + 6) : l.endsWith("/node") && (u = "");
|
|
25810
|
+
try {
|
|
25811
|
+
u = decodeURIComponent(u);
|
|
25812
|
+
} catch {}
|
|
25813
|
+
u = u.replace(/^\/+|\/+$/g, "");
|
|
25814
|
+
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));
|
|
25815
|
+
if (!p) return e.json({ error: `Channel '${f}' not found` }, 404);
|
|
25816
|
+
let m = p.status === "disabled" || p.status === "inactive" || p.isEnabled === 0 || p.isEnabled === !1;
|
|
25817
|
+
if (!o && m) return e.json({ error: `Channel '${p.key || f}' is currently inactive` }, 404);
|
|
25818
|
+
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);
|
|
25819
|
+
if (_?.redirectUrl) return e.json({
|
|
25820
|
+
redirect: _.redirectUrl,
|
|
25821
|
+
isCanonical: !1
|
|
25822
|
+
});
|
|
25823
|
+
let v = null, y = _?.treeId || c || null;
|
|
25824
|
+
if (_?.nodeId) v = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(_.nodeId);
|
|
25825
|
+
else if (/^\d+$/.test(u)) v = await t.prepare("SELECT * FROM content_nodes WHERE id = ?").get(Number(u));
|
|
25826
|
+
else {
|
|
25827
|
+
let e = u.split("/").pop() || u;
|
|
25828
|
+
v = await t.prepare("SELECT * FROM content_nodes WHERE slug = ?").get(e);
|
|
25706
25829
|
}
|
|
25707
|
-
if (!
|
|
25708
|
-
let
|
|
25709
|
-
if (
|
|
25710
|
-
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(
|
|
25830
|
+
if (!v) return e.json({ error: `Node '${u}' not found for Channel '${f}'` }, 404);
|
|
25831
|
+
let b = null;
|
|
25832
|
+
if (s) {
|
|
25833
|
+
let e = await t.prepare("SELECT snapshotJson FROM node_revisions WHERE nodeId = ? AND version = ?").get(v.id, Number(s));
|
|
25711
25834
|
if (e && e.snapshotJson) try {
|
|
25712
|
-
|
|
25835
|
+
b = JSON.parse(e.snapshotJson), b.node && (b.node.title && (v.title = b.node.title), b.node.slug && (v.slug = b.node.slug));
|
|
25713
25836
|
} catch (e) {
|
|
25714
25837
|
console.error("[CMS] Failed to parse snapshotJson", e);
|
|
25715
25838
|
}
|
|
25716
25839
|
}
|
|
25717
|
-
|
|
25718
|
-
|
|
25719
|
-
|
|
25720
|
-
|
|
25721
|
-
|
|
25722
|
-
if (D) {
|
|
25723
|
-
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));
|
|
25840
|
+
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] : []);
|
|
25841
|
+
!y && x?.treeId && (y = x.treeId), y ||= "main-nav";
|
|
25842
|
+
let S = null;
|
|
25843
|
+
if (y) {
|
|
25844
|
+
let e = await t.prepare("SELECT dataJson FROM trees WHERE id = ? OR key = ? LIMIT 1").get(Number(y) || -1, String(y));
|
|
25724
25845
|
if (e?.dataJson) try {
|
|
25725
25846
|
let t = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
25726
|
-
t.defaultLanguage ?
|
|
25847
|
+
t.defaultLanguage ? S = String(t.defaultLanguage).trim() : t.language && (S = String(t.language).trim());
|
|
25727
25848
|
} catch {}
|
|
25728
25849
|
}
|
|
25729
|
-
let
|
|
25730
|
-
if (
|
|
25731
|
-
if (
|
|
25732
|
-
else if (
|
|
25733
|
-
let e = typeof
|
|
25734
|
-
e.defaultLanguage ?
|
|
25850
|
+
let C = null;
|
|
25851
|
+
if (p) {
|
|
25852
|
+
if (p.defaultLanguage) C = String(p.defaultLanguage).trim();
|
|
25853
|
+
else if (p.dataJson) try {
|
|
25854
|
+
let e = typeof p.dataJson == "string" ? JSON.parse(p.dataJson) : p.dataJson;
|
|
25855
|
+
e.defaultLanguage ? C = String(e.defaultLanguage).trim() : e.language && (C = String(e.language).trim());
|
|
25735
25856
|
} catch {}
|
|
25736
25857
|
}
|
|
25737
|
-
let
|
|
25738
|
-
if (!
|
|
25739
|
-
let t = await
|
|
25858
|
+
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);
|
|
25859
|
+
if (!o && !D) {
|
|
25860
|
+
let t = await te.get(E);
|
|
25740
25861
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
25741
25862
|
}
|
|
25742
|
-
let
|
|
25743
|
-
id:
|
|
25744
|
-
title:
|
|
25745
|
-
slug:
|
|
25746
|
-
language:
|
|
25747
|
-
path:
|
|
25748
|
-
nodeType:
|
|
25749
|
-
createdAt:
|
|
25750
|
-
updatedAt:
|
|
25751
|
-
},
|
|
25752
|
-
|
|
25753
|
-
Object.assign(
|
|
25863
|
+
let ne = x?.parentId || null, O = _?.path || (d === "" ? "/" : d), k = {
|
|
25864
|
+
id: v.id,
|
|
25865
|
+
title: v.title,
|
|
25866
|
+
slug: v.slug,
|
|
25867
|
+
language: T,
|
|
25868
|
+
path: O,
|
|
25869
|
+
nodeType: v.contentType,
|
|
25870
|
+
createdAt: v.createdAt,
|
|
25871
|
+
updatedAt: v.updatedAt
|
|
25872
|
+
}, A = dx(e.env?.BUNDLED_DEFINITIONS), re = v.contentType || "node", ie = A.nodes?.[re] || Object.values(A.nodes || {})[0] || {}, ae = { ...ie.fields || {} };
|
|
25873
|
+
ie.tabs && Object.values(ie.tabs).forEach((e) => {
|
|
25874
|
+
Object.assign(ae, e.fields || {});
|
|
25754
25875
|
});
|
|
25755
|
-
let
|
|
25756
|
-
if (
|
|
25757
|
-
|
|
25876
|
+
let oe = {}, se = null, ce = null, le = !1, j = {}, ue = o && v.draftDataJson || v.dataJson;
|
|
25877
|
+
if (b && b.node && b.node.dataJson && (ue = b.node.dataJson), ue) try {
|
|
25878
|
+
j = typeof ue == "string" ? JSON.parse(ue) : ue;
|
|
25758
25879
|
} catch {}
|
|
25759
|
-
|
|
25760
|
-
let
|
|
25761
|
-
for (let [e, t] of Object.entries(
|
|
25762
|
-
let
|
|
25763
|
-
|
|
25764
|
-
let
|
|
25765
|
-
delete
|
|
25766
|
-
let
|
|
25767
|
-
if (!
|
|
25768
|
-
let
|
|
25769
|
-
if (
|
|
25770
|
-
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(
|
|
25771
|
-
|
|
25772
|
-
let t = {}, n =
|
|
25880
|
+
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;
|
|
25881
|
+
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;
|
|
25882
|
+
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);
|
|
25883
|
+
let ge = await ux(t, dS(j, ae));
|
|
25884
|
+
ge = fS(ge), ge = await pS(t, ge, h, n), delete ge.language;
|
|
25885
|
+
let _e = gS(ge);
|
|
25886
|
+
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;
|
|
25887
|
+
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";
|
|
25888
|
+
if (!o && (ve || ye || be && !xe)) return e.json({ error: "Node is hidden, offline, or has never been published." }, 404);
|
|
25889
|
+
let Se = [];
|
|
25890
|
+
if (x?.treeNodeId) {
|
|
25891
|
+
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;
|
|
25892
|
+
Se = n.map((e) => {
|
|
25893
|
+
let t = {}, n = o && e.draftDataJson || e.dataJson;
|
|
25773
25894
|
if (!n) return null;
|
|
25774
25895
|
try {
|
|
25775
25896
|
t = (typeof n == "string" ? JSON.parse(n) : n) || {};
|
|
25776
25897
|
} catch {}
|
|
25777
|
-
let
|
|
25778
|
-
return !
|
|
25898
|
+
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, "");
|
|
25899
|
+
return !o && (r || !a) ? null : {
|
|
25779
25900
|
treeNodeId: e.treeNodeId,
|
|
25780
25901
|
id: e.id,
|
|
25781
25902
|
title: e.title,
|
|
25782
|
-
slug:
|
|
25783
|
-
language: e.language?.trim() ||
|
|
25784
|
-
path: `${
|
|
25903
|
+
slug: s,
|
|
25904
|
+
language: e.language?.trim() || T || null,
|
|
25905
|
+
path: `${i}/${s}`.replace(/\/+/g, "/"),
|
|
25785
25906
|
nodeType: e.nodeType
|
|
25786
25907
|
};
|
|
25787
25908
|
}).filter(Boolean);
|
|
25788
25909
|
}
|
|
25789
|
-
|
|
25790
|
-
let
|
|
25791
|
-
if (
|
|
25910
|
+
k.children = Se;
|
|
25911
|
+
let Ce = [];
|
|
25912
|
+
if (b && b.blocks && Array.isArray(b.blocks)) Ce = b.blocks.map((e) => ({
|
|
25792
25913
|
...e,
|
|
25793
25914
|
isDraft: 1
|
|
25794
25915
|
}));
|
|
25795
25916
|
else {
|
|
25796
|
-
let e = +!!
|
|
25797
|
-
|
|
25917
|
+
let e = +!!o, n = await t.prepare("SELECT * FROM content_blocks WHERE contentId = ? AND isDraft = ? ORDER BY sortOrder ASC").all(v.id, e);
|
|
25918
|
+
Ce = Array.isArray(n) ? n : n?.results || [];
|
|
25798
25919
|
}
|
|
25799
|
-
let
|
|
25920
|
+
let we = {}, Te = {}, Ee = await Promise.all(Ce.map(async (e) => {
|
|
25800
25921
|
let r = e.region || "main", i = {};
|
|
25801
25922
|
try {
|
|
25802
25923
|
i = (typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson) || {};
|
|
25803
25924
|
} catch {}
|
|
25804
|
-
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true",
|
|
25805
|
-
if (!
|
|
25806
|
-
let
|
|
25807
|
-
return d = await ux(t, d), d = fS(d), d = await pS(t, d, n), d.blockId = u, {
|
|
25925
|
+
let a = i.hidden === !0 || i.hidden === 1 || i.hidden === "1" || i.hidden === "true", s = cS(i.startShowingAt, i.stopShowingAt);
|
|
25926
|
+
if (!o && (a || !s)) return null;
|
|
25927
|
+
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);
|
|
25928
|
+
return d = await ux(t, d), d = fS(d), d = await pS(t, d, h, n), d.blockId = u, {
|
|
25808
25929
|
region: r,
|
|
25809
25930
|
block: {
|
|
25810
25931
|
instanceId: e.id,
|
|
25811
25932
|
blockId: u,
|
|
25812
|
-
componentId:
|
|
25933
|
+
componentId: c,
|
|
25813
25934
|
data: d
|
|
25814
25935
|
}
|
|
25815
25936
|
};
|
|
25816
25937
|
}));
|
|
25817
|
-
for (let e of
|
|
25818
|
-
let
|
|
25938
|
+
for (let e of Ee) e && (we[e.region] || (we[e.region] = [], Te[e.region] = { isInherited: !1 }), we[e.region].push(e.block));
|
|
25939
|
+
let De = {
|
|
25819
25940
|
header: {
|
|
25820
25941
|
label: "Header",
|
|
25821
25942
|
inherit: "parent"
|
|
@@ -25824,44 +25945,91 @@ aS.openapi(ES, async (e) => {
|
|
|
25824
25945
|
label: "Footer",
|
|
25825
25946
|
inherit: "parent"
|
|
25826
25947
|
},
|
|
25827
|
-
...(
|
|
25948
|
+
...(he ? A.nodeLayouts?.[he] || A.layouts?.[he] : null)?.regions || { main: { label: "Content" } }
|
|
25828
25949
|
};
|
|
25829
|
-
for (let [e, r] of Object.entries(
|
|
25830
|
-
let i =
|
|
25831
|
-
if (
|
|
25832
|
-
let r = await uS(t,
|
|
25833
|
-
if (r.blocks.length > 0 && (
|
|
25950
|
+
for (let [e, r] of Object.entries(De)) {
|
|
25951
|
+
let i = we[e] && we[e].length > 0, a = !!oe[e];
|
|
25952
|
+
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) {
|
|
25953
|
+
let r = await uS(t, ne, String(y), e, A, o, n);
|
|
25954
|
+
if (r.blocks.length > 0 && (we[e] = r.blocks, Te[e] = {
|
|
25834
25955
|
isInherited: !0,
|
|
25835
25956
|
inheritedFromId: r.inheritedFromId,
|
|
25836
25957
|
inheritedFromTitle: r.inheritedFromTitle
|
|
25837
|
-
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (
|
|
25958
|
+
}, r.subRegions)) for (let [t, n] of Object.entries(r.subRegions)) t !== e && (we[t] = n, Te[t] = {
|
|
25838
25959
|
isInherited: !0,
|
|
25839
25960
|
inheritedFromId: r.inheritedFromId,
|
|
25840
25961
|
inheritedFromTitle: r.inheritedFromTitle
|
|
25841
25962
|
});
|
|
25842
25963
|
}
|
|
25843
25964
|
}
|
|
25844
|
-
await Promise.all(Object.keys(
|
|
25845
|
-
let
|
|
25846
|
-
channelId:
|
|
25847
|
-
treeId:
|
|
25848
|
-
language:
|
|
25849
|
-
node:
|
|
25850
|
-
content:
|
|
25851
|
-
regionMeta:
|
|
25965
|
+
await Promise.all(Object.keys(we).map((e) => lS(t, we[e], h, T)));
|
|
25966
|
+
let Oe = {
|
|
25967
|
+
channelId: h || g,
|
|
25968
|
+
treeId: y,
|
|
25969
|
+
language: T,
|
|
25970
|
+
node: k,
|
|
25971
|
+
content: we,
|
|
25972
|
+
regionMeta: Te
|
|
25852
25973
|
};
|
|
25853
|
-
return !
|
|
25974
|
+
return !o && !D && (e.header("X-Cache", "MISS"), await yS(te, E, Oe, vS(e))), e.json(Oe, 200);
|
|
25854
25975
|
} catch (t) {
|
|
25855
25976
|
return console.error("[CMS Public API] Error fetching node by path:", t), e.json({
|
|
25856
25977
|
error: "Failed to fetch JSON payload",
|
|
25857
25978
|
...e.env?.ENVIRONMENT === "development" ? { details: t.message } : {}
|
|
25858
25979
|
}, 500);
|
|
25859
25980
|
}
|
|
25981
|
+
}
|
|
25982
|
+
var xS = X({
|
|
25983
|
+
channelId: J().optional().openapi({ description: "The ID or key of the channel" }),
|
|
25984
|
+
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25985
|
+
lang: J().optional().openapi({ description: "Requested language code" }),
|
|
25986
|
+
preview: lv(["true", "false"]).optional().openapi({ description: "Request unpublished draft data" }),
|
|
25987
|
+
revisionId: J().optional().openapi({ description: "Historical revision version to load" }),
|
|
25988
|
+
treeId: J().optional().openapi({ description: "The ID of the tree to resolve paths against" })
|
|
25989
|
+
}), SS = X({
|
|
25990
|
+
error: J(),
|
|
25991
|
+
details: J().optional()
|
|
25992
|
+
}).openapi("ErrorResponse"), CS = X({
|
|
25993
|
+
channelId: G_([J(), c_()]),
|
|
25994
|
+
treeId: J().nullable(),
|
|
25995
|
+
language: J().nullable(),
|
|
25996
|
+
node: tv(k_()),
|
|
25997
|
+
content: tv(z_(k_())),
|
|
25998
|
+
regionMeta: tv(X({
|
|
25999
|
+
isInherited: g_(),
|
|
26000
|
+
inheritedFromId: J().optional(),
|
|
26001
|
+
inheritedFromTitle: J().optional()
|
|
26002
|
+
}))
|
|
26003
|
+
}).openapi("NodeResponse"), wS = eb({
|
|
26004
|
+
method: "get",
|
|
26005
|
+
path: "/{path}",
|
|
26006
|
+
summary: "Fetch CMS Node Content",
|
|
26007
|
+
description: "Retrieves a fully hydrated CMS node along with its content blocks and inherited regions using $O(1)$ routing table lookups.",
|
|
26008
|
+
tags: ["Public Node API"],
|
|
26009
|
+
request: {
|
|
26010
|
+
params: X({ path: J().optional().openapi({ description: "The full URL path or slug of the requested node" }) }),
|
|
26011
|
+
query: xS
|
|
26012
|
+
},
|
|
26013
|
+
responses: {
|
|
26014
|
+
200: {
|
|
26015
|
+
description: "Fully hydrated CMS Node",
|
|
26016
|
+
content: { "application/json": { schema: CS } }
|
|
26017
|
+
},
|
|
26018
|
+
404: {
|
|
26019
|
+
description: "Node or Channel not found",
|
|
26020
|
+
content: { "application/json": { schema: SS } }
|
|
26021
|
+
},
|
|
26022
|
+
500: {
|
|
26023
|
+
description: "Server error during hydration",
|
|
26024
|
+
content: { "application/json": { schema: SS } }
|
|
26025
|
+
}
|
|
26026
|
+
}
|
|
25860
26027
|
});
|
|
26028
|
+
oS.openapi(wS, bS), oS.get("*", bS);
|
|
25861
26029
|
//#endregion
|
|
25862
26030
|
//#region server/routes/public/tree.ts
|
|
25863
|
-
var
|
|
25864
|
-
function
|
|
26031
|
+
var TS = new $y();
|
|
26032
|
+
function ES(e, t) {
|
|
25865
26033
|
let n = /* @__PURE__ */ new Date();
|
|
25866
26034
|
if (e && String(e).trim() !== "") {
|
|
25867
26035
|
let t = new Date(e);
|
|
@@ -25873,22 +26041,22 @@ function OS(e, t) {
|
|
|
25873
26041
|
}
|
|
25874
26042
|
return !0;
|
|
25875
26043
|
}
|
|
25876
|
-
async function
|
|
26044
|
+
async function DS(e, t, n, r) {
|
|
25877
26045
|
try {
|
|
25878
26046
|
await e.set(t, n, r);
|
|
25879
26047
|
} catch (e) {
|
|
25880
26048
|
console.warn("[CMS Cache] Failed to write tree response to cache:", e);
|
|
25881
26049
|
}
|
|
25882
26050
|
}
|
|
25883
|
-
var
|
|
26051
|
+
var OS = X({ treeParam: J().openapi({ description: "The ID or key of the requested tree (e.g., \"main-nav\")" }) }), kS = X({
|
|
25884
26052
|
channelId: J().optional().openapi({ description: "Channel ID to resolve context-aware routing" }),
|
|
25885
26053
|
channel: J().optional().openapi({ description: "Legacy alias for channelId" }),
|
|
25886
26054
|
lang: J().optional().openapi({ description: "Requested language code for tree nodes" }),
|
|
25887
26055
|
preview: lv(["true", "false"]).optional().openapi({ description: "Set to true to retrieve unpublished draft data" })
|
|
25888
|
-
}),
|
|
26056
|
+
}), AS = X({
|
|
25889
26057
|
error: J(),
|
|
25890
26058
|
details: J().optional()
|
|
25891
|
-
}).openapi("ErrorResponse"),
|
|
26059
|
+
}).openapi("ErrorResponse"), jS = qv(() => X({
|
|
25892
26060
|
id: G_([J(), c_()]),
|
|
25893
26061
|
treeNodeId: G_([J(), c_()]),
|
|
25894
26062
|
parentId: G_([J(), c_()]).nullable(),
|
|
@@ -25901,129 +26069,129 @@ var AS = X({ treeParam: J().openapi({ description: "The ID or key of the request
|
|
|
25901
26069
|
summary: J(),
|
|
25902
26070
|
url: J().optional(),
|
|
25903
26071
|
target: J().optional(),
|
|
25904
|
-
children: z_(
|
|
25905
|
-
})).openapi("TreeItem"),
|
|
26072
|
+
children: z_(jS).optional()
|
|
26073
|
+
})).openapi("TreeItem"), MS = X({
|
|
25906
26074
|
treeId: G_([c_(), J()]),
|
|
25907
26075
|
key: J(),
|
|
25908
26076
|
channelId: J(),
|
|
25909
26077
|
language: J().nullable(),
|
|
25910
26078
|
label: J(),
|
|
25911
|
-
items: z_(
|
|
25912
|
-
}).catchall(k_()).openapi("TreeResponse"),
|
|
26079
|
+
items: z_(jS)
|
|
26080
|
+
}).catchall(k_()).openapi("TreeResponse"), NS = eb({
|
|
25913
26081
|
method: "get",
|
|
25914
26082
|
path: "/{treeParam}",
|
|
25915
26083
|
summary: "Fetch CMS Navigation Tree",
|
|
25916
|
-
description: "Retrieves a fully hydrated, recursive navigation tree structure.
|
|
26084
|
+
description: "Retrieves a fully hydrated, recursive navigation tree structure. Uses $O(1)$ pre-computed routing table paths.",
|
|
25917
26085
|
tags: ["Public Tree API"],
|
|
25918
26086
|
request: {
|
|
25919
|
-
params:
|
|
25920
|
-
query:
|
|
26087
|
+
params: OS,
|
|
26088
|
+
query: kS
|
|
25921
26089
|
},
|
|
25922
26090
|
responses: {
|
|
25923
26091
|
200: {
|
|
25924
26092
|
description: "Fully hydrated CMS Tree payload",
|
|
25925
|
-
content: { "application/json": { schema:
|
|
26093
|
+
content: { "application/json": { schema: MS } }
|
|
25926
26094
|
},
|
|
25927
26095
|
404: {
|
|
25928
26096
|
description: "Tree or Channel not found / inactive",
|
|
25929
|
-
content: { "application/json": { schema:
|
|
26097
|
+
content: { "application/json": { schema: AS } }
|
|
25930
26098
|
},
|
|
25931
26099
|
500: {
|
|
25932
26100
|
description: "Server error during hydration",
|
|
25933
|
-
content: { "application/json": { schema:
|
|
26101
|
+
content: { "application/json": { schema: AS } }
|
|
25934
26102
|
}
|
|
25935
26103
|
}
|
|
25936
26104
|
});
|
|
25937
|
-
|
|
26105
|
+
TS.openapi(NS, async (e) => {
|
|
25938
26106
|
try {
|
|
25939
|
-
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;
|
|
26107
|
+
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;
|
|
25940
26108
|
if (i && i !== "default" && i !== "all") {
|
|
25941
26109
|
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));
|
|
25942
26110
|
if (n) {
|
|
25943
|
-
n.defaultLanguage && (s = n.defaultLanguage.trim());
|
|
26111
|
+
c = Number(n.id), n.defaultLanguage && (s = n.defaultLanguage.trim());
|
|
25944
26112
|
let t = n.status === "disabled" || n.status === "inactive" || n.isEnabled === 0 || n.isEnabled === !1;
|
|
25945
26113
|
if (!o && t) return e.json({ error: `Channel '${n.key || i}' is currently inactive` }, 404);
|
|
25946
26114
|
}
|
|
25947
26115
|
}
|
|
25948
|
-
let
|
|
25949
|
-
if (
|
|
25950
|
-
let
|
|
25951
|
-
if (
|
|
25952
|
-
if (
|
|
25953
|
-
else if (
|
|
25954
|
-
let e = typeof
|
|
25955
|
-
e.defaultLanguage && (
|
|
26116
|
+
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);
|
|
26117
|
+
if (u && Number(u.isHidden) === 1 && !o) return e.json({ error: `Tree '${n}' is hidden` }, 404);
|
|
26118
|
+
let d = null;
|
|
26119
|
+
if (u) {
|
|
26120
|
+
if (u.defaultLanguage) d = String(u.defaultLanguage).trim();
|
|
26121
|
+
else if (u.dataJson) try {
|
|
26122
|
+
let e = typeof u.dataJson == "string" ? JSON.parse(u.dataJson) : u.dataJson;
|
|
26123
|
+
e.defaultLanguage && (d = String(e.defaultLanguage).trim());
|
|
25956
26124
|
} catch {}
|
|
25957
26125
|
}
|
|
25958
|
-
let
|
|
25959
|
-
if (!o && !
|
|
25960
|
-
let t = await
|
|
26126
|
+
let f = d || s || a?.trim() || null, p = $b(e), m = `tree:${i}:${n}:${f || "default"}`, h = e.req.header("x-bypass-cache") === "true";
|
|
26127
|
+
if (!o && !h) {
|
|
26128
|
+
let t = await p.get(m);
|
|
25961
26129
|
if (t) return e.header("X-Cache", "HIT"), e.json(t, 200);
|
|
25962
26130
|
}
|
|
25963
|
-
let
|
|
25964
|
-
if (
|
|
25965
|
-
let t = typeof
|
|
25966
|
-
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (
|
|
26131
|
+
let g = u?.id || (l ? Number(n) : null), _ = {};
|
|
26132
|
+
if (u && u.dataJson) try {
|
|
26133
|
+
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 || {};
|
|
26134
|
+
for (let [e, n] of Object.entries(t)) a[e]?.public === !0 && (_[e] = n);
|
|
25967
26135
|
} catch (e) {
|
|
25968
26136
|
console.warn("[CMS Public Tree API] Failed to parse tree dataJson", e);
|
|
25969
26137
|
}
|
|
25970
|
-
let
|
|
25971
|
-
if (
|
|
25972
|
-
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(
|
|
25973
|
-
|
|
25974
|
-
}
|
|
25975
|
-
if ((!_ || _.length === 0) && !l) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
25976
|
-
let v = /* @__PURE__ */ new Map();
|
|
25977
|
-
for (let e of _) {
|
|
25978
|
-
let t = !e.parentId || e.parentId === "null" || e.parentId === "" ? null : e.parentId, n = t === null ? "__ROOT__" : String(t), r = v.get(n);
|
|
25979
|
-
r ? r.push(e) : v.set(n, [e]);
|
|
26138
|
+
let v = [];
|
|
26139
|
+
if (g !== null) {
|
|
26140
|
+
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);
|
|
26141
|
+
v = Array.isArray(e) ? e : e?.results || [];
|
|
25980
26142
|
}
|
|
26143
|
+
if ((!v || v.length === 0) && !u) return e.json({ error: `Tree '${n}' not found` }, 404);
|
|
25981
26144
|
let y = /* @__PURE__ */ new Map();
|
|
25982
|
-
for (let e of
|
|
26145
|
+
for (let e of v) {
|
|
26146
|
+
let t = !e.parentId || e.parentId === "null" || e.parentId === "" ? null : e.parentId, n = t === null ? "__ROOT__" : String(t), r = y.get(n);
|
|
26147
|
+
r ? r.push(e) : y.set(n, [e]);
|
|
26148
|
+
}
|
|
26149
|
+
let b = /* @__PURE__ */ new Map();
|
|
26150
|
+
for (let e of v) {
|
|
25983
26151
|
let t = String(e.id), n = o && e.draftDataJson ? e.draftDataJson : e.dataJson;
|
|
25984
26152
|
if (!n) {
|
|
25985
|
-
|
|
26153
|
+
b.set(t, {});
|
|
25986
26154
|
continue;
|
|
25987
26155
|
}
|
|
25988
26156
|
try {
|
|
25989
26157
|
let e = typeof n == "string" ? JSON.parse(n) : n;
|
|
25990
|
-
|
|
26158
|
+
b.set(t, e && typeof e == "object" ? e : {});
|
|
25991
26159
|
} catch {
|
|
25992
|
-
|
|
26160
|
+
b.set(t, {});
|
|
25993
26161
|
}
|
|
25994
26162
|
}
|
|
25995
|
-
function
|
|
26163
|
+
function x(e = null, t = "") {
|
|
25996
26164
|
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e);
|
|
25997
|
-
return (
|
|
25998
|
-
let n =
|
|
26165
|
+
return (y.get(n) || []).map((e) => {
|
|
26166
|
+
let n = b.get(String(e.id)) || {}, r = {};
|
|
25999
26167
|
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);
|
|
26000
|
-
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 =
|
|
26168
|
+
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 = {
|
|
26001
26169
|
id: e.id,
|
|
26002
26170
|
treeNodeId: e.id,
|
|
26003
26171
|
parentId: e.parentId || null,
|
|
26004
26172
|
title: e.title,
|
|
26005
26173
|
slug: c,
|
|
26006
|
-
language:
|
|
26007
|
-
path:
|
|
26174
|
+
language: d,
|
|
26175
|
+
path: u,
|
|
26008
26176
|
nodeType: e.nodeType,
|
|
26009
26177
|
hidden: a || !s ? 1 : 0,
|
|
26010
26178
|
summary: r.summary || ""
|
|
26011
26179
|
};
|
|
26012
|
-
e.nodeType === "external-link" && (r.url && (
|
|
26013
|
-
let
|
|
26014
|
-
return
|
|
26180
|
+
e.nodeType === "external-link" && (r.url && (p.url = r.url), r.target && (p.target = r.target));
|
|
26181
|
+
let m = u === "/" ? "" : u;
|
|
26182
|
+
return p.children = x(e.id, m), p;
|
|
26015
26183
|
}).filter((e) => o || !e.hidden);
|
|
26016
26184
|
}
|
|
26017
|
-
let
|
|
26018
|
-
treeId:
|
|
26019
|
-
key:
|
|
26185
|
+
let S = {
|
|
26186
|
+
treeId: u?.id || g,
|
|
26187
|
+
key: u?.key || n,
|
|
26020
26188
|
channelId: String(i),
|
|
26021
|
-
language:
|
|
26022
|
-
label:
|
|
26023
|
-
...
|
|
26024
|
-
items:
|
|
26189
|
+
language: f,
|
|
26190
|
+
label: u?.label || n,
|
|
26191
|
+
..._,
|
|
26192
|
+
items: x(null)
|
|
26025
26193
|
};
|
|
26026
|
-
return !o && !
|
|
26194
|
+
return !o && !h && (e.header("X-Cache", "MISS"), await DS(p, m, S, 300)), e.json(S, 200);
|
|
26027
26195
|
} catch (t) {
|
|
26028
26196
|
return console.error("[CMS Public Tree API] Error:", t), e.json({
|
|
26029
26197
|
error: "Failed to fetch public tree",
|
|
@@ -26033,19 +26201,19 @@ DS.openapi(FS, async (e) => {
|
|
|
26033
26201
|
});
|
|
26034
26202
|
//#endregion
|
|
26035
26203
|
//#region server/routes/public/channel.ts
|
|
26036
|
-
var
|
|
26037
|
-
function
|
|
26204
|
+
var PS = new $y();
|
|
26205
|
+
function FS(e) {
|
|
26038
26206
|
let t = Number(e?.env?.CMS_CHANNEL_CACHE_TTL);
|
|
26039
26207
|
return Number.isFinite(t) && t >= 60 ? Math.floor(t) : 300;
|
|
26040
26208
|
}
|
|
26041
|
-
async function
|
|
26209
|
+
async function IS(e, t, n, r) {
|
|
26042
26210
|
try {
|
|
26043
26211
|
await e.set(t, n, r);
|
|
26044
26212
|
} catch (e) {
|
|
26045
26213
|
console.warn("[CMS Cache] Failed to write channel response to cache:", e);
|
|
26046
26214
|
}
|
|
26047
26215
|
}
|
|
26048
|
-
function
|
|
26216
|
+
function LS(e, t) {
|
|
26049
26217
|
let n = {}, r = (e) => {
|
|
26050
26218
|
if (!e || typeof e != "string") return;
|
|
26051
26219
|
let n = t?.fieldSets?.[e] || t?.fieldsets?.[e] || t?.definitions?.[e] || t?.channels?.[e] || t?.[e];
|
|
@@ -26056,7 +26224,7 @@ function zS(e, t) {
|
|
|
26056
26224
|
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);
|
|
26057
26225
|
return n;
|
|
26058
26226
|
}
|
|
26059
|
-
function
|
|
26227
|
+
function RS(e, t = {}) {
|
|
26060
26228
|
let n = {}, r = Object.keys(t).length > 0;
|
|
26061
26229
|
for (let [i, a] of Object.entries(e)) {
|
|
26062
26230
|
if (i.endsWith("_meta") || [
|
|
@@ -26075,14 +26243,14 @@ function BS(e, t = {}) {
|
|
|
26075
26243
|
}
|
|
26076
26244
|
return n;
|
|
26077
26245
|
}
|
|
26078
|
-
function
|
|
26079
|
-
if (Array.isArray(e)) return e.map(
|
|
26246
|
+
function zS(e) {
|
|
26247
|
+
if (Array.isArray(e)) return e.map(zS);
|
|
26080
26248
|
if (!e || typeof e != "object") return e;
|
|
26081
26249
|
if (typeof e.id == "string" && e.id.startsWith("ast_") && typeof e.url == "string") {
|
|
26082
26250
|
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 ? {
|
|
26083
26251
|
...t,
|
|
26084
26252
|
...t.crops?.[r] || {}
|
|
26085
|
-
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t,
|
|
26253
|
+
} : t, a = Object.fromEntries(Object.entries(n).filter(([, t]) => t?.id !== e.id).map(([t, n]) => [t, zS({
|
|
26086
26254
|
...n,
|
|
26087
26255
|
title: n?.title ?? e.title ?? "",
|
|
26088
26256
|
alt: n?.alt ?? e.alt ?? "",
|
|
@@ -26096,77 +26264,80 @@ function VS(e) {
|
|
|
26096
26264
|
...Object.keys(a).length > 0 ? { variants: a } : {}
|
|
26097
26265
|
};
|
|
26098
26266
|
}
|
|
26099
|
-
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e,
|
|
26267
|
+
return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, zS(t)]));
|
|
26100
26268
|
}
|
|
26101
|
-
async function
|
|
26269
|
+
async function BS(e, t, n) {
|
|
26102
26270
|
if (typeof t == "string") {
|
|
26103
26271
|
if (!t.includes("#node:") && !t.includes("data-node-id") && !t.includes("#asset:") && !t.includes("data-asset-id")) return t;
|
|
26104
|
-
let
|
|
26105
|
-
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi))
|
|
26106
|
-
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi))
|
|
26107
|
-
if (
|
|
26108
|
-
let
|
|
26109
|
-
|
|
26110
|
-
|
|
26111
|
-
|
|
26272
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
|
|
26273
|
+
for (let e of t.matchAll(/(?:#node:|data-node-id\s*=\s*["'])([^"'\s>]+)/gi)) r.add(e[1]);
|
|
26274
|
+
for (let e of t.matchAll(/(?:#asset:|data-asset-id\s*=\s*["'])([^"'\s>]+)/gi)) i.add(e[1]);
|
|
26275
|
+
if (r.size === 0 && i.size === 0) return t;
|
|
26276
|
+
let a = /* @__PURE__ */ new Map();
|
|
26277
|
+
if (r.size > 0) {
|
|
26278
|
+
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);
|
|
26279
|
+
(Array.isArray(i) ? i : i?.results || []).forEach((e) => a.set(String(e.nodeId), e.path));
|
|
26280
|
+
}
|
|
26281
|
+
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();
|
|
26282
|
+
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) => {
|
|
26112
26283
|
let n = (e, t) => {
|
|
26113
26284
|
let n = e.match(RegExp(`\\b${t}\\s*=\\s*(["'])(.*?)\\1`, "i"));
|
|
26114
26285
|
return n ? n[2] : void 0;
|
|
26115
|
-
}, r = n(t, "data-node-id"), i = n(t, "data-asset-id"),
|
|
26116
|
-
if (
|
|
26117
|
-
let s = i ||
|
|
26118
|
-
if (!
|
|
26119
|
-
if (s && !
|
|
26120
|
-
let n =
|
|
26286
|
+
}, r = n(t, "data-node-id"), i = n(t, "data-asset-id"), o = n(t, "href") || "";
|
|
26287
|
+
if (o.startsWith("mailto:")) return `<a ${t.replace(/\s+target\s*=\s*["'][^"']*["']/i, "")}>`;
|
|
26288
|
+
let s = i || o.match(/^#asset:(.+)$/i)?.[1], l = r || o.match(/^#node:(.+)$/i)?.[1];
|
|
26289
|
+
if (!l && !s) return e;
|
|
26290
|
+
if (s && !l) {
|
|
26291
|
+
let n = c.get(s);
|
|
26121
26292
|
if (n) {
|
|
26122
26293
|
let e = t;
|
|
26123
26294
|
return /href\s*=\s*["'][^"']*["']/i.test(e) ? e = e.replace(/href\s*=\s*["'][^"']*["']/i, `href="${n}"`) : e += ` href="${n}"`, `<a ${e}>`;
|
|
26124
26295
|
}
|
|
26125
26296
|
return e;
|
|
26126
26297
|
}
|
|
26127
|
-
let u =
|
|
26128
|
-
return /href\s*=\s*["'][^"']*["']/i.test(
|
|
26298
|
+
let u = a.get(l) || "#", d = t;
|
|
26299
|
+
return /href\s*=\s*["'][^"']*["']/i.test(d) ? d = d.replace(/href\s*=\s*["'][^"']*["']/i, `href="${u}"`) : d += ` href="${u}"`, `<a ${d}>`;
|
|
26129
26300
|
});
|
|
26130
26301
|
}
|
|
26131
|
-
if (Array.isArray(t)) return Promise.all(t.map((t) =>
|
|
26302
|
+
if (Array.isArray(t)) return Promise.all(t.map((t) => BS(e, t, n)));
|
|
26132
26303
|
if (t && typeof t == "object") {
|
|
26133
|
-
let
|
|
26134
|
-
return Object.fromEntries(
|
|
26304
|
+
let r = await Promise.all(Object.entries(t).map(async ([t, r]) => [t, await BS(e, r, n)]));
|
|
26305
|
+
return Object.fromEntries(r);
|
|
26135
26306
|
}
|
|
26136
26307
|
return t;
|
|
26137
26308
|
}
|
|
26138
|
-
var
|
|
26309
|
+
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({
|
|
26139
26310
|
error: J(),
|
|
26140
26311
|
details: J().optional()
|
|
26141
|
-
}).openapi("ErrorResponse"),
|
|
26312
|
+
}).openapi("ErrorResponse"), WS = X({
|
|
26142
26313
|
id: G_([c_(), J()]),
|
|
26143
26314
|
key: J()
|
|
26144
|
-
}).catchall(k_()).openapi("ChannelResponse"),
|
|
26315
|
+
}).catchall(k_()).openapi("ChannelResponse"), GS = eb({
|
|
26145
26316
|
method: "get",
|
|
26146
26317
|
path: "/{channelParam}",
|
|
26147
26318
|
summary: "Fetch CMS Channel Settings",
|
|
26148
26319
|
description: "Retrieves the fully hydrated, public-facing settings and payload for a specific CMS channel.",
|
|
26149
26320
|
tags: ["Public Channel API"],
|
|
26150
26321
|
request: {
|
|
26151
|
-
params:
|
|
26152
|
-
query:
|
|
26322
|
+
params: VS,
|
|
26323
|
+
query: HS
|
|
26153
26324
|
},
|
|
26154
26325
|
responses: {
|
|
26155
26326
|
200: {
|
|
26156
26327
|
description: "Fully hydrated CMS Channel payload",
|
|
26157
|
-
content: { "application/json": { schema:
|
|
26328
|
+
content: { "application/json": { schema: WS } }
|
|
26158
26329
|
},
|
|
26159
26330
|
404: {
|
|
26160
26331
|
description: "Channel not found or inactive",
|
|
26161
|
-
content: { "application/json": { schema:
|
|
26332
|
+
content: { "application/json": { schema: US } }
|
|
26162
26333
|
},
|
|
26163
26334
|
500: {
|
|
26164
26335
|
description: "Server error during hydration",
|
|
26165
|
-
content: { "application/json": { schema:
|
|
26336
|
+
content: { "application/json": { schema: US } }
|
|
26166
26337
|
}
|
|
26167
26338
|
}
|
|
26168
26339
|
});
|
|
26169
|
-
|
|
26340
|
+
PS.openapi(GS, async (e) => {
|
|
26170
26341
|
try {
|
|
26171
26342
|
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);
|
|
26172
26343
|
if (!i && !a) {
|
|
@@ -26177,23 +26348,23 @@ IS.openapi(qS, async (e) => {
|
|
|
26177
26348
|
if (!c) return e.json({ error: `Channel '${n}' not found` }, 404);
|
|
26178
26349
|
let l = c.status === "disabled" || c.status === "inactive" || c.isEnabled === 0 || c.isEnabled === !1;
|
|
26179
26350
|
if (!i && l) return e.json({ error: `Channel '${c.key || n}' is currently inactive` }, 404);
|
|
26180
|
-
let u = e.env?.BUNDLED_DEFINITIONS,
|
|
26181
|
-
if (
|
|
26182
|
-
|
|
26351
|
+
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;
|
|
26352
|
+
if (g) try {
|
|
26353
|
+
h = typeof g == "string" ? JSON.parse(g) : g;
|
|
26183
26354
|
} catch (e) {
|
|
26184
26355
|
console.warn("[CMS Public Channel API] Failed to parse channel dataJson:", e);
|
|
26185
26356
|
}
|
|
26186
|
-
let
|
|
26187
|
-
...
|
|
26357
|
+
let _ = RS({
|
|
26358
|
+
...h,
|
|
26188
26359
|
...c
|
|
26189
|
-
},
|
|
26190
|
-
|
|
26191
|
-
let
|
|
26360
|
+
}, m);
|
|
26361
|
+
_ = await ux(t, _), _ = zS(_), _ = await BS(t, _, u);
|
|
26362
|
+
let v = {
|
|
26192
26363
|
id: c.id,
|
|
26193
26364
|
key: c.key,
|
|
26194
|
-
...
|
|
26365
|
+
..._
|
|
26195
26366
|
};
|
|
26196
|
-
return !i && !a && (e.header("X-Cache", "MISS"), await
|
|
26367
|
+
return !i && !a && (e.header("X-Cache", "MISS"), await IS(s, o, v, FS(e))), e.json(v, 200);
|
|
26197
26368
|
} catch (t) {
|
|
26198
26369
|
return console.error("[CMS Public Channel API] Error:", t), e.json({
|
|
26199
26370
|
error: "Failed to fetch public channel",
|
|
@@ -26203,8 +26374,8 @@ IS.openapi(qS, async (e) => {
|
|
|
26203
26374
|
});
|
|
26204
26375
|
//#endregion
|
|
26205
26376
|
//#region server/routes/public/assets.ts
|
|
26206
|
-
var
|
|
26207
|
-
function
|
|
26377
|
+
var KS = new $y();
|
|
26378
|
+
function qS(e, t) {
|
|
26208
26379
|
if (t === "webp") return "image/webp";
|
|
26209
26380
|
if (t === "avif") return "image/avif";
|
|
26210
26381
|
if (t === "jpeg" || t === "jpg") return "image/jpeg";
|
|
@@ -26213,7 +26384,7 @@ function YS(e, t) {
|
|
|
26213
26384
|
let n = e.toLowerCase();
|
|
26214
26385
|
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";
|
|
26215
26386
|
}
|
|
26216
|
-
var
|
|
26387
|
+
var JS = eb({
|
|
26217
26388
|
method: "get",
|
|
26218
26389
|
path: "/*",
|
|
26219
26390
|
summary: "Serve & Optimize Media Assets",
|
|
@@ -26270,12 +26441,15 @@ var XS = eb({
|
|
|
26270
26441
|
}
|
|
26271
26442
|
}
|
|
26272
26443
|
});
|
|
26273
|
-
|
|
26444
|
+
KS.openapi(JS, async (e) => {
|
|
26274
26445
|
try {
|
|
26275
26446
|
let t = e.req.path.replace(/^\/media\//, "").replace(/^\//, "");
|
|
26276
26447
|
if (!t) return e.text("Asset key missing", 400);
|
|
26277
26448
|
let { w: n, h: r, q: i, f: a } = e.req.valid("query"), o = !!(n || r || i || a), s = e.req.header("Accept") || "", c = "";
|
|
26278
|
-
|
|
26449
|
+
if (o) {
|
|
26450
|
+
let e = !a || a === "auto";
|
|
26451
|
+
a === "avif" || e && s.includes("image/avif") ? c = "avif" : a === "webp" || e && s.includes("image/webp") ? c = "webp" : a === "jpeg" || a === "jpg" ? c = "jpeg" : a === "png" && (c = "png");
|
|
26452
|
+
}
|
|
26279
26453
|
let l = typeof caches < "u" && caches?.default ? caches.default : null, u = e.req.url;
|
|
26280
26454
|
if (o && c && !a) {
|
|
26281
26455
|
let e = new URL(u);
|
|
@@ -26290,7 +26464,7 @@ JS.openapi(XS, async (e) => {
|
|
|
26290
26464
|
if (!m) return e.text(`Asset not found: ${t}`, 404);
|
|
26291
26465
|
if (!o) {
|
|
26292
26466
|
let n = e.body(m, 200, {
|
|
26293
|
-
"Content-Type":
|
|
26467
|
+
"Content-Type": qS(t),
|
|
26294
26468
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
26295
26469
|
});
|
|
26296
26470
|
return l && d && e.executionCtx?.waitUntil && e.executionCtx.waitUntil(l.put(d, n.clone())), n;
|
|
@@ -26304,7 +26478,7 @@ JS.openapi(XS, async (e) => {
|
|
|
26304
26478
|
key: t,
|
|
26305
26479
|
env: e.env,
|
|
26306
26480
|
req: e.req.raw
|
|
26307
|
-
}), _ =
|
|
26481
|
+
}), _ = qS(t, c), v = e.body(g, 200, {
|
|
26308
26482
|
"Content-Type": _,
|
|
26309
26483
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
26310
26484
|
});
|
|
@@ -26315,8 +26489,8 @@ JS.openapi(XS, async (e) => {
|
|
|
26315
26489
|
});
|
|
26316
26490
|
//#endregion
|
|
26317
26491
|
//#region server/routes/public/paths.ts
|
|
26318
|
-
var
|
|
26319
|
-
function
|
|
26492
|
+
var YS = new $y();
|
|
26493
|
+
function XS(e, t) {
|
|
26320
26494
|
let n = /* @__PURE__ */ new Date();
|
|
26321
26495
|
if (e && String(e).trim() !== "") {
|
|
26322
26496
|
let t = new Date(e);
|
|
@@ -26328,73 +26502,73 @@ function QS(e, t) {
|
|
|
26328
26502
|
}
|
|
26329
26503
|
return !0;
|
|
26330
26504
|
}
|
|
26331
|
-
var
|
|
26505
|
+
var ZS = X({
|
|
26506
|
+
channelId: J().optional().openapi({ description: "Optional channel ID/key to filter and resolve root paths for" }),
|
|
26507
|
+
channel: J().optional().openapi({ description: "Legacy alias for channelId" })
|
|
26508
|
+
}), QS = z_(J()).openapi("PathsResponse"), $S = X({
|
|
26332
26509
|
error: J(),
|
|
26333
26510
|
details: J().optional()
|
|
26334
|
-
}).openapi("ErrorResponse"),
|
|
26511
|
+
}).openapi("ErrorResponse"), eC = eb({
|
|
26335
26512
|
method: "get",
|
|
26336
26513
|
path: "/",
|
|
26337
26514
|
summary: "Fetch All Public Paths",
|
|
26338
|
-
description: "Retrieves a deduplicated array of all active, published node paths
|
|
26515
|
+
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.",
|
|
26339
26516
|
tags: ["Public Paths API"],
|
|
26517
|
+
request: { query: ZS },
|
|
26340
26518
|
responses: {
|
|
26341
26519
|
200: {
|
|
26342
26520
|
description: "Array of valid public URL paths",
|
|
26343
|
-
content: { "application/json": { schema:
|
|
26521
|
+
content: { "application/json": { schema: QS } }
|
|
26344
26522
|
},
|
|
26345
26523
|
500: {
|
|
26346
26524
|
description: "Server error fetching paths",
|
|
26347
|
-
content: { "application/json": { schema:
|
|
26525
|
+
content: { "application/json": { schema: $S } }
|
|
26348
26526
|
}
|
|
26349
26527
|
}
|
|
26350
26528
|
});
|
|
26351
|
-
|
|
26529
|
+
YS.openapi(eC, async (e) => {
|
|
26352
26530
|
try {
|
|
26353
|
-
let t =
|
|
26354
|
-
|
|
26355
|
-
let
|
|
26356
|
-
|
|
26357
|
-
}
|
|
26358
|
-
let
|
|
26359
|
-
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
|
|
26364
|
-
|
|
26365
|
-
|
|
26531
|
+
let t = e.get("db"), n = e.req.valid("query"), r = n.channelId || n.channel, i = "", a = [];
|
|
26532
|
+
if (r && r !== "all") {
|
|
26533
|
+
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));
|
|
26534
|
+
e && (i = "AND nr.channelId = ?", a.push(Number(e.id)));
|
|
26535
|
+
}
|
|
26536
|
+
let o = await t.prepare(`
|
|
26537
|
+
SELECT
|
|
26538
|
+
nr.path,
|
|
26539
|
+
cn.contentType as nodeType,
|
|
26540
|
+
cn.dataJson
|
|
26541
|
+
FROM node_routes nr
|
|
26542
|
+
INNER JOIN content_nodes cn ON nr.nodeId = cn.id
|
|
26543
|
+
WHERE nr.isCanonical = 1
|
|
26544
|
+
AND (cn.status = 'published' OR cn.status = 'active')
|
|
26545
|
+
AND (cn.deletedAt IS NULL OR cn.deletedAt = '')
|
|
26546
|
+
${i}
|
|
26547
|
+
ORDER BY nr.path ASC
|
|
26548
|
+
`).all(...a), s = Array.isArray(o) ? o : o?.results || [], c = [];
|
|
26549
|
+
for (let e of s) {
|
|
26550
|
+
if (e.nodeType === "external-link" || !e.path) continue;
|
|
26551
|
+
let t = !0;
|
|
26552
|
+
if (e.dataJson) try {
|
|
26366
26553
|
let n = typeof e.dataJson == "string" ? JSON.parse(e.dataJson) : e.dataJson;
|
|
26367
|
-
|
|
26368
|
-
} catch {
|
|
26369
|
-
|
|
26370
|
-
}
|
|
26371
|
-
}
|
|
26372
|
-
function o(e = null, t = "") {
|
|
26373
|
-
let n = e == null || e === "" || e === "null" ? "__ROOT__" : String(e), s = i.get(n) || [];
|
|
26374
|
-
for (let e of s) {
|
|
26375
|
-
let n = a.get(String(e.treeNodeId)) || {}, i = e.status === "published" || e.status === "active", s = QS(n.startShowingAt, n.stopShowingAt);
|
|
26376
|
-
if (!i || !s) continue;
|
|
26377
|
-
let c = (e.slug || "").replace(/^\/+|\/+$/g, ""), l = c === "home" || c === "homee" ? "/" : `${t}/${c}`.replace(/\/+/g, "/");
|
|
26378
|
-
e.nodeType !== "external-link" && r.push(l);
|
|
26379
|
-
let u = l === "/" ? "" : l;
|
|
26380
|
-
o(e.treeNodeId, u);
|
|
26381
|
-
}
|
|
26554
|
+
t = XS(n?.startShowingAt, n?.stopShowingAt);
|
|
26555
|
+
} catch {}
|
|
26556
|
+
t && c.push(e.path);
|
|
26382
26557
|
}
|
|
26383
|
-
|
|
26384
|
-
|
|
26385
|
-
return e.json(s, 200);
|
|
26558
|
+
let l = [...new Set(c)];
|
|
26559
|
+
return e.json(l, 200);
|
|
26386
26560
|
} catch (t) {
|
|
26387
26561
|
return console.error("[CMS Paths API] Error:", t), e.json({ error: "Failed to fetch paths" }, 500);
|
|
26388
26562
|
}
|
|
26389
26563
|
});
|
|
26390
26564
|
//#endregion
|
|
26391
26565
|
//#region server/routes/public/taxonomies.ts
|
|
26392
|
-
var
|
|
26393
|
-
function
|
|
26566
|
+
var tC = new $y();
|
|
26567
|
+
function nC(e) {
|
|
26394
26568
|
let t = (e || "").trim().toLowerCase(), n = dx()?.taxonomies || {};
|
|
26395
26569
|
return n[t] ? t : n[`${t}s`] ? `${t}s` : t.endsWith("s") && n[t.slice(0, -1)] ? t.slice(0, -1) : t;
|
|
26396
26570
|
}
|
|
26397
|
-
var
|
|
26571
|
+
var rC = X({
|
|
26398
26572
|
id: c_(),
|
|
26399
26573
|
taxonomy: J(),
|
|
26400
26574
|
key: J(),
|
|
@@ -26404,14 +26578,14 @@ var iC = X({
|
|
|
26404
26578
|
data: tv(k_()),
|
|
26405
26579
|
createdAt: J(),
|
|
26406
26580
|
updatedAt: J()
|
|
26407
|
-
}),
|
|
26581
|
+
}), iC = X({
|
|
26408
26582
|
taxonomy: J(),
|
|
26409
|
-
items: z_(
|
|
26583
|
+
items: z_(rC),
|
|
26410
26584
|
total: c_()
|
|
26411
|
-
}).openapi("TaxonomyResponse"),
|
|
26585
|
+
}).openapi("TaxonomyResponse"), aC = X({
|
|
26412
26586
|
error: J(),
|
|
26413
26587
|
details: J().optional()
|
|
26414
|
-
}).openapi("ErrorResponse"),
|
|
26588
|
+
}).openapi("ErrorResponse"), oC = eb({
|
|
26415
26589
|
method: "get",
|
|
26416
26590
|
path: "/{taxonomy}",
|
|
26417
26591
|
summary: "Fetch Public Taxonomy Terms",
|
|
@@ -26421,17 +26595,17 @@ var iC = X({
|
|
|
26421
26595
|
responses: {
|
|
26422
26596
|
200: {
|
|
26423
26597
|
description: "List of taxonomy terms",
|
|
26424
|
-
content: { "application/json": { schema:
|
|
26598
|
+
content: { "application/json": { schema: iC } }
|
|
26425
26599
|
},
|
|
26426
26600
|
500: {
|
|
26427
26601
|
description: "Server error",
|
|
26428
|
-
content: { "application/json": { schema:
|
|
26602
|
+
content: { "application/json": { schema: aC } }
|
|
26429
26603
|
}
|
|
26430
26604
|
}
|
|
26431
26605
|
});
|
|
26432
|
-
|
|
26606
|
+
tC.openapi(oC, async (e) => {
|
|
26433
26607
|
try {
|
|
26434
|
-
let t = e.get("db"), n = $b(e), r = e.req.valid("param").taxonomy, i =
|
|
26608
|
+
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";
|
|
26435
26609
|
if (!o) {
|
|
26436
26610
|
let t = await n.get(a);
|
|
26437
26611
|
if (t) return e.header("X-Cache", "HIT"), e.json(t);
|
|
@@ -26467,7 +26641,7 @@ nC.openapi(sC, async (e) => {
|
|
|
26467
26641
|
});
|
|
26468
26642
|
//#endregion
|
|
26469
26643
|
//#region server/index.ts
|
|
26470
|
-
var $ = new $y(),
|
|
26644
|
+
var $ = new $y(), sC = !1;
|
|
26471
26645
|
$.use("*", t()), $.use("/media/*", t({
|
|
26472
26646
|
origin: "*",
|
|
26473
26647
|
allowMethods: [
|
|
@@ -26488,13 +26662,13 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
26488
26662
|
let n = new URL(e.req.url), r = (e.req.header("host") || n.hostname).split(":")[0];
|
|
26489
26663
|
e.set("currentDomain", r);
|
|
26490
26664
|
let i = wb(e);
|
|
26491
|
-
if (e.set("db", i), !
|
|
26492
|
-
await Mb(i),
|
|
26665
|
+
if (e.set("db", i), !sC) try {
|
|
26666
|
+
await Mb(i), sC = !0;
|
|
26493
26667
|
} catch (e) {
|
|
26494
26668
|
console.error("❌ [CMS Server] Failed to initialize system tables on cold start:", e);
|
|
26495
26669
|
}
|
|
26496
26670
|
await t();
|
|
26497
|
-
}), $.route("/media",
|
|
26671
|
+
}), $.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", {
|
|
26498
26672
|
openapi: "3.0.0",
|
|
26499
26673
|
info: {
|
|
26500
26674
|
title: "KAMA Engine Public API",
|
|
@@ -26513,4 +26687,4 @@ $.use("*", t()), $.use("/media/*", t({
|
|
|
26513
26687
|
return t();
|
|
26514
26688
|
});
|
|
26515
26689
|
//#endregion
|
|
26516
|
-
export { $ as app, $ as default,
|
|
26690
|
+
export { $ as app, $ as default, qx as compileDefinitions, Jx as getCmsDefinitions };
|