diff --git a/app/srv/ws/sync/actions-def.ts b/app/srv/ws/sync/actions-def.ts index 1fc9dc35..0c588fe7 100644 --- a/app/srv/ws/sync/actions-def.ts +++ b/app/srv/ws/sync/actions-def.ts @@ -3,7 +3,7 @@ export const SyncActionDefinition = { "list": "0", "group": "1", "load": "2", - "js": "3" + "update": "3" }, "comp": { "new": "4", @@ -30,7 +30,7 @@ export const SyncActionPaths = { "0": "site.list", "1": "site.group", "2": "site.load", - "3": "site.js", + "3": "site.update", "4": "comp.new", "5": "comp.list", "6": "comp.group", diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index 265e35a5..cf3db50a 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -23,10 +23,14 @@ export const SyncActions = { ({}) as Record, group: async () => ({}) as ReturnType, load: async (id: string) => ({}) as ESite | void, - js: async ( + update: async ( id: string, - js_compressed: Uint8Array, - built_compressed: Uint8Array + site: Partial< + Omit & { + js: Buffer; + js_compiled: Buffer; + } + > ) => {}, }, comp: { diff --git a/app/srv/ws/sync/actions/index.ts b/app/srv/ws/sync/actions/index.ts index d0fa6da7..eabd69fc 100644 --- a/app/srv/ws/sync/actions/index.ts +++ b/app/srv/ws/sync/actions/index.ts @@ -1,6 +1,6 @@ export * from "./activity"; export * from "./client_info"; -export * from "./site_js"; +export * from "./site_update"; export * from "./site_load"; export * from "./site_group"; export * from "./page_load"; diff --git a/app/srv/ws/sync/actions/site_js.ts b/app/srv/ws/sync/actions/site_update.ts similarity index 65% rename from app/srv/ws/sync/actions/site_js.ts rename to app/srv/ws/sync/actions/site_update.ts index b600bc6f..6d94fcec 100644 --- a/app/srv/ws/sync/actions/site_js.ts +++ b/app/srv/ws/sync/actions/site_update.ts @@ -7,21 +7,24 @@ import { conns } from "../entity/conn"; import { sendWS } from "../sync-handler"; const decoder = new TextDecoder(); -export const site_js: SAction["site"]["js"] = async function ( +export const site_update: SAction["site"]["update"] = async function ( this: SyncConnection, id: string, - js_compressed, - built_compressed + site ) { if (validate(id)) { - const js = decoder.decode(await gunzipAsync(js_compressed)); - const js_compiled = decoder.decode(await gunzipAsync(built_compressed)); + const updated = {} as any; + for (const [key, value] of Object.entries(site)) { + if (key === "js" || key === "js_compiled") { + updated[key] = decoder.decode(await gunzipAsync(value as any)); + } else { + updated[key] = value; + } + } + await db.site.update({ where: { id }, - data: { - js, - js_compiled, - }, + data: updated, }); user.active.findAll({ site_id: id }).map((e) => { @@ -31,7 +34,7 @@ export const site_js: SAction["site"]["js"] = async function ( sendWS(ws, { type: SyncType.Event, event: "site_js_updated", - data: { js: js_compressed, jsc: built_compressed }, + data: site, }); } }); diff --git a/app/web/src/render/ed/logic/ed-sync.tsx b/app/web/src/render/ed/logic/ed-sync.tsx index e2a02b43..7707e157 100644 --- a/app/web/src/render/ed/logic/ed-sync.tsx +++ b/app/web/src/render/ed/logic/ed-sync.tsx @@ -108,12 +108,14 @@ export const edInitSync = (p: PG) => { p.site = site; p.render(); }, - site_js_updated(arg) { - const js = decoder.decode(decompress(arg.js)); - const jsc = decoder.decode(decompress(arg.jsc)); - - p.site.js = js; - p.site.js_compiled = jsc; + site_js_updated(site) { + for (const [k, v] of Object.entries(site)) { + if (k === "js" || k === "js_compiled") { + p.site[k] = decoder.decode(decompress(v as any)); + } else { + (p.site as any)[k] = v; + } + } p.render(); }, async remote_svlocal(data) { diff --git a/app/web/src/render/ed/panel/script/site.tsx b/app/web/src/render/ed/panel/script/site.tsx index 4dfdaef8..ae2f3bd2 100644 --- a/app/web/src/render/ed/panel/script/site.tsx +++ b/app/web/src/render/ed/panel/script/site.tsx @@ -40,15 +40,13 @@ export const EdScriptSite = () => { p.site.js = src; p.site.js_compiled = built; - // todo: re-run site js clearTimeout(local.timeout); local.timeout = setTimeout(async () => { - await p.sync.site.js( - p.site.id, - Buffer.from(compress(src)), - Buffer.from(compress(built)) - ); + await p.sync.site.update(p.site.id, { + js: Buffer.from(compress(src)), + js_compiled: Buffer.from(compress(built)), + }); }, 1000); } }, diff --git a/app/web/src/utils/sync/ws-client.ts b/app/web/src/utils/sync/ws-client.ts index 0706a24f..bfeafced 100644 --- a/app/web/src/utils/sync/ws-client.ts +++ b/app/web/src/utils/sync/ws-client.ts @@ -82,7 +82,14 @@ export const clientStartSync = async (arg: { id: string; sv_local: Uint8Array; }) => void; - site_js_updated: (arg: { js: Uint8Array; jsc: Uint8Array }) => void; + site_js_updated: ( + arg: Partial< + Omit & { + js: Uint8Array; + js_compiled: Uint8Array; + } + > + ) => void; activity: (arg: { page: Record; comp: Record;