dsh-plugin 1.6.5 → 1.6.6
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/README.en.md +11 -11
- package/README.md +11 -11
- package/client/client.js +420 -389
- package/client/client.js.map +1 -1
- package/lib/http/catalog.js +132 -0
- package/lib/http/diagnostics.js +201 -0
- package/lib/http/install.js +399 -0
- package/lib/http/logs.js +164 -0
- package/lib/http/routes.js +19 -1263
- package/lib/http/settings.js +77 -0
- package/lib/http/shared.js +169 -0
- package/lib/http/task.js +208 -0
- package/lib/services/install/install.js +1 -1
- package/lib/services/install/task-queue.js +45 -16
- package/lib/services/probe.js +1 -1
- package/lib/types/http/catalog.d.ts +10 -0
- package/lib/types/http/diagnostics.d.ts +4 -0
- package/lib/types/http/install.d.ts +11 -0
- package/lib/types/http/logs.d.ts +2 -0
- package/lib/types/http/routes.d.ts +15 -20
- package/lib/types/http/settings.d.ts +2 -0
- package/lib/types/http/shared.d.ts +44 -0
- package/lib/types/http/task.d.ts +3 -0
- package/lib/types/services/install/install.d.ts +1 -1
- package/package.json +1 -1
- package/src/client/components/PluginHubSection.tsx +3 -0
- package/src/client/components/modals/NotificationsModal.tsx +34 -18
- package/src/client/components/modals/modals.tsx +38 -28
- package/src/client/components/views/InstalledView.tsx +23 -11
- package/src/client/hooks/useCatalog.ts +1 -1
- package/src/client/locales.ts +24 -8
- package/src/client/logic/failures.ts +36 -157
- package/src/client/logic/urls.ts +72 -1
- package/src/client/types.ts +1 -1
- package/src/server/http/catalog.ts +143 -0
- package/src/server/http/diagnostics.ts +193 -0
- package/src/server/http/install.ts +391 -0
- package/src/server/http/logs.ts +149 -0
- package/src/server/http/routes.ts +22 -1222
- package/src/server/http/settings.ts +73 -0
- package/src/server/http/shared.ts +191 -0
- package/src/server/http/task.ts +194 -0
- package/src/server/services/install/install-types.ts +9 -1
- package/src/server/services/install/install.ts +11 -1
- package/src/server/services/install/task-queue.ts +45 -16
- package/src/server/services/probe.ts +1 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH Plugin Hub — the community plugin marketplace for DeepSeek Harness.
|
|
3
|
+
* Website: https://dsh-plugin.org
|
|
4
|
+
* GitHub: https://github.com/dshplugin/dsh-plugin-hub
|
|
5
|
+
*
|
|
6
|
+
* Diagnostics routes: streaming connectivity self-check, proxy verification,
|
|
7
|
+
* and the host environment snapshot shared with the task module's /env route.
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from 'node:fs'
|
|
10
|
+
import { homedir, release } from 'node:os'
|
|
11
|
+
import { dirname, join, resolve } from 'node:path'
|
|
12
|
+
import { spawnSync } from 'node:child_process'
|
|
13
|
+
import { loadSettings } from '../services/settings.ts'
|
|
14
|
+
import { gitLsRemote, probeUrl, systemProxy } from '../services/probe.ts'
|
|
15
|
+
import { appendLog } from '../services/log.ts'
|
|
16
|
+
import { readJsonBody, requireTrustedPost, sendJson, type WebRoute, type WebServerService } from './shared.ts'
|
|
17
|
+
|
|
18
|
+
/** 宿主 dsh CLI 版本:优先直接跑 `dsh --version`(与 pnpm/npm/git 同款同步探测,1500ms 超时兜底,
|
|
19
|
+
* 绝不挂起);拿不到再退回从入口 `process.argv[1]` 向上找 package.json(dsh 不在 PATH 时兜底)。 */
|
|
20
|
+
function hostDshVersion(): string | null {
|
|
21
|
+
const viaCli = toolVersion('dsh', ['--version'])
|
|
22
|
+
if (viaCli) return viaCli
|
|
23
|
+
const entry = process.argv[1]
|
|
24
|
+
if (entry === undefined) return null
|
|
25
|
+
let dir = dirname(resolve(entry))
|
|
26
|
+
for (let depth = 0; depth < 4; depth++) {
|
|
27
|
+
try {
|
|
28
|
+
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { name?: string; version?: string }
|
|
29
|
+
const name = manifest.name ?? ''
|
|
30
|
+
if (typeof manifest.version === 'string' && (name === 'dsh' || name.includes('dsh') || name.includes('harness'))) {
|
|
31
|
+
return manifest.version
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
/* not a package root — keep walking up */
|
|
35
|
+
}
|
|
36
|
+
const parent = dirname(dir)
|
|
37
|
+
if (parent === dir) break
|
|
38
|
+
dir = parent
|
|
39
|
+
}
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 探测命令行工具的版本号(pnpm --version / npm --version / git --version):
|
|
44
|
+
* 未安装 / 不在 PATH / 超时一律返回 null —— issue 环境快照如实写 unknown,绝不挂起。
|
|
45
|
+
* (同步探测仅用于启动期/请求期的低频率 /env 快照,安装通道不经过这里。) */
|
|
46
|
+
function toolVersion(cmd: string, args: string[]): string | null {
|
|
47
|
+
try {
|
|
48
|
+
const r = spawnSync(cmd, args, { timeout: 1500, encoding: 'utf8' })
|
|
49
|
+
if (r.error || r.status !== 0) return null
|
|
50
|
+
const v = (r.stdout ?? '').trim().split(/\r?\n/)[0]
|
|
51
|
+
return v || null
|
|
52
|
+
} catch {
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 宿主环境快照:提交 bug 时随 issue 附上,便于作者复现(前端 /env 端点返回)。 */
|
|
58
|
+
export function hostEnv(profile: string): Record<string, string | null> {
|
|
59
|
+
return {
|
|
60
|
+
dshVersion: hostDshVersion(),
|
|
61
|
+
nodeVersion: process.version,
|
|
62
|
+
pnpmVersion: toolVersion('pnpm', ['--version']),
|
|
63
|
+
npmVersion: toolVersion('npm', ['--version']),
|
|
64
|
+
gitVersion: toolVersion('git', ['--version']),
|
|
65
|
+
platform: process.platform,
|
|
66
|
+
arch: process.arch,
|
|
67
|
+
release: release(),
|
|
68
|
+
profile,
|
|
69
|
+
dshHome: process.env.DSH_HOME ?? join(homedir(), '.dsh'),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function registerDiagnosticsRoutes(webServer: WebServerService, profile: string): WebRoute[] {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
kind: 'exact',
|
|
77
|
+
path: '/dsh-plugin-hub/diagnostics',
|
|
78
|
+
handler: async (request, response) => {
|
|
79
|
+
if (!requireTrustedPost(request, response)) return
|
|
80
|
+
// 连通性自检:npm registry(镜像/官方)/ GitHub API / 目录站点,逐路探测并测速。
|
|
81
|
+
// 与安装通道一一对应 —— npm 反查与 npm 安装走 registry、git 源走 github、目录数据走 dsh-plugin.org。
|
|
82
|
+
// 流式(NDJSON)逐条上报:每个探测先发命令行,完成后发结果行,客户端以黑窗口终端实时展示。
|
|
83
|
+
// 可选 body { key }:只重测指定通道(页面列表「重测」单项时用),缺省全量串行探测。
|
|
84
|
+
let onlyKey = ''
|
|
85
|
+
try {
|
|
86
|
+
const body = await readJsonBody(request)
|
|
87
|
+
if (body !== null && typeof body === 'object' && typeof (body as { key?: unknown }).key === 'string') {
|
|
88
|
+
onlyKey = (body as { key: string }).key
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
// 空 body / 非 JSON:视为全量探测
|
|
92
|
+
}
|
|
93
|
+
const settings = loadSettings(profile)
|
|
94
|
+
// npm 通道:设置里配置了镜像源就探测该镜像(安装通道吃同一个 registry);
|
|
95
|
+
// 未配置(空串)时探测官方源作为「跟随本机 npm 配置」的基础连通性参考。
|
|
96
|
+
const registry = settings.npmRegistry.replace(/\/+$/, '') || 'https://registry.npmjs.org'
|
|
97
|
+
// 连通性自检直接打安装通道真实访问的轻量资源:npm 源拉包元数据、git 通道探
|
|
98
|
+
// 仓库主页、目录站探 badge 小文件,避免拉取目录全量 JSON。
|
|
99
|
+
// npm 行 display:配置了镜像就显示镜像地址;未配置置空 —— 客户端显示「未配置(跟随本机 npm 配置)」。
|
|
100
|
+
const allChecks: Array<{ key: string; url: string; display: string; cmd: string; proxy?: string; git?: boolean }> = [
|
|
101
|
+
{ key: 'npm', url: `${registry}/dsh-plugin`, display: settings.npmRegistry !== '' ? registry : '', cmd: `npm view dsh-plugin version --registry ${registry}` },
|
|
102
|
+
// GitHub 行用真实 git 克隆握手(git ls-remote)打 dshplugin/hello-dsh 小仓库:
|
|
103
|
+
// 「网页能打开」和「git 能克隆」是两码事,握手成功才算通道通;小仓库秒级完成,不打 17MB 的 dsh-plugin-hub。
|
|
104
|
+
{ key: 'github', url: 'https://github.com/dshplugin/hello-dsh', display: 'github.com', cmd: 'git ls-remote https://github.com/dshplugin/hello-dsh', git: true },
|
|
105
|
+
{ key: 'catalog', url: 'https://api.dsh-plugin.org/stats.json', display: '', cmd: 'curl -s https://api.dsh-plugin.org/stats.json' },
|
|
106
|
+
]
|
|
107
|
+
// 配置了 HTTP 代理:追加一行代理诊断 —— 用该代理打 github.com(安装通道真实访问的地址),
|
|
108
|
+
// 验证「代理能不能把请求带出去」。与安装同口径:curl 子进程注入该代理 env。
|
|
109
|
+
// 设置里未配置代理时不显示该行(跟随系统代理/直连,无「代理本身」可验证)。
|
|
110
|
+
if (settings.proxy !== '') {
|
|
111
|
+
allChecks.push({ key: 'proxy', url: 'https://github.com', display: settings.proxy, cmd: `curl -s -o /dev/null -x ${settings.proxy} https://github.com`, proxy: settings.proxy })
|
|
112
|
+
}
|
|
113
|
+
const checks = onlyKey !== '' ? allChecks.filter((c) => c.key === onlyKey) : allChecks
|
|
114
|
+
response.writeHead(200, {
|
|
115
|
+
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
116
|
+
'cache-control': 'no-store',
|
|
117
|
+
})
|
|
118
|
+
const send = (line: unknown) => { response.write(`${JSON.stringify(line)}\n`) }
|
|
119
|
+
// 探测走代理的优先级:设置里的代理 → 系统代理(macOS scutil / Windows 注册表)→ 环境变量 HTTPS_PROXY → 直连。
|
|
120
|
+
// 与安装通道一致(npm/git 靠 HTTP_PROXY 环境变量走代理),且自动跟随系统代理 ——
|
|
121
|
+
// 浏览器挂着代理能开、诊断就能测通,不用用户手动把代理填进设置。
|
|
122
|
+
// proxy 行例外:它验证的正是「设置里配的那个代理」,必须显式用它(而非 effectiveProxy)去探测。
|
|
123
|
+
const effectiveProxy = settings.proxy !== ''
|
|
124
|
+
? settings.proxy
|
|
125
|
+
: (systemProxy() ?? process.env.HTTPS_PROXY ?? process.env.https_proxy ?? '')
|
|
126
|
+
const probe = (url: string, proxy?: string) => probeUrl(url, proxy ?? effectiveProxy, 6000)
|
|
127
|
+
// 逐路串行:一条命令一条结果地推送给终端,保持「程序在跑」的真实感
|
|
128
|
+
const results: Array<{ key: string; ok: boolean }> = []
|
|
129
|
+
for (const c of checks) {
|
|
130
|
+
send({ type: 'probe', key: c.key, cmd: c.cmd, display: c.display })
|
|
131
|
+
// git 行走真实克隆握手(gitLsRemote),其余走 curl 探测,两路都带超时兜底
|
|
132
|
+
const r = c.git
|
|
133
|
+
? await gitLsRemote(c.url, c.proxy ?? effectiveProxy, 6000)
|
|
134
|
+
: await probe(c.url, c.proxy)
|
|
135
|
+
results.push({ key: c.key, ok: r.ok })
|
|
136
|
+
// git 行的 status 是退出码,客户端 git 行只显示 OK / 不可达,不显示成 HTTP 码。
|
|
137
|
+
// reason 透出失败细分原因(如 Windows 证书吊销受阻),客户端据此给对症提示而非笼统「不可达」。
|
|
138
|
+
send({
|
|
139
|
+
type: r.ok ? 'ok' : 'fail',
|
|
140
|
+
key: c.key,
|
|
141
|
+
display: c.display,
|
|
142
|
+
ms: r.ms,
|
|
143
|
+
status: c.git ? null : r.status,
|
|
144
|
+
reason: r.ok ? null : (r.reason ?? null),
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
send({ type: 'end', at: Date.now() })
|
|
148
|
+
response.end()
|
|
149
|
+
// 系统日志:诊断汇总(全部通过 / 存在不可达)
|
|
150
|
+
const failed = results.filter((r) => !r.ok)
|
|
151
|
+
appendLog(profile, {
|
|
152
|
+
at: Date.now(),
|
|
153
|
+
level: failed.length === 0 ? 'success' : 'error',
|
|
154
|
+
category: 'diagnostics',
|
|
155
|
+
event: 'diagnostics.done',
|
|
156
|
+
message: failed.length === 0
|
|
157
|
+
? `连通性检测通过(${results.length} 个通道)`
|
|
158
|
+
: `连通性检测:${failed.length}/${results.length} 个通道不可达`,
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
kind: 'exact',
|
|
164
|
+
path: '/dsh-plugin-hub/proxy-check',
|
|
165
|
+
handler: async (request, response) => {
|
|
166
|
+
if (!requireTrustedPost(request, response)) return
|
|
167
|
+
// 代理连通性校验:用待测代理打 dshplugin/hello-dsh 真实仓库页(权威可达目标),
|
|
168
|
+
// 供设置页输入代理时实时反馈「这个地址通不通」。不通过也允许保存 ——
|
|
169
|
+
// 用户可能是先填地址后开代理,因此这里只报告探测结果、不拦截保存。
|
|
170
|
+
let proxy = ''
|
|
171
|
+
let target = 'https://github.com/dshplugin/hello-dsh'
|
|
172
|
+
try {
|
|
173
|
+
const body = await readJsonBody(request)
|
|
174
|
+
if (body !== null && typeof body === 'object') {
|
|
175
|
+
const b = body as { proxy?: unknown; target?: unknown }
|
|
176
|
+
if (typeof b.proxy === 'string') proxy = b.proxy.trim()
|
|
177
|
+
if (typeof b.target === 'string' && b.target.trim() !== '') target = b.target.trim()
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
// 空 body / 非 JSON:按默认目标探测
|
|
181
|
+
}
|
|
182
|
+
if (proxy === '') {
|
|
183
|
+
sendJson(response, 200, { ok: false, ms: null, status: null, target, reason: 'empty' })
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
// 探测走该代理本身(不是 effectiveProxy):验证的就是用户填的这个地址。
|
|
187
|
+
// reason 带上失败细分原因(如证书吊销受阻),设置页才能提示「不是代理地址的问题」。
|
|
188
|
+
const r = await probeUrl(target, proxy, 6000)
|
|
189
|
+
sendJson(response, 200, { ok: r.ok, ms: r.ms, status: r.status, target, reason: r.reason ?? null })
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH Plugin Hub — the community plugin marketplace for DeepSeek Harness.
|
|
3
|
+
* Website: https://dsh-plugin.org
|
|
4
|
+
* GitHub: https://github.com/dshplugin/dsh-plugin-hub
|
|
5
|
+
*
|
|
6
|
+
* Install/uninstall routes: validate the target and spawn the official dsh CLI
|
|
7
|
+
* (see services/install/install.ts), reporting the captured result back.
|
|
8
|
+
*/
|
|
9
|
+
import { githubRefOf, githubRepoOf, githubTarget, globalNpmPackagesOf, hasQueuedTarget, installTargetOf, startPluginMutation, validPackageName, type LoaderHandle } from '../services/install/install.ts'
|
|
10
|
+
import { githubReleaseTarget } from '../services/install/release-target.ts'
|
|
11
|
+
import { recordResolvedNpmPackage } from '../services/profile/installed-versions.ts'
|
|
12
|
+
import { isDshNpmPackageForRepo, resolveNpmPackage } from '../services/install/npm-resolve.ts'
|
|
13
|
+
import { preflightTarget } from '../services/install/preflight.ts'
|
|
14
|
+
import { gitLsRemote, probeUrl, systemProxy } from '../services/probe.ts'
|
|
15
|
+
import { loadSettings, type HubSettings } from '../services/settings.ts'
|
|
16
|
+
import { installedRepoOf, readInstalled } from './catalog.ts'
|
|
17
|
+
import { COMMAND_TIMEOUT_MS, readJsonBody, requireTrustedPost, sendJson, type WebRoute, type WebServerService } from './shared.ts'
|
|
18
|
+
|
|
19
|
+
/** 安装/卸载 CLI 的子进程环境:透传宿主环境,并按设置注入 HTTP(S) 代理。
|
|
20
|
+
* 不注入 npm registry —— 安装完全沿用用户本机 npm 配置(~/.npmrc / 全局配置)。
|
|
21
|
+
* 代理优先级:设置里的代理 → 系统代理(macOS scutil / Windows 注册表)→ 宿主 env 原有值。
|
|
22
|
+
* 使安装通道与诊断使用相同的代理来源。 */
|
|
23
|
+
function mutationEnv(settings: HubSettings): NodeJS.ProcessEnv {
|
|
24
|
+
const env: NodeJS.ProcessEnv = { ...process.env, CI: 'true' }
|
|
25
|
+
const proxy = settings.proxy !== '' ? settings.proxy : (systemProxy() ?? '')
|
|
26
|
+
if (proxy !== '') {
|
|
27
|
+
env.HTTP_PROXY = proxy
|
|
28
|
+
env.HTTPS_PROXY = proxy
|
|
29
|
+
env.http_proxy = proxy
|
|
30
|
+
env.https_proxy = proxy
|
|
31
|
+
}
|
|
32
|
+
return env
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Match a GitHub install target against the installed table; returns the package name when already installed. */
|
|
36
|
+
function installedByRepo(installed: Record<string, string>, target: string): string | null {
|
|
37
|
+
const repo = githubRepoOf(target)
|
|
38
|
+
if (repo === null) return null
|
|
39
|
+
const needle = repo.toLowerCase()
|
|
40
|
+
for (const [name, spec] of Object.entries(installed)) {
|
|
41
|
+
if (githubRepoOf(spec)?.toLowerCase() === needle) return name
|
|
42
|
+
}
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function registerInstallRoutes(webServer: WebServerService, profile: string, loader: LoaderHandle | undefined): WebRoute[] {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
kind: 'exact',
|
|
50
|
+
path: '/dsh-plugin-hub/install',
|
|
51
|
+
handler: async (request, response) => {
|
|
52
|
+
if (!requireTrustedPost(request, response)) return
|
|
53
|
+
// 任务自动入队:即使已有插件操作在跑也接受请求(FIFO 串行执行),不做 409 拒绝
|
|
54
|
+
try {
|
|
55
|
+
const body = await readJsonBody(request)
|
|
56
|
+
// mode: 'update' = 已安装目标的覆盖更新(放行 add,pnpm 对已存在依赖原位覆盖重装)。
|
|
57
|
+
// 后续「同仓库残留」检测可能把 install 就地升级为 update(见包名冲突检测),故用 let。
|
|
58
|
+
let mode = body !== null && typeof body === 'object' && (body as { mode?: unknown }).mode === 'update'
|
|
59
|
+
? 'update'
|
|
60
|
+
: 'install'
|
|
61
|
+
// installTargetOf 先把完整 DSH 命令(`dsh plugin [--profile <p>] add <target>`)剥成裸目标,
|
|
62
|
+
// 兼容用户直接粘贴命令行(防输错),真正语法判定交给下面 githubRepoOf / validPackageName。
|
|
63
|
+
const rawRepo = typeof body === 'object' && body !== null && typeof (body as { repo?: unknown }).repo === 'string'
|
|
64
|
+
? installTargetOf((body as { repo: string }).repo)
|
|
65
|
+
: ''
|
|
66
|
+
// 前端决策的展示用仓库名(owner/repo):npm 安装时 body.repo 是包名,display 用于
|
|
67
|
+
// 待重启行 / 任务恢复时展示仓库名,保证用户无感知(安装通道变化不改变所见目标)
|
|
68
|
+
const displayRepo = typeof body === 'object' && body !== null && typeof (body as { display?: unknown }).display === 'string'
|
|
69
|
+
? (body as { display: string }).display.trim()
|
|
70
|
+
: rawRepo
|
|
71
|
+
// 请求来源:目录插件安装(catalog)走目录白名单;命令行安装(custom)按通道受安全开关控制
|
|
72
|
+
const source = typeof body === 'object' && body !== null && typeof (body as { source?: unknown }).source === 'string'
|
|
73
|
+
? (body as { source: string }).source
|
|
74
|
+
: ''
|
|
75
|
+
// 自定义安装入口渠道(客户端三张卡片:NPM 包 / GitHub 源码 / DSH 命令):
|
|
76
|
+
// 客户端显式上报,服务端日志/报错据此精准溯源「从哪个入口发起」;目录插件安装不传。
|
|
77
|
+
const installChannel = (() => {
|
|
78
|
+
const raw = body !== null && typeof body === 'object' ? (body as { installChannel?: unknown }).installChannel : undefined
|
|
79
|
+
return raw === 'git' || raw === 'dsh' || raw === 'npm' ? raw : undefined
|
|
80
|
+
})()
|
|
81
|
+
const settings = loadSettings(profile)
|
|
82
|
+
// 界面语言(客户端随请求携带):错误消息按用户当前语言提示(中文界面给中文,英文界面给英文)
|
|
83
|
+
const lang = typeof body === 'object' && body !== null && (body as { lang?: unknown }).lang === 'en'
|
|
84
|
+
? 'en'
|
|
85
|
+
: 'zh'
|
|
86
|
+
// 全局 npm 安装(官方 README 的 `npm install -g <pkgs>`,如 dsh-tui 的安装命令):
|
|
87
|
+
// 直接从命令框输入格式执行全局安装,不进任何 profile、无需宿主重启。
|
|
88
|
+
// 包列表优先取 body.globalNpm(客户端命令框解析后显式携带);兜底再从 rawRepo 解析,
|
|
89
|
+
// 保证直接调 API 传完整命令也能识别。
|
|
90
|
+
const bodyGlobalNpm = Array.isArray((body as { globalNpm?: unknown }).globalNpm)
|
|
91
|
+
? (body as { globalNpm: unknown[] }).globalNpm.filter((x): x is string => typeof x === 'string' && x !== '')
|
|
92
|
+
: []
|
|
93
|
+
let globalNpm: string[] = bodyGlobalNpm.length > 0 ? bodyGlobalNpm : (globalNpmPackagesOf(rawRepo) ?? [])
|
|
94
|
+
if (globalNpm.length > 0) {
|
|
95
|
+
// 包名逐个按 npm 包名语法校验 + 拒绝以 - 开头的 token(npm 会把 --xxx 当参数而非包名),数量封顶防滥用
|
|
96
|
+
if (globalNpm.length > 20 || globalNpm.some((p) => !validPackageName(p) || p.startsWith('-'))) {
|
|
97
|
+
sendJson(response, 400, { error: 'unsupported install target' })
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
// 通道门禁与安装通道同构:全局安装本质是 npm 操作,吃「启用 NPM 安装」开关
|
|
101
|
+
if (source !== 'catalog' && !settings.enableNpmInstall) {
|
|
102
|
+
sendJson(response, 403, { error: 'npm installs are disabled by the security settings' })
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
// 队列级去重:同一包列表已在排队/执行中时拒绝
|
|
106
|
+
const identity = globalNpm.join(' ')
|
|
107
|
+
if (hasQueuedTarget(identity)) {
|
|
108
|
+
sendJson(response, 409, { error: `already queued: ${identity}` })
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
const task = startPluginMutation({
|
|
112
|
+
action: 'add',
|
|
113
|
+
profile,
|
|
114
|
+
target: identity,
|
|
115
|
+
displayTarget: identity,
|
|
116
|
+
globalNpm,
|
|
117
|
+
timeoutMs: COMMAND_TIMEOUT_MS,
|
|
118
|
+
env: mutationEnv(settings),
|
|
119
|
+
// 全局 npm 安装由 NPM 包卡片/官方命令发起:日志体现入口渠道
|
|
120
|
+
installChannel: installChannel ?? 'npm',
|
|
121
|
+
})
|
|
122
|
+
sendJson(response, 200, { ok: true, task: task.id })
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
// 目标语法三态:固定 GitHub release .tgz(保留其包根目录,不转成仓库 HEAD);
|
|
126
|
+
// GitHub 地址(owner/repo、github:、https/ssh 链接等任意写法)→ 显式 HTTPS Git 源
|
|
127
|
+
// (走装前预检);npm 包名(@scope/name 或 name)→ 信任 registry 直接安装。
|
|
128
|
+
// githubRepoOf 先把各种 GitHub 地址归一成 owner/repo,让「输入地址即装」兼容粘贴完整链接。
|
|
129
|
+
const gitRepo = githubRepoOf(rawRepo)
|
|
130
|
+
const release = githubReleaseTarget(rawRepo)
|
|
131
|
+
// 显式 pin 的 Git ref(`#tag` / `#commit`)是用户意图:保留它,且不让 npm 反查
|
|
132
|
+
// 把这个精确修订换成 registry 上的默认版本。
|
|
133
|
+
const pinnedRef = githubRefOf(rawRepo)
|
|
134
|
+
const repoTarget = gitRepo !== null && release === null ? githubTarget(gitRepo, pinnedRef) : null
|
|
135
|
+
let target: string | null = release?.target ?? repoTarget ?? (validPackageName(rawRepo) ? rawRepo : null)
|
|
136
|
+
if (target === null) {
|
|
137
|
+
sendJson(response, 400, { error: 'unsupported install target' })
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
const attempts: string[] = []
|
|
141
|
+
// 代理口径与诊断/安装通道一致:设置里的代理 → 系统代理 → 环境变量 → 直连。
|
|
142
|
+
// 供 npm 反查时跟随 GitHub 改名跳转用(Node https 读不到系统代理,交给 curl)。
|
|
143
|
+
const effectiveProxy = settings.proxy !== ''
|
|
144
|
+
? settings.proxy
|
|
145
|
+
: (systemProxy() ?? process.env.HTTPS_PROXY ?? process.env.https_proxy ?? '')
|
|
146
|
+
// Catalog metadata may outlive a packaging split: one repository can publish both a
|
|
147
|
+
// CLI/helper package and a dedicated DSH plugin package. Keep the catalog target when
|
|
148
|
+
// registry metadata confirms it is a DSH package for this repo. Otherwise inspect the
|
|
149
|
+
// repository root package.json and use its package name only when that exact registry
|
|
150
|
+
// package also points back to the repo and identifies as a DSH plugin. This avoids
|
|
151
|
+
// relying on npm search ranking, which is not a repository index and can omit the
|
|
152
|
+
// correct package even with a large result window.
|
|
153
|
+
const catalogRepo = source === 'catalog' ? githubRepoOf(displayRepo) : null
|
|
154
|
+
if (catalogRepo !== null && release === null && repoTarget === null && validPackageName(rawRepo)) {
|
|
155
|
+
const catalogTargetIsDsh = await isDshNpmPackageForRepo(rawRepo, catalogRepo, settings.npmRegistry, effectiveProxy)
|
|
156
|
+
if (catalogTargetIsDsh) {
|
|
157
|
+
recordResolvedNpmPackage(profile, catalogRepo, rawRepo)
|
|
158
|
+
} else {
|
|
159
|
+
const catalogGitTarget = githubTarget(catalogRepo)
|
|
160
|
+
if (catalogGitTarget !== null) {
|
|
161
|
+
const root = await preflightTarget(catalogGitTarget)
|
|
162
|
+
const rootName = root.ok && root.name !== null && validPackageName(root.name) ? root.name : null
|
|
163
|
+
if (rootName !== null && rootName !== rawRepo
|
|
164
|
+
&& await isDshNpmPackageForRepo(rootName, catalogRepo, settings.npmRegistry, effectiveProxy)) {
|
|
165
|
+
attempts.push(`catalog npm target: \`${target}\` → repository root DSH package \`${rootName}\``)
|
|
166
|
+
target = rootName
|
|
167
|
+
recordResolvedNpmPackage(profile, catalogRepo, rootName)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// npm 优先:git 目标先反查该仓库的官方 npm 包,命中则改走 npm 通道。
|
|
173
|
+
// git 分发常缺构建产物/子模块,npm 包是作者发布的完整产物;未命中或
|
|
174
|
+
// 查询失败保留 github 直装(不阻塞安装,预检仍会拦截缺入口文件的情况)。
|
|
175
|
+
// 通用机制,不针对具体插件。
|
|
176
|
+
// 反查本身计入「已尝试的安装方式」:组织 scope 与 GitHub 用户名不一致时仅凭
|
|
177
|
+
// 仓库名猜不到包名,失败提 Issue 时作者看到我们查过的命令就能直接指认正确包名。
|
|
178
|
+
// 显式 pin 了 Git ref 时跳过 npm 反查:用户要的就是那个精确修订,
|
|
179
|
+
// 不能用 registry 上的默认版本覆盖它。
|
|
180
|
+
if (repoTarget !== null && pinnedRef === null) {
|
|
181
|
+
// 反查/记录统一用归一化后的 owner/repo(gitRepo),保证「输入完整链接」也走同一套 npm 反查
|
|
182
|
+
const repoIdentity = gitRepo ?? rawRepo
|
|
183
|
+
const npmName = await resolveNpmPackage(repoIdentity, settings.npmRegistry, effectiveProxy)
|
|
184
|
+
if (npmName !== null) {
|
|
185
|
+
target = npmName
|
|
186
|
+
attempts.push(`npm registry search: \`npm search repository:${repoIdentity}\` → found \`${npmName}\``)
|
|
187
|
+
// 持久化 repo → npm 包名映射:目录数据未下发 npmPackage(组织 scope 与 GitHub
|
|
188
|
+
// 用户名不一致)时,客户端仍能通过 /installed 的 versions 把依赖 key 匹配回仓库,
|
|
189
|
+
// 列表立即显示「已安装」,避免安装成功后仍显示可安装
|
|
190
|
+
recordResolvedNpmPackage(profile, repoIdentity, npmName)
|
|
191
|
+
} else {
|
|
192
|
+
attempts.push(`npm registry search: \`npm search repository:${repoIdentity}\` → no matching package found (falling back to git install)`)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// 命令行安装(目录外)按通道门禁:GitHub 源码通道受「启用 GitHub 源码安装」控制,
|
|
196
|
+
// npm 通道受「启用 NPM 安装」控制 —— 目录插件安装走目录白名单,不受开关影响。
|
|
197
|
+
// 通道判定看反查后的最终 target:release 包与 git 目标同属 GitHub 通道,否则走 npm。
|
|
198
|
+
if (source !== 'catalog') {
|
|
199
|
+
const isGitChannel = release !== null || (repoTarget !== null && target === repoTarget)
|
|
200
|
+
if (isGitChannel && !settings.enableGitInstall) {
|
|
201
|
+
sendJson(response, 403, { error: 'git installs are disabled by the security settings' })
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
if (!isGitChannel && !settings.enableNpmInstall) {
|
|
205
|
+
sendJson(response, 403, { error: 'npm installs are disabled by the security settings' })
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// 重复安装防护:非更新请求命中已安装目标时直接拒绝,不重复跑 CLI
|
|
210
|
+
// (否则 CLI 会因「已存在」失败,且用户看到的是莫名其妙的报错);
|
|
211
|
+
// 更新请求(mode: 'update')放行,CLI 的 add 对已存在依赖是 pnpm 原位覆盖重装。
|
|
212
|
+
// 命中判定双通道:npm 包名按 dependencies 键直接命中,GitHub 目标按仓库身份匹配。
|
|
213
|
+
const installed = readInstalled(profile)
|
|
214
|
+
const already = installedByRepo(installed, target) ?? (installed[target] !== undefined ? target : null)
|
|
215
|
+
if (already !== null && mode !== 'update') {
|
|
216
|
+
sendJson(response, 409, { error: `already installed: ${already}` })
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
// 队列级去重:同一目标已在排队/执行中时拒绝,避免客户端防重竞态导致重复入队
|
|
220
|
+
if (hasQueuedTarget(target)) {
|
|
221
|
+
sendJson(response, 409, { error: `already queued: ${target}` })
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
// 安装前网络连通性预检:npm 通道探 registry、git 通道探 github.com 连通性。
|
|
225
|
+
// 探测目标固定为通道的稳定入口(registry 根 / github.com 主页),不探具体包或仓库
|
|
226
|
+
// 页 —— 404 表示「目标不存在」而非网络不通,不该被当成网络故障拦截。
|
|
227
|
+
// 仅新安装预检(更新是已信任目标的覆盖重装,跳过);不通直接 400 拦下并打
|
|
228
|
+
// [network] 标记,客户端据此提示「你的网络不通」,而不是把网络失败当成
|
|
229
|
+
// 插件侧问题引导去作者仓库提 Issue。
|
|
230
|
+
// 代理口径与诊断一致:设置里的代理 → 系统代理 → 环境变量 → 直连。
|
|
231
|
+
if (already === null) {
|
|
232
|
+
const isGitChannel = release !== null || (repoTarget !== null && target === repoTarget)
|
|
233
|
+
// release 包是 https://github.com/ 直链下载(非 git 克隆),探针按 HTTP 打 github.com 主页;
|
|
234
|
+
// npm 通道探 registry 根。两者都是通道的稳定入口,不探具体包/仓库(404 会被误判成网络故障)。
|
|
235
|
+
const httpProbeTarget = release !== null
|
|
236
|
+
? 'https://github.com/'
|
|
237
|
+
: `${(settings.npmRegistry.replace(/\/+$/, '') || 'https://registry.npmjs.org')}/`
|
|
238
|
+
// git 通道的探针换成克隆握手本身:git ls-remote 走的就是 pnpm 克隆前的同一套
|
|
239
|
+
// https 传输。curl 打 github.com 主页会被按协议/端口区分的防火墙与 TLS 复检
|
|
240
|
+
// 拦截(能 git 克隆、打不开网页),把可装的仓库误判成 [network] 而中止。
|
|
241
|
+
// 握手失败时再用 curl 复核一次主页连通性:只有两者都不通
|
|
242
|
+
// 才判「网络不通」;仅握手失败(仓库不存在、私有仓库、需要凭据)放行,
|
|
243
|
+
// 交给后续预检与真实安装给出准确原因。
|
|
244
|
+
// 探针只握手仓库本身(去掉 git+ 前缀与 #ref 片段):ls-remote 认的是仓库地址,
|
|
245
|
+
// 带 ref 片段会干扰 URL 解析
|
|
246
|
+
const gitProbeTarget = repoTarget === null ? null : repoTarget.replace(/^git\+/, '').replace(/#.*$/, '')
|
|
247
|
+
let net: Awaited<ReturnType<typeof probeUrl>>
|
|
248
|
+
if (gitProbeTarget !== null) {
|
|
249
|
+
net = await gitLsRemote(gitProbeTarget, effectiveProxy, 6000)
|
|
250
|
+
if (!net.ok) {
|
|
251
|
+
const reachable = await probeUrl('https://github.com/', effectiveProxy, 6000)
|
|
252
|
+
if (reachable.ok) net = reachable
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
net = await probeUrl(httpProbeTarget, effectiveProxy, 6000)
|
|
256
|
+
}
|
|
257
|
+
const probeTarget = gitProbeTarget ?? httpProbeTarget
|
|
258
|
+
if (!net.ok) {
|
|
259
|
+
// 错误消息按客户端界面语言提示:中文界面给中文、英文界面给英文,
|
|
260
|
+
// 让用户一眼看懂是网络问题而非插件问题
|
|
261
|
+
const channelName = isGitChannel
|
|
262
|
+
? (lang === 'zh' ? 'GitHub' : 'github.com')
|
|
263
|
+
: (lang === 'zh' ? 'npm 源' : 'the npm registry')
|
|
264
|
+
const error = lang === 'zh'
|
|
265
|
+
? `[network] 安装已中止:安装前无法连接到 ${channelName}(${probeTarget})—— 您的网络似乎不通或被拦截(断网 / DNS 解析失败 / 防火墙 / 代理配置问题)。这不是插件本身的问题,请检查网络连接或代理设置,运行「系统诊断」检测各通道连通性后重试。`
|
|
266
|
+
: `[network] install aborted: cannot reach ${channelName} (${probeTarget}) before install — your network connection appears to be down or blocked (DNS / proxy / firewall). This is not a problem with the plugin itself. Check your connection or proxy settings, run the connectivity diagnostic, then retry.`
|
|
267
|
+
sendJson(response, 400, { error, attempts })
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// 安装前预检:仅新安装走预检(github 源分发改入口文件缺失时直接拦截)。
|
|
272
|
+
// 更新是已信任目标的覆盖重装,跳过预检避免重复下载 tarball。
|
|
273
|
+
// npm 包信任 registry 直接放行;github 源拦截时标记 [packaging] 前缀,
|
|
274
|
+
// 供客户端归类为「插件分发不完整」并引导去仓库提 Issue
|
|
275
|
+
if (already === null) {
|
|
276
|
+
const preflight = await preflightTarget(target)
|
|
277
|
+
if (!preflight.ok) {
|
|
278
|
+
// 预检拦截(git 分发缺入口文件):同步 400 返回,附上已尝试的安装方式,
|
|
279
|
+
// 客户端失败弹窗提 Issue 时一并贴给作者
|
|
280
|
+
sendJson(response, 400, {
|
|
281
|
+
error: `[packaging] ${target}: plugin distribution is incomplete — the entry file ${preflight.missing ?? '?'} declared in package.json is not present in the git distribution (build output not committed). Report to the author.`,
|
|
282
|
+
attempts,
|
|
283
|
+
})
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
// 包名冲突检测(仅 git 通道):git 目标包内声明的 name 若与 profile 已装依赖同名,
|
|
287
|
+
// pnpm 会以该 name 做依赖键撞车,抛出的 CLI 报错晦涩难懂 —— 且该包名在 registry 上
|
|
288
|
+
// 可能被别的仓库占用,npm 反查搜不到,git 直装就会撞上已装的同名依赖。
|
|
289
|
+
// 到这里已装依赖要么来源不同仓库、要么 spec 是版本号解析不出仓库身份。
|
|
290
|
+
// 读 node_modules 里已装包的真实 repository 区分两种情况:
|
|
291
|
+
// - 指向同一仓库 → 是「同仓库残留」(spec 丢了仓库身份),就地转 update 覆盖重装(幂等);
|
|
292
|
+
// - 指向别的仓库 / 读不到 → 跨仓库包名冲突,入队前转成明确 409,指导用户先卸载或改装。
|
|
293
|
+
if (preflight.name !== null && repoTarget !== null && target === repoTarget) {
|
|
294
|
+
const declared = preflight.name
|
|
295
|
+
if (installed[declared] !== undefined) {
|
|
296
|
+
const installedRepo = installedRepoOf(profile, declared)
|
|
297
|
+
if (installedRepo !== null && gitRepo !== null && installedRepo.toLowerCase() === gitRepo.toLowerCase()) {
|
|
298
|
+
// 同名且同源:已装 spec 丢了仓库身份导致的残留,直接按 update 覆盖重装,不打扰用户
|
|
299
|
+
attempts.push(`same-repo residual: \`${declared}\` resolves to \`${installedRepo}\` → reinstall as update`)
|
|
300
|
+
mode = 'update'
|
|
301
|
+
} else {
|
|
302
|
+
attempts.push(`package name conflict: \`${gitRepo}\` declares npm name \`${declared}\`, which is already present in the profile and cannot be matched to this repo (that npm name is likely registered by another repository)`)
|
|
303
|
+
const error = lang === 'zh'
|
|
304
|
+
? `already installed: ${declared} —— ${gitRepo} 声明的 npm 包名「${declared}」已存在于当前 profile,且无法匹配到本仓库(该包名在 npm 上可能被其他仓库占用)。请先移除现有的 ${declared}(dsh plugin remove ${declared}),再重新安装;或改装该包名对应的官方 npm 包。`
|
|
305
|
+
: `already installed: ${declared} — ${gitRepo} declares the npm package name "${declared}", which is already present in the profile and cannot be matched to this repo (that npm name is likely registered by another repository). Remove the existing ${declared} dependency (dsh plugin remove ${declared}) first, then retry; or install the official npm package under that name.`
|
|
306
|
+
sendJson(response, 409, { error, attempts })
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// 入队前复检(与上方检查同语义,但必须在同步块内):preflight 的 await 期间并发请求
|
|
313
|
+
// 可能已通过上方检查、任务却尚未入队——此处检查与 startPluginMutation 之间无 await,
|
|
314
|
+
// JS 单线程保证同一目标至多一个任务,杜绝双击/并发产生双任务
|
|
315
|
+
if (hasQueuedTarget(target)) {
|
|
316
|
+
sendJson(response, 409, { error: `already queued: ${target}` })
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
// Kick off the CLI in the background; the client polls /status for progress
|
|
320
|
+
const task = startPluginMutation({
|
|
321
|
+
// mode=update(已安装目标的覆盖更新)以 update 动作入队:
|
|
322
|
+
// 日志按 update 类别落盘(update.start/done/fail),实际 CLI 执行仍是 add <target>@latest
|
|
323
|
+
action: mode === 'update' ? 'update' : 'add',
|
|
324
|
+
profile,
|
|
325
|
+
target,
|
|
326
|
+
// npm 安装时 target 是包名:displayTarget 固定展示仓库名,待重启行/前端恢复不受通道变化影响
|
|
327
|
+
displayTarget: githubRepoOf(displayRepo) ?? undefined,
|
|
328
|
+
// 已尝试的安装方式(npm 反查):实际执行命令由 spawn 时追加,失败 issue 一并展示
|
|
329
|
+
attempts,
|
|
330
|
+
timeoutMs: COMMAND_TIMEOUT_MS,
|
|
331
|
+
env: mutationEnv(settings),
|
|
332
|
+
// 覆盖更新:npm 通道命令显式 @latest(pnpm add 无版本对已存在依赖是幂等的,不加版本不会真更新)
|
|
333
|
+
updateNpm: mode === 'update',
|
|
334
|
+
// 运行中 loader:安装成功后把新插件热挂进 loader,非桌面端 + 纯服务端插件无需重启即生效
|
|
335
|
+
loader,
|
|
336
|
+
// 自定义安装入口渠道(NPM 包 / GitHub 源码 / DSH 命令卡片):日志/报错据此溯源
|
|
337
|
+
installChannel,
|
|
338
|
+
})
|
|
339
|
+
sendJson(response, 200, { ok: true, task: task.id })
|
|
340
|
+
} catch (error) {
|
|
341
|
+
sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
kind: 'exact',
|
|
347
|
+
path: '/dsh-plugin-hub/uninstall',
|
|
348
|
+
handler: async (request, response) => {
|
|
349
|
+
if (!requireTrustedPost(request, response)) return
|
|
350
|
+
// 与安装一致:卸载也进入同一队列,FIFO 串行执行
|
|
351
|
+
try {
|
|
352
|
+
const body = await readJsonBody(request)
|
|
353
|
+
const name = typeof body === 'object' && body !== null && typeof (body as { name?: unknown }).name === 'string'
|
|
354
|
+
? (body as { name: string }).name
|
|
355
|
+
: ''
|
|
356
|
+
// 展示用的 owner/repo:卸载命令只需要 npm 包名,但待重启行要与安装行一致地显示仓库名
|
|
357
|
+
const repo = typeof body === 'object' && body !== null && typeof (body as { repo?: unknown }).repo === 'string'
|
|
358
|
+
? (body as { repo: string }).repo
|
|
359
|
+
: ''
|
|
360
|
+
if (!validPackageName(name) || name === 'dsh-plugin') {
|
|
361
|
+
sendJson(response, 400, { error: 'plugin cannot be uninstalled here' })
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
if (readInstalled(profile)[name] === undefined) {
|
|
365
|
+
sendJson(response, 400, { error: 'plugin is not installed' })
|
|
366
|
+
return
|
|
367
|
+
}
|
|
368
|
+
// 队列级去重:同一包已在排队/执行中卸载时拒绝
|
|
369
|
+
if (hasQueuedTarget(name)) {
|
|
370
|
+
sendJson(response, 409, { error: `already queued: ${name}` })
|
|
371
|
+
return
|
|
372
|
+
}
|
|
373
|
+
const task = startPluginMutation({
|
|
374
|
+
action: 'remove',
|
|
375
|
+
profile,
|
|
376
|
+
target: name,
|
|
377
|
+
// 卸载的 mutation 目标是 npm 包名;待重启行要显示 owner/repo(与安装行一致),非法/缺失时回退包名
|
|
378
|
+
displayTarget: githubRepoOf(repo) ?? undefined,
|
|
379
|
+
// 运行中 loader:卸载成功后主动移除条目,立即生效、无需重启
|
|
380
|
+
loader,
|
|
381
|
+
timeoutMs: COMMAND_TIMEOUT_MS,
|
|
382
|
+
env: mutationEnv(loadSettings(profile)),
|
|
383
|
+
})
|
|
384
|
+
sendJson(response, 200, { ok: true, task: task.id })
|
|
385
|
+
} catch (error) {
|
|
386
|
+
sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
]
|
|
391
|
+
}
|