feat(state): 恢复「云状态 + git 历史」能力 (REQ-20261117-0013)
背景:qiudl 分支(0.4.9-rc.2,用户原本在用的)有云状态功能——状态落在一个 独立 git 仓(~/Library/Application Support/dsh-worktable-state/),由 launchd 每 5 分钟 commit+push。Gitea 0.5.x 线没有这个功能,只有 DSH_HOME 下的单文件 镜像(worktable-state.json)。升级到 0.5.3 后两处路径不同,用户 14 个工作台 布局在界面上「消失」(数据本身还在那个 git 仓里)。 改法(不移植 976 行云状态代码,改走配置指针): - 宿主侧 /api/worktable/state 的文件路径改为优先取本机配置 03_local/local.json 的 cloudStatePath(指向那个 git 仓),未配置时回落到 DSH_HOME/worktable-state.json(与旧行为一致) - 新增 localConfigPaths / readLocalConfigField:候选链含环境变量 DSH_WORKTABLE_LOCAL_DIR、插件根相对 03_local、DSH_HOME/03_local - 客户端兼容旧 updatedAt 形态:旧线写 ISO 字符串,本线写毫秒数字,两种都认 (否则指向旧文件后永远判「宿主不比本地新」而不回填) 这样云状态写入自动进 git 仓,每次变更都有提交历史,launchd 继续 push 到远端。 版本 0.5.3-local.2 -> 0.5.3-local.3 验证:build 通过;client-factory-gate 10/10;7 个兼容回归 105/105; 配置解析链在本机实测命中 <DSH_HOME>/03_local/local.json -> 云状态 git 仓路径
This commit is contained in:
@@ -9175,7 +9175,7 @@ var CHANGELOG_V030 = `\u66F4\u65B0\u516C\u544A \xB7 v0.5.1
|
||||
\u30103.1 \u6587\u5B57\u4E0E\u7EC6\u8282\u6253\u78E8\u3011\u5168\u5C40\u5B57\u4F53\u4E0E\u5B57\u53F7\u7EDF\u4E00\u4F18\u5316\u3001\u4E0B\u62C9\u9762\u677F\u73BB\u7483\u5316\u4E0E\u5BF9\u9F50\u3001\u83DC\u5355\u70B9\u9009\u540E\u4FDD\u6301\u6253\u5F00\u4FBF\u4E8E\u8FDE\u7EED\u9884\u89C8\u3001\u6309\u94AE\u63CF\u8FB9\u4E0E\u60AC\u505C\u53CD\u9988\u7B49\u4EA4\u4E92\u7EC6\u8282\uFF1B\u540C\u65F6\u4FEE\u590D\u4E86\u591A\u9879\u4F53\u9A8C\u95EE\u9898\uFF08\u7167\u7247\u4E0A\u4F20\u6E05\u6670\u5EA6\u3001\u80CC\u666F\u7F51\u683C\u7EBF\u5728\u7167\u7247\u6A21\u5F0F\u4E0B\u4E0D\u751F\u6548\u3001\u6D45\u8272\u4E3B\u9898\u4E0B\u5DE5\u4F5C\u72B6\u6001\u5149\u6548\u4E0D\u53EF\u89C1\u7B49\uFF09\u3002`;
|
||||
|
||||
// src/client/updateCheck.ts
|
||||
var LOCAL_VERSION = false ? "dev" : "0.5.3-local.2";
|
||||
var LOCAL_VERSION = false ? "dev" : "0.5.3-local.3";
|
||||
var UPDATE_REPO = "Aisland-SJL/dsh-worktable";
|
||||
var K_UPDATE_CHECK = "dsh.worktable.updateCheck.v1";
|
||||
var K_LAST_CHECK = "dsh.worktable.lastUpdateCheck.v1";
|
||||
@@ -22158,7 +22158,8 @@ function WorktableSection(props) {
|
||||
return;
|
||||
}
|
||||
const host = res.state;
|
||||
const hostAt = typeof host?.updatedAt === "number" ? host.updatedAt : 0;
|
||||
const rawAt = host?.updatedAt;
|
||||
const hostAt = typeof rawAt === "number" ? rawAt : typeof rawAt === "string" ? Number.isFinite(Date.parse(rawAt)) ? Date.parse(rawAt) : 0 : 0;
|
||||
if (host && hostAt > localAt) {
|
||||
if (host.projects) persistProjects(normalizeProjects(host.projects));
|
||||
if (host.view) persistView(normalizeView(host.view));
|
||||
|
||||
+34
-3
@@ -225,7 +225,7 @@ function resolveDshHomeSafe() {
|
||||
cachedDshHome = baseDshHome();
|
||||
return cachedDshHome;
|
||||
}
|
||||
var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.2";
|
||||
var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.3";
|
||||
var name = "dsh-worktable";
|
||||
var inject = ["webServer", "sessions"];
|
||||
var HEALTH_PATH = "/api/worktable/health";
|
||||
@@ -843,12 +843,43 @@ function apply(ctx) {
|
||||
}
|
||||
}
|
||||
});
|
||||
const statePath = () => pathResolve(resolveDshHomeSafe(), "worktable-state.json");
|
||||
const localConfigPaths = (fileName) => {
|
||||
const out = [];
|
||||
const envDir = process.env.DSH_WORKTABLE_LOCAL_DIR;
|
||||
if (typeof envDir === "string" && envDir.trim()) out.push(pathResolve(envDir.trim(), fileName));
|
||||
try {
|
||||
const libDir = dirname(fileURLToPath(import.meta.url));
|
||||
out.push(pathResolve(libDir, "..", "03_local", fileName));
|
||||
out.push(pathResolve(libDir, "..", "..", "03_local", fileName));
|
||||
out.push(pathResolve(libDir, "..", "..", "..", "03_local", fileName));
|
||||
} catch {
|
||||
}
|
||||
try {
|
||||
const home = resolveDshHomeSafe();
|
||||
if (typeof home === "string" && home) out.push(pathResolve(home, "03_local", fileName));
|
||||
} catch {
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const readLocalConfigField = async (fileName, field) => {
|
||||
for (const file of localConfigPaths(fileName)) {
|
||||
try {
|
||||
const raw = await readFile(file, "utf8");
|
||||
const parsed = JSON.parse(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw);
|
||||
const value = parsed && typeof parsed === "object" ? parsed[field] : void 0;
|
||||
const text = typeof value === "string" ? value.trim() : "";
|
||||
if (text) return text;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const statePath = async () => await readLocalConfigField("local.json", "cloudStatePath") ?? pathResolve(resolveDshHomeSafe(), "worktable-state.json");
|
||||
register({
|
||||
kind: "exact",
|
||||
path: "/api/worktable/state",
|
||||
handler: async (req, res) => {
|
||||
const file = statePath();
|
||||
const file = await statePath();
|
||||
if (req.method === "GET" || req.method === "HEAD") {
|
||||
try {
|
||||
const raw = await readFile(file, "utf8");
|
||||
|
||||
Reference in New Issue
Block a user