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