diff --git a/app/srv/api/prod-zip.ts b/app/srv/api/prod-zip.ts index e8c298bb..6962c67e 100644 --- a/app/srv/api/prod-zip.ts +++ b/app/srv/api/prod-zip.ts @@ -4,6 +4,7 @@ import fs from "fs"; import path from "path"; import { gzipAsync } from "../ws/sync/entity/zlib"; import { validate } from "uuid"; +import { dir } from "dir"; export const _ = { url: "/prod-zip/:site_id", @@ -30,6 +31,7 @@ export const _ = { code.path(site_id, "server", "build") ), site: readDirectoryRecursively(code.path(site_id, "site", "build")), + core: readDirectoryRecursively(dir.data(`prod`)), }, }; diff --git a/app/srv/ws/edit/action/diff-local.ts b/app/srv/ws/edit/action/diff-local.ts index 4d0d0d91..c2fbf9d7 100644 --- a/app/srv/ws/edit/action/diff-local.ts +++ b/app/srv/ws/edit/action/diff-local.ts @@ -1,4 +1,6 @@ +import { gzipAsync } from "../../sync/entity/zlib"; import { eg } from "../edit-global"; +const history = {} as Record; export const diffLocal = (ws: any, msg: any) => { return new Promise((resolve) => { @@ -31,6 +33,37 @@ export const diffLocal = (ws: any, msg: any) => { if (msg.id) { const page = eg.edit.page[msg.id].doc.getMap("map").toJSON(); try { + const id = msg.id; + let mode = "create" as "create" | "update"; + const cur = Math.round(Date.now() / 5000) + ""; + if (history[id] && history[id] === cur) { + mode = "update"; + } + history[id] = cur; + if (mode === "create") { + await _db.page_history.create({ + data: { + id_page: id, + content_tree: await gzipAsync( + JSON.stringify(page.content_tree) + ), + ts: history[id], + }, + }); + } else { + await _db.page_history.updateMany({ + data: { + content_tree: await gzipAsync( + JSON.stringify(page.content_tree) + ), + }, + where: { + id_page: id, + ts: history[id], + }, + }); + } + await _db.page.update({ where: { id: page.id }, data: {