diff --git a/app/srv/ws/sync/actions/site_load.ts b/app/srv/ws/sync/actions/site_load.ts index 34e8ebe7..f1d80375 100644 --- a/app/srv/ws/sync/actions/site_load.ts +++ b/app/srv/ws/sync/actions/site_load.ts @@ -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 }, }; } } diff --git a/app/srv/ws/sync/editor/code/prep-code.ts b/app/srv/ws/sync/editor/code/prep-code.ts index bb4e6e5b..cb1d5604 100644 --- a/app/srv/ws/sync/editor/code/prep-code.ts +++ b/app/srv/ws/sync/editor/code/prep-code.ts @@ -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>, null>; export const prepCode = async (site_id: string, name: string) => { diff --git a/app/srv/ws/sync/entity/snapshot.ts b/app/srv/ws/sync/entity/snapshot.ts index d5b90647..13c9755d 100644 --- a/app/srv/ws/sync/entity/snapshot.ts +++ b/app/srv/ws/sync/entity/snapshot.ts @@ -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: "", diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index 1189c3e8..677f7e89 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -19,8 +19,10 @@ export const EmptySite = { js_compiled: "", layout: { id: "--", - meta: {} as Record, - entry: [] as string[], + snapshot: null as null | Uint8Array, + }, + code: { + snapshot: null as null | Uint8Array, }, };