wip snapshot

This commit is contained in:
Rizky 2024-01-10 20:21:39 +07:00
parent 0f4cfc87f7
commit 8717951270
4 changed files with 31 additions and 9 deletions

View File

@ -3,13 +3,16 @@ import { ESite } from "../../../../web/src/nova/ed/logic/ed-global";
import { SAction } from "../actions";
import { activity } from "../entity/activity";
import { SyncConnection } from "../type";
import { prepCode } from "../editor/code/prep-code";
import { docs } from "../entity/docs";
import { snapshot } from "../entity/snapshot";
export const site_load: SAction["site"]["load"] = async function (
this: SyncConnection,
id: string
site_id: string
) {
if (validate(id)) {
const site = await db.site.findFirst({ where: { id } });
if (validate(site_id)) {
const site = await db.site.findFirst({ where: { id: site_id } });
if (site) {
if (this.conf) this.conf.site_id = site.id;
@ -22,13 +25,15 @@ export const site_load: SAction["site"]["load"] = async function (
const layout = await db.page.findFirst({
where: {
id_site: id,
id_site: site_id,
is_deleted: false,
is_default_layout: true,
},
select: { id: true },
});
await prepCode(site_id, "site");
return {
id: site.id,
name: site.name,
@ -37,6 +42,7 @@ export const site_load: SAction["site"]["load"] = async function (
js: site.js || "",
js_compiled: site.js_compiled || "",
layout: { id: layout?.id || "", snapshot: null },
code: { snapshot: null },
};
}
}

View File

@ -1,7 +1,6 @@
import { dir } from "dir";
import { g } from "utils/global";
import { dirAsync } from "fs-jetpack";
import { docs } from "../../entity/docs";
import { g } from "utils/global";
export type DBCode = Exclude<Awaited<ReturnType<typeof getCode>>, null>;
export const prepCode = async (site_id: string, name: string) => {

View File

@ -28,12 +28,27 @@ type PageSnapshot = {
url: string;
id_site: string;
};
type SiteSnapshot = {
type: "site";
id: string;
id_doc: number;
name: string;
src_bin: Uint8Array;
build_bin: Uint8Array;
};
type DocSnapshotMap = {
page: PageSnapshot;
comp: CompSnapshot;
site: SiteSnapshot;
"": EmptySnapshot;
};
export type DocSnapshot = EmptySnapshot | CompSnapshot | PageSnapshot;
export type DocSnapshot =
| EmptySnapshot
| CompSnapshot
| PageSnapshot
| SiteSnapshot;
const emptySnapshot: DocSnapshot = {
type: "",

View File

@ -19,8 +19,10 @@ export const EmptySite = {
js_compiled: "",
layout: {
id: "--",
meta: {} as Record<string, IMeta>,
entry: [] as string[],
snapshot: null as null | Uint8Array,
},
code: {
snapshot: null as null | Uint8Array,
},
};