This commit is contained in:
Rizky 2024-02-15 06:45:53 +07:00
parent 7e3134d5c0
commit 81fa96ec5b
2 changed files with 27 additions and 11 deletions

View File

@ -1,6 +1,6 @@
import { readAsync } from "fs-jetpack"; import { readAsync } from "fs-jetpack";
import { apiContext } from "service-srv"; import { apiContext } from "service-srv";
import { g } from "utils/global"; import { SinglePage, g } from "utils/global";
import { dir } from "utils/dir"; import { dir } from "utils/dir";
import { gzipAsync } from "utils/gzip"; import { gzipAsync } from "utils/gzip";
@ -23,9 +23,20 @@ export const _ = {
_: () => { _: () => {
res.send({ prasi: "v2" }); res.send({ prasi: "v2" });
}, },
code: async () => {
if (gz) {
const path = parts.slice(1).join("/");
if (gz.code.site[path]) {
res.send(
gz.code.site[path],
req.headers.get("accept-encoding") || ""
);
}
}
},
route: async () => { route: async () => {
if (gz) { if (gz) {
let layout = null as any; let layout = null as null | SinglePage;
for (const l of gz.layouts) { for (const l of gz.layouts) {
if (!layout) layout = l; if (!layout) layout = l;
if (l.is_default_layout) layout = l; if (l.is_default_layout) layout = l;
@ -37,7 +48,10 @@ export const _ = {
urls: gz.pages.map((e) => { urls: gz.pages.map((e) => {
return { id: e.id, url: e.url }; return { id: e.id, url: e.url };
}), }),
layout, layout: {
id: layout?.id,
root: layout?.content_tree
},
}) })
); );

View File

@ -14,6 +14,14 @@ type SingleRoute = {
path: string; path: string;
}; };
export type SinglePage = {
id: string;
url: string;
name: true;
content_tree: any;
is_default_layout: true;
}
type PrasiServer = { type PrasiServer = {
ws?: WebSocketHandler<{ url: string }>; ws?: WebSocketHandler<{ url: string }>;
http: (arg: { http: (arg: {
@ -67,14 +75,8 @@ export const g = global as unknown as {
{ id: string; url: string; name: true; content_tree: any } { id: string; url: string; name: true; content_tree: any }
>; >;
gz: null | { gz: null | {
layouts: { layouts: SinglePage[];
id: string; pages: SinglePage[];
url: string;
name: true;
content_tree: any;
is_default_layout: true;
}[];
pages: { id: string; url: string; name: true; content_tree: any }[];
site: {}; site: {};
comps: { id: string; content_tree: true }[]; comps: { id: string; content_tree: true }[];
code: { code: {