fix: 状态镜像防冲掉——服务端按 key 合并,客户端读不到宿主就不写
This commit is contained in:
+10
-3
@@ -225,7 +225,7 @@ function resolveDshHomeSafe() {
|
||||
cachedDshHome = baseDshHome();
|
||||
return cachedDshHome;
|
||||
}
|
||||
var PLUGIN_VERSION = false ? "dev" : "0.5.2-local.2";
|
||||
var PLUGIN_VERSION = false ? "dev" : "0.5.2-local.3";
|
||||
var name = "dsh-worktable";
|
||||
var inject = ["webServer", "sessions"];
|
||||
var HEALTH_PATH = "/api/worktable/health";
|
||||
@@ -857,11 +857,18 @@ function apply(ctx) {
|
||||
}
|
||||
try {
|
||||
const body = await readJsonBody(req);
|
||||
const state = body && typeof body.state === "object" && body.state !== null ? body.state : null;
|
||||
if (!state) {
|
||||
const incoming = body && typeof body.state === "object" && body.state !== null ? body.state : null;
|
||||
if (!incoming) {
|
||||
json(res, 400, { error: "missing state" });
|
||||
return;
|
||||
}
|
||||
let previous = null;
|
||||
try {
|
||||
const raw = await readFile(file, "utf8");
|
||||
previous = JSON.parse(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw);
|
||||
} catch {
|
||||
}
|
||||
const state = previous && typeof previous === "object" && !Array.isArray(previous) ? { ...previous, ...incoming } : incoming;
|
||||
const text = JSON.stringify(state);
|
||||
if (text.length > 20 * 1024 * 1024) {
|
||||
json(res, 413, { error: "state too large" });
|
||||
|
||||
Reference in New Issue
Block a user