wip snapshot
This commit is contained in:
parent
0f4cfc87f7
commit
8717951270
|
|
@ -3,13 +3,16 @@ import { ESite } from "../../../../web/src/nova/ed/logic/ed-global";
|
||||||
import { SAction } from "../actions";
|
import { SAction } from "../actions";
|
||||||
import { activity } from "../entity/activity";
|
import { activity } from "../entity/activity";
|
||||||
import { SyncConnection } from "../type";
|
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 (
|
export const site_load: SAction["site"]["load"] = async function (
|
||||||
this: SyncConnection,
|
this: SyncConnection,
|
||||||
id: string
|
site_id: string
|
||||||
) {
|
) {
|
||||||
if (validate(id)) {
|
if (validate(site_id)) {
|
||||||
const site = await db.site.findFirst({ where: { id } });
|
const site = await db.site.findFirst({ where: { id: site_id } });
|
||||||
if (site) {
|
if (site) {
|
||||||
if (this.conf) this.conf.site_id = site.id;
|
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({
|
const layout = await db.page.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id_site: id,
|
id_site: site_id,
|
||||||
is_deleted: false,
|
is_deleted: false,
|
||||||
is_default_layout: true,
|
is_default_layout: true,
|
||||||
},
|
},
|
||||||
select: { id: true },
|
select: { id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await prepCode(site_id, "site");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: site.id,
|
id: site.id,
|
||||||
name: site.name,
|
name: site.name,
|
||||||
|
|
@ -37,6 +42,7 @@ export const site_load: SAction["site"]["load"] = async function (
|
||||||
js: site.js || "",
|
js: site.js || "",
|
||||||
js_compiled: site.js_compiled || "",
|
js_compiled: site.js_compiled || "",
|
||||||
layout: { id: layout?.id || "", snapshot: null },
|
layout: { id: layout?.id || "", snapshot: null },
|
||||||
|
code: { snapshot: null },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { dir } from "dir";
|
import { dir } from "dir";
|
||||||
import { g } from "utils/global";
|
|
||||||
import { dirAsync } from "fs-jetpack";
|
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 type DBCode = Exclude<Awaited<ReturnType<typeof getCode>>, null>;
|
||||||
|
|
||||||
export const prepCode = async (site_id: string, name: string) => {
|
export const prepCode = async (site_id: string, name: string) => {
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,27 @@ type PageSnapshot = {
|
||||||
url: string;
|
url: string;
|
||||||
id_site: string;
|
id_site: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SiteSnapshot = {
|
||||||
|
type: "site";
|
||||||
|
id: string;
|
||||||
|
id_doc: number;
|
||||||
|
name: string;
|
||||||
|
src_bin: Uint8Array;
|
||||||
|
build_bin: Uint8Array;
|
||||||
|
};
|
||||||
|
|
||||||
type DocSnapshotMap = {
|
type DocSnapshotMap = {
|
||||||
page: PageSnapshot;
|
page: PageSnapshot;
|
||||||
comp: CompSnapshot;
|
comp: CompSnapshot;
|
||||||
|
site: SiteSnapshot;
|
||||||
"": EmptySnapshot;
|
"": EmptySnapshot;
|
||||||
};
|
};
|
||||||
export type DocSnapshot = EmptySnapshot | CompSnapshot | PageSnapshot;
|
export type DocSnapshot =
|
||||||
|
| EmptySnapshot
|
||||||
|
| CompSnapshot
|
||||||
|
| PageSnapshot
|
||||||
|
| SiteSnapshot;
|
||||||
|
|
||||||
const emptySnapshot: DocSnapshot = {
|
const emptySnapshot: DocSnapshot = {
|
||||||
type: "",
|
type: "",
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,10 @@ export const EmptySite = {
|
||||||
js_compiled: "",
|
js_compiled: "",
|
||||||
layout: {
|
layout: {
|
||||||
id: "--",
|
id: "--",
|
||||||
meta: {} as Record<string, IMeta>,
|
snapshot: null as null | Uint8Array,
|
||||||
entry: [] as string[],
|
},
|
||||||
|
code: {
|
||||||
|
snapshot: null as null | Uint8Array,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue