@michengai/dsh-archive-manager 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/CHANGELOG.zh-CN.md +8 -0
- package/README.de.md +4 -10
- package/README.en.md +3 -9
- package/README.es.md +4 -10
- package/README.fr.md +4 -10
- package/README.ja.md +3 -9
- package/README.md +3 -9
- package/README.pt.md +4 -10
- package/README.ru.md +3 -9
- package/README.zh-CN.md +3 -9
- package/lib/client.js +1 -1
- package/lib/index.js +65 -63
- package/lib/plugin-settings.js +2 -22
- package/package.json +27 -26
- package/lib/plugin-updater.js +0 -446
- package/lib/release-age.js +0 -164
package/lib/index.js
CHANGED
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
import { getEntryLocation,
|
|
2
|
-
import {
|
|
1
|
+
import { getEntryLocation, getSidebarFavoriteStarMode, setEntryLocation, setSidebarFavoriteStarMode } from "./plugin-settings.js";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
3
|
import { apply as installHost, inject as hostInject } from "./host-install.js";
|
|
4
4
|
import { authorizeExplorerPath } from "./explorer-path-policy.js";
|
|
5
5
|
import { revealPathInSystem } from "./native-explorer.js";
|
|
6
6
|
const inject = ["webServer", ...hostInject];
|
|
7
7
|
const SIDEBAR_ENTRY_ENDPOINT = "/api/michengai/dsh-archive-manager/sidebar-entry";
|
|
8
|
-
const ONLINE_UPDATE_ENDPOINT = "/api/michengai/dsh-archive-manager/online-update";
|
|
9
8
|
const SIDEBAR_FAVORITE_STAR_ENDPOINT = "/api/michengai/dsh-archive-manager/sidebar-favorite-star";
|
|
10
9
|
const OPEN_IN_EXPLORER_ENDPOINT = "/api/michengai/dsh-archive-manager/open-in-explorer";
|
|
10
|
+
const TRUSTED_MUTATION_HEADER = "x-michengai-archive-settings";
|
|
11
|
+
function header(request, name) {
|
|
12
|
+
const value = request.headers?.[name];
|
|
13
|
+
return Array.isArray(value) ? value[0] : value;
|
|
14
|
+
}
|
|
15
|
+
function isLoopbackAddress(value) {
|
|
16
|
+
const address = value?.toLowerCase().replace(/^\[|\]$/g, "");
|
|
17
|
+
return address === "localhost" || address === "localhost." || address === "::1" || address?.startsWith("127.") === true || address?.startsWith("::ffff:127.") === true;
|
|
18
|
+
}
|
|
19
|
+
function isTrustedLocalRequest(request) {
|
|
20
|
+
if (header(request, TRUSTED_MUTATION_HEADER) !== "1") return false;
|
|
21
|
+
if (!isLoopbackAddress(request.socket?.remoteAddress)) return false;
|
|
22
|
+
const site = header(request, "sec-fetch-site");
|
|
23
|
+
if (site !== void 0 && site !== "same-origin") return false;
|
|
24
|
+
const host = header(request, "host");
|
|
25
|
+
if (host === void 0 || host === "") return false;
|
|
26
|
+
const origin = header(request, "origin");
|
|
27
|
+
if (origin === void 0 || origin === "") {
|
|
28
|
+
try {
|
|
29
|
+
return isLoopbackAddress(new URL(`http://${host}`).hostname);
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(origin);
|
|
36
|
+
return (url.protocol === "http:" || url.protocol === "https:") && isLoopbackAddress(url.hostname) && url.host === host;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const managedRoutes = Symbol.for("dsh-archive-manager.managed-routes");
|
|
42
|
+
function managedRouteBag(server) {
|
|
43
|
+
const owner = server;
|
|
44
|
+
return owner[managedRoutes] ?? (owner[managedRoutes] = /* @__PURE__ */ new Map());
|
|
45
|
+
}
|
|
46
|
+
function rawService(service) {
|
|
47
|
+
const original = Reflect.get(service, symbols.original);
|
|
48
|
+
return original !== null && typeof original === "object" ? original : service;
|
|
49
|
+
}
|
|
50
|
+
function releaseManagedRoute(server, path) {
|
|
51
|
+
const raw = rawService(server);
|
|
52
|
+
const bag = managedRouteBag(raw);
|
|
53
|
+
const owned = bag.get(path);
|
|
54
|
+
if (owned !== void 0) {
|
|
55
|
+
bag.delete(path);
|
|
56
|
+
owned();
|
|
57
|
+
}
|
|
58
|
+
for (const key of ["exact", "prefixes"]) {
|
|
59
|
+
const table = Reflect.get(raw, key);
|
|
60
|
+
if (table instanceof Map && table.has(path)) table.delete(path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
11
63
|
function sendJson(response, statusCode, value) {
|
|
12
64
|
response.writeHead(statusCode, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
13
65
|
response.end(JSON.stringify(value));
|
|
@@ -34,12 +86,11 @@ function readJsonBody(request) {
|
|
|
34
86
|
request.on("error", () => resolve(null));
|
|
35
87
|
});
|
|
36
88
|
}
|
|
37
|
-
function registerSettingsRoutes(ctx
|
|
89
|
+
function registerSettingsRoutes(ctx) {
|
|
38
90
|
const server = rawService(ctx.webServer);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
releaseUpdateRoute(server, OPEN_IN_EXPLORER_ENDPOINT);
|
|
91
|
+
releaseManagedRoute(server, SIDEBAR_ENTRY_ENDPOINT);
|
|
92
|
+
releaseManagedRoute(server, SIDEBAR_FAVORITE_STAR_ENDPOINT);
|
|
93
|
+
releaseManagedRoute(server, OPEN_IN_EXPLORER_ENDPOINT);
|
|
43
94
|
const disposeSidebar = ctx.webServer.register({
|
|
44
95
|
kind: "exact",
|
|
45
96
|
path: SIDEBAR_ENTRY_ENDPOINT,
|
|
@@ -50,7 +101,7 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
50
101
|
return;
|
|
51
102
|
}
|
|
52
103
|
if (request.method === "POST") {
|
|
53
|
-
if (!
|
|
104
|
+
if (!isTrustedLocalRequest(request)) {
|
|
54
105
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
55
106
|
return;
|
|
56
107
|
}
|
|
@@ -90,7 +141,7 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
90
141
|
return;
|
|
91
142
|
}
|
|
92
143
|
if (request.method === "POST") {
|
|
93
|
-
if (!
|
|
144
|
+
if (!isTrustedLocalRequest(request)) {
|
|
94
145
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
95
146
|
return;
|
|
96
147
|
}
|
|
@@ -120,37 +171,6 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
120
171
|
response.end();
|
|
121
172
|
}
|
|
122
173
|
});
|
|
123
|
-
const disposeUpdate = ctx.webServer.register({
|
|
124
|
-
kind: "exact",
|
|
125
|
-
path: ONLINE_UPDATE_ENDPOINT,
|
|
126
|
-
handler: async (request, response) => {
|
|
127
|
-
if (request.method === "GET" || request.method === "HEAD") {
|
|
128
|
-
const enabled = !hostUpdateDisabled && await getOnlineUpdate();
|
|
129
|
-
sendJson(response, 200, { ok: true, enabled, locked: hostUpdateDisabled });
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (request.method === "POST") {
|
|
133
|
-
if (!isTrustedUpdateRequest(request)) {
|
|
134
|
-
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (hostUpdateDisabled) {
|
|
138
|
-
sendJson(response, 403, { ok: false, error: "\u5728\u7EBF\u66F4\u65B0\u5DF2\u88AB\u5BBF\u4E3B\u914D\u7F6E\u9501\u5B9A\u7981\u7528" });
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const body = await readJsonBody(request);
|
|
142
|
-
if (!body || typeof body.enabled !== "boolean") {
|
|
143
|
-
sendJson(response, 400, { ok: false, error: "enabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C" });
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const enabled = await setOnlineUpdate(body.enabled);
|
|
147
|
-
sendJson(response, 200, { ok: true, enabled });
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
response.writeHead(405, { allow: "GET, HEAD, POST" });
|
|
151
|
-
response.end();
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
174
|
const disposeOpenExplorer = ctx.webServer.register({
|
|
155
175
|
kind: "exact",
|
|
156
176
|
path: OPEN_IN_EXPLORER_ENDPOINT,
|
|
@@ -160,7 +180,7 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
160
180
|
response.end();
|
|
161
181
|
return;
|
|
162
182
|
}
|
|
163
|
-
if (!
|
|
183
|
+
if (!isTrustedLocalRequest(request)) {
|
|
164
184
|
sendJson(response, 403, { ok: false, error: "\u5DF2\u62D2\u7EDD\u975E\u672C\u673A\u540C\u6E90\u8BF7\u6C42\u3002" });
|
|
165
185
|
return;
|
|
166
186
|
}
|
|
@@ -191,48 +211,29 @@ function registerSettingsRoutes(ctx, hostUpdateDisabled) {
|
|
|
191
211
|
disposeFavoriteStar();
|
|
192
212
|
} catch {
|
|
193
213
|
}
|
|
194
|
-
try {
|
|
195
|
-
disposeUpdate();
|
|
196
|
-
} catch {
|
|
197
|
-
}
|
|
198
214
|
try {
|
|
199
215
|
disposeOpenExplorer();
|
|
200
216
|
} catch {
|
|
201
217
|
}
|
|
202
218
|
};
|
|
203
219
|
}
|
|
204
|
-
async function apply(ctx,
|
|
205
|
-
const hostUpdateDisabled = config?.updater === false || config?.onlineUpdate === false;
|
|
206
|
-
let disposeUpdater = () => {
|
|
207
|
-
};
|
|
220
|
+
async function apply(ctx, _config) {
|
|
208
221
|
let disposeSettingsRoutes = () => {
|
|
209
222
|
};
|
|
210
223
|
try {
|
|
211
|
-
disposeSettingsRoutes = registerSettingsRoutes(ctx
|
|
224
|
+
disposeSettingsRoutes = registerSettingsRoutes(ctx);
|
|
212
225
|
} catch (error) {
|
|
213
226
|
ctx.logger?.warn?.(`archive-manager: settings routes skipped: ${String(error)}`);
|
|
214
227
|
}
|
|
215
|
-
try {
|
|
216
|
-
disposeUpdater = registerPluginUpdater(ctx, {
|
|
217
|
-
endpoint: "/api/michengai/dsh-archive-manager/update",
|
|
218
|
-
packageName: "@michengai/dsh-archive-manager",
|
|
219
|
-
manifestUrl: new URL("../package.json", import.meta.url),
|
|
220
|
-
isEnabled: async () => !hostUpdateDisabled && await getOnlineUpdate()
|
|
221
|
-
});
|
|
222
|
-
} catch (error) {
|
|
223
|
-
ctx.logger?.warn?.(`archive-manager: update route skipped: ${String(error)}`);
|
|
224
|
-
}
|
|
225
228
|
let disposeHost;
|
|
226
229
|
try {
|
|
227
230
|
disposeHost = await installHost(ctx);
|
|
228
231
|
} catch (error) {
|
|
229
|
-
disposeUpdater();
|
|
230
232
|
disposeSettingsRoutes();
|
|
231
233
|
throw error;
|
|
232
234
|
}
|
|
233
235
|
return async () => {
|
|
234
236
|
try {
|
|
235
|
-
disposeUpdater();
|
|
236
237
|
disposeSettingsRoutes();
|
|
237
238
|
} finally {
|
|
238
239
|
await disposeHost();
|
|
@@ -244,5 +245,6 @@ export {
|
|
|
244
245
|
SIDEBAR_FAVORITE_STAR_ENDPOINT,
|
|
245
246
|
apply,
|
|
246
247
|
inject,
|
|
248
|
+
isTrustedLocalRequest,
|
|
247
249
|
registerSettingsRoutes
|
|
248
250
|
};
|
package/lib/plugin-settings.js
CHANGED
|
@@ -66,7 +66,6 @@ async function readSettings() {
|
|
|
66
66
|
const defaultSettings = {
|
|
67
67
|
entryLocation: "settings",
|
|
68
68
|
sidebarEntry: false,
|
|
69
|
-
onlineUpdate: true,
|
|
70
69
|
sidebarFavoriteStar: "all"
|
|
71
70
|
};
|
|
72
71
|
if (!existsSync(path)) {
|
|
@@ -90,7 +89,6 @@ async function readSettings() {
|
|
|
90
89
|
return {
|
|
91
90
|
entryLocation,
|
|
92
91
|
sidebarEntry: entryLocation !== "settings",
|
|
93
|
-
onlineUpdate: typeof item.onlineUpdate === "boolean" ? item.onlineUpdate : true,
|
|
94
92
|
sidebarFavoriteStar: normalizeFavoriteStarMode(item.sidebarFavoriteStar)
|
|
95
93
|
};
|
|
96
94
|
} catch {
|
|
@@ -103,7 +101,6 @@ async function writeSettings(next) {
|
|
|
103
101
|
const normalized = {
|
|
104
102
|
entryLocation: location,
|
|
105
103
|
sidebarEntry: location !== "settings",
|
|
106
|
-
onlineUpdate: next.onlineUpdate !== false,
|
|
107
104
|
sidebarFavoriteStar: normalizeFavoriteStarMode(next.sidebarFavoriteStar)
|
|
108
105
|
};
|
|
109
106
|
const serialized = `${JSON.stringify(normalized, null, 2)}
|
|
@@ -128,36 +125,21 @@ async function setEntryLocation(location) {
|
|
|
128
125
|
}
|
|
129
126
|
async function getSidebarEntry() {
|
|
130
127
|
const current = await readSettings();
|
|
131
|
-
return current.entryLocation !== "settings";
|
|
128
|
+
return current.sidebarEntry ?? current.entryLocation !== "settings";
|
|
132
129
|
}
|
|
133
130
|
async function setSidebarEntry(enabled) {
|
|
134
131
|
if (typeof enabled !== "boolean") {
|
|
135
132
|
throw new TypeError("sidebarEntry must be a boolean");
|
|
136
133
|
}
|
|
137
134
|
return enqueueWrite(async () => {
|
|
138
|
-
const location = enabled ? "both" : "settings";
|
|
139
135
|
const current = await readSettings();
|
|
136
|
+
const location = enabled ? current.entryLocation === "settings" ? "both" : current.entryLocation ?? "both" : "settings";
|
|
140
137
|
current.entryLocation = location;
|
|
141
138
|
current.sidebarEntry = enabled;
|
|
142
139
|
await writeSettings(current);
|
|
143
140
|
return enabled;
|
|
144
141
|
});
|
|
145
142
|
}
|
|
146
|
-
async function getOnlineUpdate() {
|
|
147
|
-
const current = await readSettings();
|
|
148
|
-
return current.onlineUpdate !== false;
|
|
149
|
-
}
|
|
150
|
-
async function setOnlineUpdate(enabled) {
|
|
151
|
-
if (typeof enabled !== "boolean") {
|
|
152
|
-
throw new TypeError("onlineUpdate must be a boolean");
|
|
153
|
-
}
|
|
154
|
-
return enqueueWrite(async () => {
|
|
155
|
-
const current = await readSettings();
|
|
156
|
-
current.onlineUpdate = enabled;
|
|
157
|
-
await writeSettings(current);
|
|
158
|
-
return enabled;
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
143
|
async function getSidebarFavoriteStarMode() {
|
|
162
144
|
const current = await readSettings();
|
|
163
145
|
return normalizeFavoriteStarMode(current.sidebarFavoriteStar);
|
|
@@ -190,7 +172,6 @@ async function setSidebarFavoriteStar(value) {
|
|
|
190
172
|
}
|
|
191
173
|
export {
|
|
192
174
|
getEntryLocation,
|
|
193
|
-
getOnlineUpdate,
|
|
194
175
|
getSidebarEntry,
|
|
195
176
|
getSidebarFavoriteStar,
|
|
196
177
|
getSidebarFavoriteStarMode,
|
|
@@ -198,7 +179,6 @@ export {
|
|
|
198
179
|
normalizeFavoriteStarMode,
|
|
199
180
|
readSettings,
|
|
200
181
|
setEntryLocation,
|
|
201
|
-
setOnlineUpdate,
|
|
202
182
|
setSidebarEntry,
|
|
203
183
|
setSidebarFavoriteStar,
|
|
204
184
|
setSidebarFavoriteStarMode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-archive-manager",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "归档、恢复、收藏和永久删除会话,并诊断损坏的会话日志。 · Archive, restore, favorite, and permanently delete sessions, and diagnose damaged session logs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.22.0",
|
|
@@ -74,31 +74,32 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@deepseek-ai/cordis": "4.0
|
|
78
|
-
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.
|
|
79
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.
|
|
80
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.
|
|
81
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-rc.
|
|
82
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.
|
|
83
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.
|
|
85
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.
|
|
86
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.
|
|
87
|
-
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.
|
|
88
|
-
"@deepseek-ai/dsh-
|
|
89
|
-
"@deepseek-ai/dsh-
|
|
90
|
-
"@deepseek-ai/dsh-
|
|
91
|
-
"@deepseek-ai/dsh-session
|
|
92
|
-
"@deepseek-ai/dsh-session-
|
|
93
|
-
"@deepseek-ai/dsh-session-
|
|
94
|
-
"@deepseek-ai/dsh-session-projection
|
|
95
|
-
"@deepseek-ai/dsh-
|
|
96
|
-
"@deepseek-ai/dsh-spill
|
|
97
|
-
"@deepseek-ai/dsh-
|
|
98
|
-
"@deepseek-ai/dsh-storage
|
|
99
|
-
"@deepseek-ai/dsh-
|
|
100
|
-
"@deepseek-ai/dsh-typert-
|
|
101
|
-
"@deepseek-ai/dsh-
|
|
77
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
78
|
+
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.2",
|
|
80
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.2",
|
|
81
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.2",
|
|
82
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.2",
|
|
83
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.2",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.2",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.2",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.2",
|
|
87
|
+
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.2",
|
|
88
|
+
"@deepseek-ai/dsh-error": "0.2.2-rc.2",
|
|
89
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.2",
|
|
90
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.2",
|
|
91
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
92
|
+
"@deepseek-ai/dsh-session-format-catalog": "0.2.2-rc.2",
|
|
93
|
+
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.2",
|
|
94
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
|
|
95
|
+
"@deepseek-ai/dsh-session-projection-cache": "0.2.2-rc.2",
|
|
96
|
+
"@deepseek-ai/dsh-spill": "0.2.2-rc.2",
|
|
97
|
+
"@deepseek-ai/dsh-spill-local": "0.2.2-rc.2",
|
|
98
|
+
"@deepseek-ai/dsh-storage": "0.2.2-rc.2",
|
|
99
|
+
"@deepseek-ai/dsh-storage-domain": "0.2.2-rc.2",
|
|
100
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.2",
|
|
101
|
+
"@deepseek-ai/dsh-typert-registry": "0.2.2-rc.2",
|
|
102
|
+
"@deepseek-ai/dsh-workspace": "0.2.2-rc.2",
|
|
102
103
|
"@types/node": "^22.20.4",
|
|
103
104
|
"@types/react": "^18.3.31",
|
|
104
105
|
"@types/react-dom": "^18.0.0",
|