From 81fa96ec5bc67e6fa08a3342e18d2c4d3e1c87e2 Mon Sep 17 00:00:00 2001 From: Rizky Date: Thu, 15 Feb 2024 06:45:53 +0700 Subject: [PATCH] wip fix --- pkgs/api/_prasi.ts | 20 +++++++++++++++++--- pkgs/utils/global.ts | 18 ++++++++++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/pkgs/api/_prasi.ts b/pkgs/api/_prasi.ts index 311f49e..30c95e0 100644 --- a/pkgs/api/_prasi.ts +++ b/pkgs/api/_prasi.ts @@ -1,6 +1,6 @@ import { readAsync } from "fs-jetpack"; import { apiContext } from "service-srv"; -import { g } from "utils/global"; +import { SinglePage, g } from "utils/global"; import { dir } from "utils/dir"; import { gzipAsync } from "utils/gzip"; @@ -23,9 +23,20 @@ export const _ = { _: () => { 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 () => { if (gz) { - let layout = null as any; + let layout = null as null | SinglePage; for (const l of gz.layouts) { if (!layout) layout = l; if (l.is_default_layout) layout = l; @@ -37,7 +48,10 @@ export const _ = { urls: gz.pages.map((e) => { return { id: e.id, url: e.url }; }), - layout, + layout: { + id: layout?.id, + root: layout?.content_tree + }, }) ); diff --git a/pkgs/utils/global.ts b/pkgs/utils/global.ts index 418b806..585c854 100644 --- a/pkgs/utils/global.ts +++ b/pkgs/utils/global.ts @@ -14,6 +14,14 @@ type SingleRoute = { path: string; }; +export type SinglePage = { + id: string; + url: string; + name: true; + content_tree: any; + is_default_layout: true; +} + type PrasiServer = { ws?: WebSocketHandler<{ url: string }>; http: (arg: { @@ -67,14 +75,8 @@ export const g = global as unknown as { { id: string; url: string; name: true; content_tree: any } >; gz: null | { - layouts: { - id: string; - url: string; - name: true; - content_tree: any; - is_default_layout: true; - }[]; - pages: { id: string; url: string; name: true; content_tree: any }[]; + layouts: SinglePage[]; + pages: SinglePage[]; site: {}; comps: { id: string; content_tree: true }[]; code: {