dsh-modpack-kit 0.0.0-stage → 0.1.1
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/LICENSE +75 -0
- package/README.md +191 -2
- package/client.js +840 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +82 -0
- package/icon.svg +14 -0
- package/index.js +566 -0
- package/lib/classify.mjs +105 -0
- package/lib/compat.mjs +112 -0
- package/lib/install.mjs +344 -0
- package/lib/manifest.mjs +189 -0
- package/lib/market-catalog.mjs +419 -0
- package/lib/pack.mjs +382 -0
- package/lib/profile.mjs +274 -0
- package/lib/registry.mjs +223 -0
- package/lib/scan.mjs +278 -0
- package/lib/semver.mjs +143 -0
- package/lib/store.mjs +182 -0
- package/lib/tar.mjs +107 -0
- package/lib/yamlish.mjs +385 -0
- package/lib/zip.mjs +232 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -3
package/client.js
ADDED
|
@@ -0,0 +1,840 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-modpack —— 客户端半边:左侧栏「整合包」。
|
|
3
|
+
*
|
|
4
|
+
* 三页:打包(挑插件、选版本、看检测报告)、安装(链接/本机包、预览、落地)、
|
|
5
|
+
* 设置与记录(扫描策略、白名单、历史)。数据全部来自 /dsh-modpack/api/*(同源 fetch),
|
|
6
|
+
* 与 host 半端共用同一份状态;这里不碰文件,也不做网络请求。
|
|
7
|
+
*
|
|
8
|
+
* 制作通告:本文件在 DeepSeek Harness(DSH)会话中由 AI 助手与作者 Vesna-Strivozha-cn 协作产出。
|
|
9
|
+
*/
|
|
10
|
+
window.__ModuleLoader__.load({
|
|
11
|
+
id: "dsh-modpack-kit",
|
|
12
|
+
factory: (require) => {
|
|
13
|
+
const module = { exports: {} }
|
|
14
|
+
const exports = module.exports
|
|
15
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
16
|
+
|
|
17
|
+
const React = require("react")
|
|
18
|
+
const { createElement: h, useCallback, useEffect, useMemo, useRef, useState } = React
|
|
19
|
+
|
|
20
|
+
const API = "/dsh-modpack-kit/api"
|
|
21
|
+
|
|
22
|
+
const box = { border: "0.5px solid var(--dsw-alias-border-l2)", borderRadius: "8px", padding: "12px 14px" }
|
|
23
|
+
const hint = { color: "var(--dsw-alias-label-tertiary)", fontSize: "11.5px", lineHeight: "17px" }
|
|
24
|
+
const label = { fontSize: "13px", lineHeight: "19px" }
|
|
25
|
+
const strong = { fontSize: "13px", fontWeight: 600, lineHeight: "20px" }
|
|
26
|
+
const btn = { height: "28px", padding: "0 12px", fontSize: "12.5px", borderRadius: "6px", cursor: "pointer", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-primary)" }
|
|
27
|
+
const btnPrimary = { ...btn, background: "var(--dsw-alias-fill-primary, #3b6cf6)", borderColor: "transparent", color: "#fff" }
|
|
28
|
+
const input = { height: "26px", padding: "0 8px", fontSize: "12.5px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-primary)", boxSizing: "border-box" }
|
|
29
|
+
const mono = { fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", fontSize: "11.5px", lineHeight: "17px" }
|
|
30
|
+
const row = { display: "flex", gap: "8px", alignItems: "center", flexWrap: "wrap" }
|
|
31
|
+
const chip = { fontSize: "11px", padding: "1px 6px", borderRadius: "999px", border: "0.5px solid var(--dsw-alias-border-l2)", color: "var(--dsw-alias-label-secondary)" }
|
|
32
|
+
const chipBtn = { ...chip, cursor: "pointer", background: "transparent", fontFamily: "inherit" }
|
|
33
|
+
const chipOn = { ...chipBtn, color: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-fill-primary, #3b6cf6)" }
|
|
34
|
+
|
|
35
|
+
const LEVEL_COLOR = { high: "#ff6b6b", error: "#ff6b6b", medium: "#ffb020", warn: "#ffb020", low: "#8a8f98", info: "#8a8f98" }
|
|
36
|
+
const FORMAT_TEXT = { full: "完整版(含插件本体)", lite: "轻量版(联网取包)" }
|
|
37
|
+
// 分类以插件市场为准:id 与市场目录一致,中文名由 host 从市场目录里带回来。
|
|
38
|
+
const CATEGORY_LABELS = { all: "全部", other: "其它" }
|
|
39
|
+
const categoryOf = (entry) => (entry && entry.category) || "other"
|
|
40
|
+
|
|
41
|
+
// 三处显示位(设置内 / 侧边栏 / 插件内页签):各自独立开关,点一下立刻重挂载,不用重启。
|
|
42
|
+
const PLACEMENT_KEYS = ["settings", "sidebar", "pluginsTab"]
|
|
43
|
+
const placement = { value: { settings: true, sidebar: true, pluginsTab: false }, subs: new Set() }
|
|
44
|
+
function normalizePlacement(raw) {
|
|
45
|
+
const next = { settings: true, sidebar: true, pluginsTab: false }
|
|
46
|
+
if (raw && typeof raw === "object") for (const key of PLACEMENT_KEYS) if (typeof raw[key] === "boolean") next[key] = raw[key]
|
|
47
|
+
// 三处全关就等于把插件藏起来了,host 也拦;这里再兜一层
|
|
48
|
+
if (!next.settings && !next.sidebar && !next.pluginsTab) next.sidebar = true
|
|
49
|
+
return next
|
|
50
|
+
}
|
|
51
|
+
function setPlacement(raw) {
|
|
52
|
+
const next = normalizePlacement(raw)
|
|
53
|
+
const same = PLACEMENT_KEYS.every((key) => placement.value[key] === next[key])
|
|
54
|
+
placement.value = next
|
|
55
|
+
if (same) return
|
|
56
|
+
for (const fn of [...placement.subs]) { try { fn(next) } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
|
|
57
|
+
}
|
|
58
|
+
function subscribePlacement(fn) {
|
|
59
|
+
placement.subs.add(fn)
|
|
60
|
+
return () => placement.subs.delete(fn)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function api(pathname, body) {
|
|
64
|
+
const init = body === undefined ? { headers: { Accept: "application/json" } } : {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "Content-Type": "application/json" },
|
|
67
|
+
body: JSON.stringify(body),
|
|
68
|
+
}
|
|
69
|
+
let res
|
|
70
|
+
try {
|
|
71
|
+
res = await fetch(API + pathname, init)
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new Error("连不上 DSH 本体:" + (e && e.message ? e.message : e))
|
|
74
|
+
}
|
|
75
|
+
let data = null
|
|
76
|
+
try { data = await res.json() } catch {
|
|
77
|
+
throw new Error("服务端返回了非 JSON(HTTP " + res.status + ")")
|
|
78
|
+
}
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
// 统一在这里抛:上层只要 try/catch 就能把「为什么失败」显示出来,而不是静默卡住
|
|
81
|
+
const message = (data && (data.error || data.message)) || ("HTTP " + res.status)
|
|
82
|
+
const error = new Error(message)
|
|
83
|
+
error.status = res.status
|
|
84
|
+
error.data = data
|
|
85
|
+
throw error
|
|
86
|
+
}
|
|
87
|
+
return data
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const bytes = (n) => {
|
|
91
|
+
const v = Number(n) || 0
|
|
92
|
+
if (v < 1024) return v + " B"
|
|
93
|
+
if (v < 1024 * 1024) return (v / 1024).toFixed(1) + " KB"
|
|
94
|
+
return (v / 1024 / 1024).toFixed(2) + " MB"
|
|
95
|
+
}
|
|
96
|
+
const when = (iso) => {
|
|
97
|
+
if (!iso) return "—"
|
|
98
|
+
try { return new Date(iso).toLocaleString() } catch { return String(iso) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function Switch(props) {
|
|
102
|
+
return h("label", { style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
|
|
103
|
+
h("input", { type: "checkbox", checked: !!props.checked, disabled: !!props.disabled, onChange: (e) => props.onChange(e.target.checked) }),
|
|
104
|
+
props.label)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 一句话闪 5 秒:用于「点了也不给关」的开关。
|
|
108
|
+
function useNag(ms = 5000) {
|
|
109
|
+
const [text, setText] = useState("")
|
|
110
|
+
const timer = useRef(null)
|
|
111
|
+
const fire = useCallback((msg) => {
|
|
112
|
+
setText(msg)
|
|
113
|
+
if (timer.current) clearTimeout(timer.current)
|
|
114
|
+
timer.current = setTimeout(() => setText(""), ms)
|
|
115
|
+
}, [ms])
|
|
116
|
+
useEffect(() => () => { if (timer.current) clearTimeout(timer.current) }, [])
|
|
117
|
+
return [text, fire]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function NagText(props) {
|
|
121
|
+
if (!props.text) return null
|
|
122
|
+
return h("div", { style: { color: "#ff6b6b", fontSize: "12px", lineHeight: "18px" } }, props.text)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 强制项:开关照常显示(让人知道这项存在),但点不动——点一次弹红字。
|
|
126
|
+
function ForcedSwitch(props) {
|
|
127
|
+
return h("label", {
|
|
128
|
+
style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: "not-allowed", opacity: 0.6 },
|
|
129
|
+
title: "强制性检查,不能关",
|
|
130
|
+
onClick: (e) => { e.preventDefault(); props.onNag() },
|
|
131
|
+
},
|
|
132
|
+
h("input", { type: "checkbox", checked: true, readOnly: true, disabled: true, style: { cursor: "not-allowed" } }),
|
|
133
|
+
props.label)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function Tag(props) {
|
|
137
|
+
return h("span", { style: { ...chip, color: props.color || chip.color, borderColor: props.color || "var(--dsw-alias-border-l2)" } }, props.children)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function Notice(props) {
|
|
141
|
+
return h("div", { style: { ...box, borderColor: props.tone === "warn" ? "#ffb020" : props.tone === "bad" ? "#ff6b6b" : "var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-l2, transparent)", fontSize: "12px", lineHeight: "18px" } }, props.children)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function ScanReport(props) {
|
|
145
|
+
const scan = props.scan
|
|
146
|
+
if (!scan) return null
|
|
147
|
+
const findings = Array.isArray(scan.findings) ? scan.findings : []
|
|
148
|
+
const counts = scan.counts || { high: 0, medium: 0, low: 0 }
|
|
149
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
150
|
+
h("div", { style: row },
|
|
151
|
+
h("div", { style: strong }, "安全检测"),
|
|
152
|
+
h(Tag, { color: counts.high ? "#ff6b6b" : counts.medium ? "#ffb020" : "#2bb673" },
|
|
153
|
+
"高 " + counts.high + " · 中 " + counts.medium + " · 低 " + counts.low),
|
|
154
|
+
h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : ""))),
|
|
155
|
+
findings.length
|
|
156
|
+
? h("div", { style: { display: "flex", flexDirection: "column", gap: "4px", maxHeight: "190px", overflow: "auto" } },
|
|
157
|
+
findings.slice(0, 120).map((f, i) => h("div", { key: i, style: { ...mono, color: LEVEL_COLOR[f.severity] || "inherit" } },
|
|
158
|
+
"[" + String(f.severity || "").toUpperCase() + "] " + (f.label || f.rule) + " · " + f.file + (f.line ? ":" + f.line : "") + " · " + (f.masked || ""))))
|
|
159
|
+
: h("div", { style: hint }, "没有命中敏感信息或可疑代码规则。"),
|
|
160
|
+
h("div", { style: hint }, props.footNote || "命中内容只在内存里比对,报告只保留类型、位置与掩码,原文不落盘。"))
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function CompatList(props) {
|
|
164
|
+
const compat = props.compat
|
|
165
|
+
if (!compat) return null
|
|
166
|
+
const findings = compat.findings || []
|
|
167
|
+
if (findings.length === 0) return h("div", { style: hint }, "兼容性:没有发现问题。")
|
|
168
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "5px" } },
|
|
169
|
+
h("div", { style: row }, h("div", { style: strong }, "兼容性"), h("span", { style: hint }, compat.summary || ""),
|
|
170
|
+
compat.blocking ? h(Tag, { color: "#ff6b6b" }, "有阻断项") : null),
|
|
171
|
+
findings.map((f, i) => h("div", { key: i, style: { borderLeft: "2px solid " + (LEVEL_COLOR[f.level] || "transparent"), paddingLeft: "8px" } },
|
|
172
|
+
h("div", { style: { ...label, color: LEVEL_COLOR[f.level] || "inherit" } }, (f.plugin ? f.plugin + ":" : "") + f.message),
|
|
173
|
+
f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// —— 打包 ——
|
|
177
|
+
function PackPanel(props) {
|
|
178
|
+
const status = props.status
|
|
179
|
+
const pageSize = (status && status.config && status.config.catalogPageSize) || 20
|
|
180
|
+
const [installed, setInstalled] = useState((status && status.installed) || [])
|
|
181
|
+
const [marketInfo, setMarketInfo] = useState({}) // name -> 市场同名条目(标题/版本/分类)
|
|
182
|
+
const [catalog, setCatalog] = useState((status && status.catalog) || { present: false, categories: [] })
|
|
183
|
+
const [loading, setLoading] = useState(!(status && status.installed))
|
|
184
|
+
const [selected, setSelected] = useState({}) // name -> {source, spec, mode}
|
|
185
|
+
const [query, setQuery] = useState("")
|
|
186
|
+
const [category, setCategory] = useState("all")
|
|
187
|
+
const [search, setSearch] = useState({ items: [], total: 0, page: 0, hasMore: false, error: "" })
|
|
188
|
+
const [searching, setSearching] = useState(false)
|
|
189
|
+
const [syncing, setSyncing] = useState("")
|
|
190
|
+
const [options, setOptions] = useState({
|
|
191
|
+
includePayload: true,
|
|
192
|
+
includeConfig: true,
|
|
193
|
+
includeLocalEdits: false,
|
|
194
|
+
scanBeforePack: true,
|
|
195
|
+
confirmLicense: false,
|
|
196
|
+
name: "DSH 整合包",
|
|
197
|
+
description: "",
|
|
198
|
+
author: "",
|
|
199
|
+
})
|
|
200
|
+
const [busy, setBusy] = useState("")
|
|
201
|
+
const [result, setResult] = useState(null)
|
|
202
|
+
const [error, setError] = useState("")
|
|
203
|
+
const [packNag, firePackNag] = useNag()
|
|
204
|
+
|
|
205
|
+
const active = query.trim() !== "" || category !== "all"
|
|
206
|
+
|
|
207
|
+
// 首屏只读「已装 + 目录摘要 + 每条的相机市场信息」,不整份下发目录
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
let alive = true
|
|
210
|
+
;(async () => {
|
|
211
|
+
try {
|
|
212
|
+
const st = status && status.installed ? status : await api("/status")
|
|
213
|
+
if (!alive) return
|
|
214
|
+
const list = (st && st.installed) || []
|
|
215
|
+
setInstalled(list)
|
|
216
|
+
setCatalog((st && st.catalog) || { present: false, categories: [] })
|
|
217
|
+
if (st && st.placements) setPlacement(st.placements)
|
|
218
|
+
if (list.length) {
|
|
219
|
+
const look = await api("/catalog/lookup", { names: list.map((p) => p.name) })
|
|
220
|
+
if (alive && look && look.ok) setMarketInfo(look.items || {})
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
if (alive) setError(e.message || String(e))
|
|
224
|
+
} finally {
|
|
225
|
+
if (alive) setLoading(false)
|
|
226
|
+
}
|
|
227
|
+
})()
|
|
228
|
+
return () => { alive = false }
|
|
229
|
+
}, [])
|
|
230
|
+
|
|
231
|
+
// 搜索/选分类才查市场目录;服务端分页,一次一页,输入停 220ms 再发
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
if (!active) { setSearch({ items: [], total: 0, page: 0, hasMore: false, error: "" }); return }
|
|
234
|
+
let alive = true
|
|
235
|
+
const timer = setTimeout(async () => {
|
|
236
|
+
setSearching(true)
|
|
237
|
+
try {
|
|
238
|
+
const data = await api("/catalog/search", { query, category, page: 1, pageSize })
|
|
239
|
+
if (!alive) return
|
|
240
|
+
setSearch({
|
|
241
|
+
items: data.items || [],
|
|
242
|
+
total: data.total || 0,
|
|
243
|
+
page: data.page || 1,
|
|
244
|
+
hasMore: !!data.hasMore,
|
|
245
|
+
error: data.error || "",
|
|
246
|
+
})
|
|
247
|
+
} catch (e) {
|
|
248
|
+
if (alive) setSearch({ items: [], total: 0, page: 0, hasMore: false, error: e.message || String(e) })
|
|
249
|
+
} finally {
|
|
250
|
+
if (alive) setSearching(false)
|
|
251
|
+
}
|
|
252
|
+
}, 220)
|
|
253
|
+
return () => { alive = false; clearTimeout(timer) }
|
|
254
|
+
}, [query, category, active, pageSize])
|
|
255
|
+
|
|
256
|
+
const loadMore = async () => {
|
|
257
|
+
if (searching || !search.hasMore) return
|
|
258
|
+
setSearching(true)
|
|
259
|
+
try {
|
|
260
|
+
const data = await api("/catalog/search", { query, category, page: (search.page || 1) + 1, pageSize })
|
|
261
|
+
setSearch((prev) => ({
|
|
262
|
+
...prev,
|
|
263
|
+
items: prev.items.concat(data.items || []),
|
|
264
|
+
page: data.page || prev.page,
|
|
265
|
+
hasMore: !!data.hasMore,
|
|
266
|
+
total: data.total || prev.total,
|
|
267
|
+
}))
|
|
268
|
+
} catch (e) {
|
|
269
|
+
setSearch((prev) => ({ ...prev, error: e.message || String(e) }))
|
|
270
|
+
} finally {
|
|
271
|
+
setSearching(false)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const buildCatalog = async () => {
|
|
276
|
+
setSyncing("正在从插件市场取目录(5~30 秒,看网络)…")
|
|
277
|
+
try {
|
|
278
|
+
const data = await api("/catalog/sync", { force: true })
|
|
279
|
+
if (data && data.ok) {
|
|
280
|
+
setCatalog((data.catalog) || { present: true })
|
|
281
|
+
setSyncing("目录就绪:" + (data.count || 0) + " 条" + (data.skipped ? "(本来就有)" : ""))
|
|
282
|
+
} else {
|
|
283
|
+
setSyncing((data && data.error) || "目录没取到,稍后再试")
|
|
284
|
+
}
|
|
285
|
+
} catch (e) {
|
|
286
|
+
setSyncing(String((e && e.message) || e))
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const localRows = useMemo(() => installed.map((p) => {
|
|
291
|
+
const m = marketInfo[p.name] || {}
|
|
292
|
+
return {
|
|
293
|
+
name: p.name,
|
|
294
|
+
version: p.version,
|
|
295
|
+
title: m.title || p.name,
|
|
296
|
+
description: m.description || p.description || "",
|
|
297
|
+
category: m.category || p.category || "other",
|
|
298
|
+
marketVersion: m.version || "",
|
|
299
|
+
hasMarket: Boolean(m.version),
|
|
300
|
+
source: "profile",
|
|
301
|
+
}
|
|
302
|
+
}), [installed, marketInfo])
|
|
303
|
+
|
|
304
|
+
const rows = active ? search.items : localRows
|
|
305
|
+
const chips = useMemo(() => {
|
|
306
|
+
const list = (catalog && Array.isArray(catalog.categories)) ? catalog.categories : []
|
|
307
|
+
return [{ id: "all", label: "全部", count: (catalog && catalog.count) || 0 }].concat(list.map((c) => ({ id: c.id, label: c.label, count: c.count || 0 })))
|
|
308
|
+
}, [catalog])
|
|
309
|
+
const labelOf = (id) => {
|
|
310
|
+
const hit = chips.find((c) => c.id === id)
|
|
311
|
+
return (hit && hit.label) || CATEGORY_LABELS[id] || id
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const picked = Object.keys(selected)
|
|
315
|
+
const toggle = (entry) => {
|
|
316
|
+
setSelected((prev) => {
|
|
317
|
+
const next = { ...prev }
|
|
318
|
+
if (next[entry.name]) delete next[entry.name]
|
|
319
|
+
else next[entry.name] = {
|
|
320
|
+
name: entry.name,
|
|
321
|
+
source: entry.source,
|
|
322
|
+
spec: entry.version || "",
|
|
323
|
+
mode: entry.source === "profile" ? (options.includeLocalEdits ? "local" : "base") : "base",
|
|
324
|
+
}
|
|
325
|
+
return next
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
const setSpec = (name, spec) => setSelected((prev) => ({ ...prev, [name]: { ...prev[name], spec } }))
|
|
329
|
+
const setMode = (name, mode) => setSelected((prev) => ({ ...prev, [name]: { ...prev[name], mode } }))
|
|
330
|
+
// 同名市场版:装出来是上游原版代码 + 插件默认配置
|
|
331
|
+
const switchMarket = (entry, toMarket) => setSelected((prev) => {
|
|
332
|
+
if (!prev[entry.name]) return prev
|
|
333
|
+
return {
|
|
334
|
+
...prev,
|
|
335
|
+
[entry.name]: toMarket
|
|
336
|
+
? { name: entry.name, source: "npm", spec: entry.marketVersion || "", mode: "base" }
|
|
337
|
+
: { name: entry.name, source: "profile", spec: entry.version || "", mode: options.includeLocalEdits ? "local" : "base" },
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
const doPack = async () => {
|
|
342
|
+
setBusy("pack"); setError(""); setResult(null)
|
|
343
|
+
try {
|
|
344
|
+
const data = await api("/pack", {
|
|
345
|
+
selection: picked.map((name) => selected[name]),
|
|
346
|
+
options: {
|
|
347
|
+
includePayload: options.includePayload,
|
|
348
|
+
includeConfig: options.includeConfig,
|
|
349
|
+
includeLocalEdits: options.includeLocalEdits,
|
|
350
|
+
scanBeforePack: options.scanBeforePack,
|
|
351
|
+
confirmLicense: options.confirmLicense,
|
|
352
|
+
name: options.name,
|
|
353
|
+
description: options.description,
|
|
354
|
+
author: options.author,
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
if (!data) { setError("没有响应"); return }
|
|
358
|
+
if (!data.ok) { setResult({ refused: data.refused, error: data.error, scan: data.scan }); return }
|
|
359
|
+
setResult(data)
|
|
360
|
+
} catch (e) {
|
|
361
|
+
setError(String((e && e.message) || e))
|
|
362
|
+
} finally { setBusy("") }
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const downloadPack = async () => {
|
|
366
|
+
if (!result || !result.token) return
|
|
367
|
+
setBusy("download")
|
|
368
|
+
try {
|
|
369
|
+
const res = await fetch(API + "/download", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: result.token, fileName: result.fileName }) })
|
|
370
|
+
if (!res.ok) { setError("下载失败(" + res.status + ")"); return }
|
|
371
|
+
const blob = await res.blob()
|
|
372
|
+
const url = URL.createObjectURL(blob)
|
|
373
|
+
const a = document.createElement("a")
|
|
374
|
+
a.href = url
|
|
375
|
+
a.download = result.fileName || "pack.dshpack"
|
|
376
|
+
document.body.appendChild(a)
|
|
377
|
+
a.click()
|
|
378
|
+
setTimeout(() => { try { a.remove(); URL.revokeObjectURL(url) } catch {} }, 4000)
|
|
379
|
+
} catch (e) {
|
|
380
|
+
setError("下载失败:" + (e && e.message ? e.message : e))
|
|
381
|
+
} finally { setBusy("") }
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const savePack = async () => {
|
|
385
|
+
if (!result || !result.token) return
|
|
386
|
+
setBusy("save")
|
|
387
|
+
try {
|
|
388
|
+
const data = await api("/save", { token: result.token, fileName: result.fileName })
|
|
389
|
+
if (data && data.ok) setResult({ ...result, savedPath: data.path })
|
|
390
|
+
else setError((data && data.error) || "保存失败")
|
|
391
|
+
} catch (e) {
|
|
392
|
+
setError(e.message || String(e))
|
|
393
|
+
} finally { setBusy("") }
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
397
|
+
h(Notice, null,
|
|
398
|
+
h("b", null, "打包就是把这些插件打成一个 .dshpack"),
|
|
399
|
+
" 完整版连插件本体一起装进包里;轻量版只记录名字和版本,装的时候联网按版本取。两种都不改你的 profile,直到你真的点安装。",
|
|
400
|
+
status && status.market && status.market.installed
|
|
401
|
+
? h("div", { style: { ...hint, marginTop: "6px" } }, "插件市场 v" + status.market.version + " 已装:目录、本机列表、安装链路都是同一条;本插件不依赖它,拆掉也照常打包与装包。")
|
|
402
|
+
: h("div", { style: { ...hint, marginTop: "6px" } }, "没装插件市场也能用:打包、装包、检测全在本地跑。建议先装一下 dshmarket —— 分类、搜索、「(切换市场版)」会更顺手;不装的话第一次自己点一次「建立目录索引」即可,其余体验不受影响。"),
|
|
403
|
+
h("div", { style: hint }, "市场里若有同名插件,那多半就是它的市场版:行末小字「(切换市场版)」可以改成打上游原版,装出来和你从市场装一样。")),
|
|
404
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
405
|
+
h("div", { style: row },
|
|
406
|
+
h("div", { style: strong }, "选择插件"),
|
|
407
|
+
h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "搜索插件名 / 描述(在插件市场目录里搜)", value: query, onChange: (e) => setQuery(e.target.value) }),
|
|
408
|
+
active ? h("button", { style: btn, onClick: () => { setQuery(""); setCategory("all") } }, "回到已装") : null,
|
|
409
|
+
h("span", { style: hint }, loading ? "读取中…" : active
|
|
410
|
+
? ("已选 " + picked.length + " · 匹配 " + search.total + " 条" + (searching ? " · 搜索中…" : "") + (search.total > rows.length ? " · 已加载 " + rows.length : ""))
|
|
411
|
+
: ("已选 " + picked.length + " 个 · 本机已装 " + localRows.length + " 个"))),
|
|
412
|
+
!catalog.present
|
|
413
|
+
? h("div", { style: row },
|
|
414
|
+
h("span", { style: hint }, "还没有插件市场目录——分类和搜索要靠它。"),
|
|
415
|
+
h("button", { style: btn, disabled: !!syncing, onClick: buildCatalog }, syncing || "建立目录索引(5~30 秒)"))
|
|
416
|
+
: null,
|
|
417
|
+
catalog.present && syncing ? h("div", { style: hint }, syncing) : null,
|
|
418
|
+
catalog.present ? h("div", { style: { ...row, rowGap: "4px", maxHeight: "78px", overflow: "auto" } },
|
|
419
|
+
chips.map((c) => h("button", {
|
|
420
|
+
key: c.id,
|
|
421
|
+
style: category === c.id ? chipOn : chipBtn,
|
|
422
|
+
onClick: () => setCategory(c.id),
|
|
423
|
+
title: "只看「" + c.label + "」" + (c.count ? ",市场内 " + c.count + " 个" : ""),
|
|
424
|
+
}, c.label + (c.count ? " " + c.count : "")))) : null,
|
|
425
|
+
search.error ? h("div", { style: { ...hint, color: "#ffb020" } }, search.error) : null,
|
|
426
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "320px", overflow: "auto" } },
|
|
427
|
+
rows.length === 0
|
|
428
|
+
? h("div", { style: hint }, loading ? "稍等…" : active ? (searching ? "搜索中…" : "没有匹配的插件") : "本机还没有装插件")
|
|
429
|
+
: rows.map((entry) => {
|
|
430
|
+
const on = Boolean(selected[entry.name])
|
|
431
|
+
return h("div", { key: entry.name, style: { display: "flex", gap: "8px", alignItems: "center", padding: "5px 2px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", flexWrap: "wrap" } },
|
|
432
|
+
h("input", { type: "checkbox", checked: on, onChange: () => toggle(entry) }),
|
|
433
|
+
h("div", { style: { flex: "1 1 220px", minWidth: "180px" } },
|
|
434
|
+
h("div", { style: label }, entry.title || entry.name, " ", h("span", { style: hint }, "@" + (entry.version || "?"))),
|
|
435
|
+
h("div", { style: hint }, (entry.description || "").slice(0, 110))),
|
|
436
|
+
h("span", { style: chip }, entry.installed === false ? "市场" : "本机"),
|
|
437
|
+
h("span", { style: { ...chip, color: "var(--dsw-alias-label-tertiary)" } }, labelOf(categoryOf(entry))),
|
|
438
|
+
entry.updateAvailable ? h(Tag, { color: "#2bb673" }, "市场版 " + (entry.marketVersion || entry.version) + " 更新") : null,
|
|
439
|
+
on ? h("input", {
|
|
440
|
+
style: { ...input, width: "120px" },
|
|
441
|
+
placeholder: selected[entry.name].source === "npm" ? "版本,空=最新" : "版本,空=原版",
|
|
442
|
+
value: selected[entry.name].spec || "",
|
|
443
|
+
onChange: (e) => setSpec(entry.name, e.target.value),
|
|
444
|
+
}) : null,
|
|
445
|
+
on && entry.source === "profile" && selected[entry.name].source === "profile" ? h("div", { style: { display: "flex", gap: "4px" } },
|
|
446
|
+
h("button", { style: selected[entry.name].mode === "base" ? chipOn : chipBtn, onClick: () => setMode(entry.name, "base"), title: "上游原版代码 + 插件默认配置,不带你的修改" }, "基础配置"),
|
|
447
|
+
h("button", { style: selected[entry.name].mode === "local" ? chipOn : chipBtn, onClick: () => setMode(entry.name, "local"), title: "打你本机现在的代码、配置与数据快照" }, "本地改动")) : null,
|
|
448
|
+
entry.hasMarket && entry.source === "profile" && on ? h("button", {
|
|
449
|
+
style: { ...chipBtn, border: "none", fontSize: "10.5px", color: "var(--dsw-alias-label-tertiary)" },
|
|
450
|
+
onClick: () => switchMarket(entry, selected[entry.name].source !== "npm"),
|
|
451
|
+
title: "改用插件市场发的同名版本(上游原版代码 + 默认配置),装出来和从市场装一样",
|
|
452
|
+
}, selected[entry.name].source === "npm" ? "(切回本机版)" : "(切换市场版)") : null)
|
|
453
|
+
})),
|
|
454
|
+
active && search.hasMore ? h("div", { style: row },
|
|
455
|
+
h("button", { style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : ("加载更多(还有 " + Math.max(0, search.total - rows.length) + " 条)"))) : null,
|
|
456
|
+
h("div", { style: hint }, active
|
|
457
|
+
? "排序:已装的排前面,其余按插件市场的相关度与目录顺序。分类和词条都来自插件市场目录。"
|
|
458
|
+
: "首屏只列本机已装。搜索或点分类才会去插件市场目录里查,服务端分页、一次一页。")
|
|
459
|
+
),
|
|
460
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
461
|
+
h("div", { style: strong }, "包选项"),
|
|
462
|
+
h("div", { style: { ...row, rowGap: "6px" } },
|
|
463
|
+
h(Switch, { checked: options.includePayload, label: "包含插件本体(关=轻量版)", onChange: (v) => setOptions({ ...options, includePayload: v }) }),
|
|
464
|
+
h(Switch, { checked: options.includeConfig, label: "包含配置与数据快照", onChange: (v) => setOptions({ ...options, includeConfig: v }) }),
|
|
465
|
+
h(Switch, { checked: options.includeLocalEdits, label: "默认打包本机修改(勾选后可逐个改)", onChange: (v) => setOptions({ ...options, includeLocalEdits: v }) }),
|
|
466
|
+
h(ForcedSwitch, { label: "打包前安全检测(强制)", onNag: () => firePackNag("你想干什么") })),
|
|
467
|
+
h(NagText, { text: packNag }),
|
|
468
|
+
h("div", { style: { ...row, rowGap: "6px" } },
|
|
469
|
+
h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "整合包名", value: options.name, onChange: (e) => setOptions({ ...options, name: e.target.value }) }),
|
|
470
|
+
h("input", { style: { ...input, flex: "1 1 160px" }, placeholder: "作者(可空)", value: options.author, onChange: (e) => setOptions({ ...options, author: e.target.value }) })),
|
|
471
|
+
h("input", { style: { ...input, width: "100%" }, placeholder: "一句话描述(可空)", value: options.description, onChange: (e) => setOptions({ ...options, description: e.target.value }) }),
|
|
472
|
+
h(Switch, { checked: options.confirmLicense, label: "我确认所选插件的许可证允许再分发,或已获得作者授权", onChange: (v) => setOptions({ ...options, confirmLicense: v }) }),
|
|
473
|
+
h("div", { style: row },
|
|
474
|
+
h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "pack", onClick: doPack }, busy === "pack" ? "打包中…" : ("打包 " + picked.length + " 个插件")),
|
|
475
|
+
status ? h("span", { style: hint }, "DSH " + (status.dshVersion || "?") + " · profile " + status.profile) : null)),
|
|
476
|
+
error ? h(Notice, { tone: "bad" }, error) : null,
|
|
477
|
+
result ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
478
|
+
result.refused || result.error
|
|
479
|
+
? h(Notice, { tone: "warn" }, h("b", null, "已停止:"), result.error || "未通过检查", result.scan ? null : null)
|
|
480
|
+
: h("div", { style: row },
|
|
481
|
+
h("div", { style: strong }, result.fileName),
|
|
482
|
+
h(Tag, { color: "#2bb673" }, bytes(result.size)),
|
|
483
|
+
h(Tag, null, FORMAT_TEXT[result.manifest && result.manifest.format] || ""),
|
|
484
|
+
h("span", { style: hint }, "包内插件 " + ((result.manifest && result.manifest.plugins) || []).length + " 个")),
|
|
485
|
+
result.scan ? h(ScanReport, { scan: result.scan, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
|
|
486
|
+
result.manifest && result.manifest.plugins && result.manifest.plugins.length
|
|
487
|
+
? h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
|
|
488
|
+
result.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
|
|
489
|
+
"· " + p.name + "@" + p.version + " " + (p.size ? bytes(p.size) : "") + ((p.mode === "local" || p.localEdits) ? " [本地改动]" : " [基础配置]") + (p.configIncluded ? " [含配置]" : ""))))
|
|
490
|
+
: null,
|
|
491
|
+
result.compat ? h(CompatList, { compat: result.compat }) : null,
|
|
492
|
+
result.notes && result.notes.length ? h("div", { style: { ...hint, maxHeight: "110px", overflow: "auto" } }, result.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
|
|
493
|
+
result.refused || result.error ? null : h("div", { style: row },
|
|
494
|
+
h("button", { style: btnPrimary, disabled: busy !== "", onClick: downloadPack }, busy === "download" ? "准备下载…" : "下载 .dshpack"),
|
|
495
|
+
h("button", { style: btn, disabled: busy !== "", onClick: savePack }, busy === "save" ? "保存中…" : "保存到本机 packs/"),
|
|
496
|
+
result.savedPath ? h("span", { style: hint }, "已存:" + result.savedPath) : null),
|
|
497
|
+
result.refused || result.error ? null : h("div", { style: hint }, "下载完点「安装 / 导入」页签就能读回来,或把文件发给别人。"))
|
|
498
|
+
: null)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// —— 安装 / 导入 ——
|
|
502
|
+
function InstallPanel(props) {
|
|
503
|
+
const [source, setSource] = useState({ kind: "url", url: "", file: "" })
|
|
504
|
+
const [packs, setPacks] = useState([])
|
|
505
|
+
const [preview, setPreview] = useState(null)
|
|
506
|
+
const [busy, setBusy] = useState("")
|
|
507
|
+
const [error, setError] = useState("")
|
|
508
|
+
const [done, setDone] = useState(null)
|
|
509
|
+
const [options, setOptions] = useState({ keepLocal: true, applyConfig: true, force: false, dryRun: false, enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) })
|
|
510
|
+
|
|
511
|
+
const reloadPacks = useCallback(async () => {
|
|
512
|
+
try {
|
|
513
|
+
const data = await api("/packs")
|
|
514
|
+
if (data && data.ok) setPacks(data.items || [])
|
|
515
|
+
} catch { /* 列目录失败不打扰用户,真要装可以用链接 */ }
|
|
516
|
+
}, [])
|
|
517
|
+
useEffect(() => { reloadPacks() }, [reloadPacks])
|
|
518
|
+
|
|
519
|
+
const bodyFor = () => {
|
|
520
|
+
if (source.kind === "url") return { url: source.url.trim() }
|
|
521
|
+
return { file: source.file }
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const inspect = async () => {
|
|
525
|
+
setBusy("inspect"); setError(""); setPreview(null); setDone(null)
|
|
526
|
+
try {
|
|
527
|
+
const data = await api("/inspect", { ...bodyFor(), force: options.force })
|
|
528
|
+
if (data && data.ok) setPreview(data)
|
|
529
|
+
else { setPreview(null); setError((data && data.error) || "读取失败") }
|
|
530
|
+
} catch (e) {
|
|
531
|
+
setPreview(null); setError(e.message || String(e))
|
|
532
|
+
} finally { setBusy("") }
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const install = async () => {
|
|
536
|
+
setBusy("install"); setError(""); setDone(null)
|
|
537
|
+
try {
|
|
538
|
+
const data = await api("/install", { ...bodyFor(), ...options })
|
|
539
|
+
if (!data.ok) {
|
|
540
|
+
setDone({ ok: false, error: data.error, refused: data.refused, scan: data.scan, report: data.report })
|
|
541
|
+
return
|
|
542
|
+
}
|
|
543
|
+
setDone(data)
|
|
544
|
+
} catch (e) {
|
|
545
|
+
setDone({ ok: false, error: e.message || String(e), scan: (e.data && e.data.scan) || null, report: (e.data && e.data.report) || "", refused: Boolean(e.data && e.data.refused) })
|
|
546
|
+
} finally { setBusy("") }
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
550
|
+
h(Notice, null,
|
|
551
|
+
h("b", null, "先看清楚,再装"),
|
|
552
|
+
" 读取阶段解压、校验完整性、扫一遍风险,全部在内存里完成;只有你点「安装」才会碰 profile。安装走官方 ",
|
|
553
|
+
h("code", { style: mono }, "dsh plugin add"), ",不手改 node_modules。"),
|
|
554
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
555
|
+
h("div", { style: row },
|
|
556
|
+
h("button", { style: source.kind === "url" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "url" }) }, "从链接读取"),
|
|
557
|
+
h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "从本机 packs/ 读取")),
|
|
558
|
+
source.kind === "url"
|
|
559
|
+
? h("input", { style: { ...input, width: "100%" }, placeholder: "https://…/xxx.dshpack", value: source.url, onChange: (e) => setSource({ ...source, url: e.target.value }) })
|
|
560
|
+
: h("div", { style: row },
|
|
561
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", flex: "1 1 260px", maxHeight: "170px", overflow: "auto" } },
|
|
562
|
+
packs.length === 0 ? h("div", { style: hint }, "packs 目录还是空的。先去打包页生成一个,或把 .dshpack 放进 " + ((props.status && props.status.paths && props.status.paths.packs) || "packs")) : null,
|
|
563
|
+
packs.map((p) => h("label", { key: p.name, style: { ...row, gap: "6px", cursor: "pointer" } },
|
|
564
|
+
h("input", { type: "radio", name: "packfile", checked: source.file === p.name, onChange: () => setSource({ ...source, file: p.name }) }),
|
|
565
|
+
h("span", { style: label }, p.name),
|
|
566
|
+
h("span", { style: hint }, bytes(p.size) + " · " + when(p.mtime))))),
|
|
567
|
+
h("button", { style: btn, onClick: reloadPacks }, "刷新")),
|
|
568
|
+
h("div", { style: row },
|
|
569
|
+
h(Switch, { checked: options.keepLocal, label: "保留本地已有修改(不覆盖已装插件)", onChange: (v) => setOptions({ ...options, keepLocal: v }) }),
|
|
570
|
+
h(Switch, { checked: options.applyConfig, label: "安装后回填包内配置", onChange: (v) => setOptions({ ...options, applyConfig: v }) }),
|
|
571
|
+
h(Switch, { checked: options.enableBundles, label: "安装后直接启用(登记 bundle,重启后加载;默认关)", onChange: (v) => setOptions({ ...options, enableBundles: v }) }),
|
|
572
|
+
h(Switch, { checked: options.force, label: "忽略阻断(我知道自己在干什么)", onChange: (v) => setOptions({ ...options, force: v }) })),
|
|
573
|
+
h("div", { style: row },
|
|
574
|
+
h("button", { style: btnPrimary, disabled: busy !== "" || (source.kind === "url" ? !source.url.trim() : !source.file), onClick: inspect }, busy === "inspect" ? "检测中…" : "检测这个包"),
|
|
575
|
+
source.kind === "file" && source.file ? h("span", { style: hint }, "选中:" + source.file) : null)),
|
|
576
|
+
error ? h(Notice, { tone: "bad" }, error) : null,
|
|
577
|
+
preview ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
578
|
+
h("div", { style: row },
|
|
579
|
+
h("div", { style: strong }, preview.manifest.name),
|
|
580
|
+
h(Tag, null, FORMAT_TEXT[preview.manifest.format] || preview.manifest.format),
|
|
581
|
+
h(Tag, { color: preview.integrity && preview.integrity.ok ? "#2bb673" : "#ffb020" }, preview.integrity && preview.integrity.present ? (preview.integrity.ok ? "完整性通过" : "完整性有出入") : "无完整性清单"),
|
|
582
|
+
h("span", { style: hint }, "生成于 " + when(preview.manifest.createdAt) + (preview.manifest.author ? " · " + preview.manifest.author : ""))),
|
|
583
|
+
preview.manifest.description ? h("div", { style: label }, preview.manifest.description) : null,
|
|
584
|
+
preview.blockingReasons && preview.blockingReasons.length
|
|
585
|
+
? h(Notice, { tone: "bad" }, h("b", null, "阻断:" ), preview.blockingReasons.join(";"), " (真要装,勾上面的「忽略阻断」)")
|
|
586
|
+
: null,
|
|
587
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
|
|
588
|
+
preview.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
|
|
589
|
+
"· " + p.name + "@" + p.version + (p.localEdits ? " [含本机修改]" : "") + (p.configIncluded ? " [有配置]" : "") + (p.dataIncluded ? " [有数据快照]" : "")))),
|
|
590
|
+
h(ScanReport, { scan: preview.scan }),
|
|
591
|
+
h(CompatList, { compat: preview.compat }),
|
|
592
|
+
preview.notes && preview.notes.length ? h("div", { style: hint }, preview.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
|
|
593
|
+
h("div", { style: row },
|
|
594
|
+
h(Switch, { checked: options.dryRun, label: "只演练不落地", onChange: (v) => setOptions({ ...options, dryRun: v }) }),
|
|
595
|
+
h("button", { style: btnPrimary, disabled: busy !== "", onClick: install }, busy === "install" ? "安装中…" : (options.dryRun ? "演练一次" : "安装这个整合包"))))
|
|
596
|
+
: null,
|
|
597
|
+
done ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
598
|
+
h("div", { style: row },
|
|
599
|
+
h("div", { style: strong }, done.ok ? "安装完成" : "没有装成"),
|
|
600
|
+
done.needsRestart ? h(Tag, { color: "#ffb020" }, "需要重启 DSH 生效") : null),
|
|
601
|
+
done.error ? h("div", { style: { ...label, color: "#ff6b6b" } }, done.error) : null,
|
|
602
|
+
(done.actions || []).map((a, i) => h("div", { key: i, style: { ...mono, color: a.ok ? "inherit" : "#ff6b6b" } },
|
|
603
|
+
(a.ok ? "✓ " : "✗ ") + a.plugin + " · " + a.action + " · " + a.message)),
|
|
604
|
+
(done.lines || []).length ? h("details", null, h("summary", { style: hint }, "命令输出(" + done.lines.length + " 行)"),
|
|
605
|
+
h("pre", { style: { ...mono, maxHeight: "200px", overflow: "auto", whiteSpace: "pre-wrap" } }, done.lines.join("\n"))) : null,
|
|
606
|
+
done.scan ? h(ScanReport, { scan: done.scan }) : null)
|
|
607
|
+
: null)
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// —— 设置与记录 ——
|
|
611
|
+
function SettingsPanel(props) {
|
|
612
|
+
const [cfg, setCfg] = useState(props.status ? props.status.config : null)
|
|
613
|
+
const [saved, setSaved] = useState("")
|
|
614
|
+
const [busy, setBusy] = useState(false)
|
|
615
|
+
const [scanNag, fireScanNag] = useNag()
|
|
616
|
+
const history = (props.status && props.status.history) || []
|
|
617
|
+
|
|
618
|
+
const patch = async (p) => {
|
|
619
|
+
setBusy(true); setSaved("")
|
|
620
|
+
try {
|
|
621
|
+
const data = await api("/settings", { patch: p })
|
|
622
|
+
if (data && data.ok) { setCfg(data.config); setSaved("已保存") }
|
|
623
|
+
else setSaved((data && data.error) || "保存失败")
|
|
624
|
+
} catch (e) {
|
|
625
|
+
setSaved(e.message || String(e))
|
|
626
|
+
} finally { setBusy(false) }
|
|
627
|
+
}
|
|
628
|
+
const setField = (key, value) => setCfg((prev) => ({ ...(prev || {}), [key]: value }))
|
|
629
|
+
// 显示位:先本地生效(不用等接口回来),再落盘
|
|
630
|
+
const placementOn = {
|
|
631
|
+
showInSettings: !!cfg && cfg.showInSettings !== false,
|
|
632
|
+
showInSidebar: !!cfg && cfg.showInSidebar !== false,
|
|
633
|
+
showInPluginsTab: !!cfg && cfg.showInPluginsTab === true,
|
|
634
|
+
}
|
|
635
|
+
const placementCount = (placementOn.showInSettings ? 1 : 0) + (placementOn.showInSidebar ? 1 : 0) + (placementOn.showInPluginsTab ? 1 : 0)
|
|
636
|
+
// 只剩一处开着时,这一处锁死:点了只会提示,不能让三处全关
|
|
637
|
+
const placementLocked = (key) => placementCount <= 1 && placementOn[key] === true
|
|
638
|
+
const savePlacement = async (key, value) => {
|
|
639
|
+
const next = { ...(cfg || {}), [key]: value }
|
|
640
|
+
const want = {
|
|
641
|
+
settings: next.showInSettings !== false,
|
|
642
|
+
sidebar: next.showInSidebar !== false,
|
|
643
|
+
pluginsTab: next.showInPluginsTab === true,
|
|
644
|
+
}
|
|
645
|
+
if (!want.settings && !want.sidebar && !want.pluginsTab) { setSaved("三处至少留一处,最后剩的那个不能关"); return }
|
|
646
|
+
setCfg(next)
|
|
647
|
+
setPlacement(want)
|
|
648
|
+
setBusy(true)
|
|
649
|
+
try {
|
|
650
|
+
const data = await api("/settings", { patch: { [key]: value } })
|
|
651
|
+
if (data && data.ok) { setCfg(data.config); setSaved("已保存") } else setSaved((data && data.error) || "保存失败")
|
|
652
|
+
} catch (e) {
|
|
653
|
+
setSaved(e.message || String(e))
|
|
654
|
+
} finally { setBusy(false) }
|
|
655
|
+
}
|
|
656
|
+
if (!cfg) return h("div", { style: hint }, "设置读取中…")
|
|
657
|
+
|
|
658
|
+
const textList = (key) => (Array.isArray(cfg[key]) ? cfg[key].join("\n") : "")
|
|
659
|
+
|
|
660
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
661
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
662
|
+
h("div", { style: strong }, "扫描与安装策略"),
|
|
663
|
+
h("div", { style: row },
|
|
664
|
+
h(ForcedSwitch, { label: "打包前扫描(强制)", onNag: () => fireScanNag("你想干什么") }),
|
|
665
|
+
h(Switch, { checked: cfg.scanBeforeInstall !== false, label: "安装前扫描", onChange: (v) => { setField("scanBeforeInstall", v); patch({ scanBeforeInstall: v }) } }),
|
|
666
|
+
h(Switch, { checked: cfg.blockHighRisk !== false, label: "高风险直接拒绝", onChange: (v) => { setField("blockHighRisk", v); patch({ blockHighRisk: v }) } }),
|
|
667
|
+
h(Switch, { checked: cfg.applyPackedConfig !== false, label: "默认回填配置", onChange: (v) => { setField("applyPackedConfig", v); patch({ applyPackedConfig: v }) } }),
|
|
668
|
+
h(Switch, { checked: cfg.enableOnInstall === true, label: "装完直接启用(默认关)", onChange: (v) => { setField("enableOnInstall", v); patch({ enableOnInstall: v }) } })),
|
|
669
|
+
h(NagText, { text: scanNag }),
|
|
670
|
+
h("div", { style: hint }, "扫描只看代码与文本,不执行任何东西;命中原文不会落盘,也不进日志。"),
|
|
671
|
+
h("div", { style: row },
|
|
672
|
+
h("span", { style: label }, "体积上限(MB)"),
|
|
673
|
+
h("input", { style: { ...input, width: "90px" }, type: "number", min: "1", value: Math.round((cfg.maxPackBytes || 0) / 1048576), onChange: (e) => setField("maxPackBytes", Number(e.target.value) * 1048576) }),
|
|
674
|
+
h("button", { style: btn, disabled: busy, onClick: () => patch({ maxPackBytes: cfg.maxPackBytes, maxDownloadBytes: cfg.maxDownloadBytes, maxFileBytes: cfg.maxFileBytes, licenseAllow: cfg.licenseAllow, registries: cfg.registries, allowHosts: cfg.allowHosts }) }, "保存数值"),
|
|
675
|
+
saved ? h("span", { style: hint }, saved) : null)),
|
|
676
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
677
|
+
h("div", { style: strong }, "信任清单"),
|
|
678
|
+
h("div", { style: hint }, "允许的许可证(一行一个,例如 MIT):"),
|
|
679
|
+
h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("licenseAllow"), onChange: (e) => setField("licenseAllow", e.target.value.split("\n")) }),
|
|
680
|
+
h("div", { style: hint }, "允许的下载域名(一行一个,只走 https):"),
|
|
681
|
+
h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("allowHosts"), onChange: (e) => setField("allowHosts", e.target.value.split("\n")) }),
|
|
682
|
+
h("div", { style: hint }, "npm 源(按顺序回退):"),
|
|
683
|
+
h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("registries"), onChange: (e) => setField("registries", e.target.value.split("\n")) }),
|
|
684
|
+
h("div", { style: row },
|
|
685
|
+
h("button", { style: btn, disabled: busy, onClick: () => patch({ licenseAllow: cfg.licenseAllow.filter(Boolean), allowHosts: cfg.allowHosts.filter(Boolean), registries: cfg.registries.filter(Boolean) }) }, "保存清单"))),
|
|
686
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
687
|
+
h("div", { style: strong }, "位置"),
|
|
688
|
+
h("div", { style: mono }, "profile:" + ((props.status && props.status.paths && props.status.paths.profile) || "?")),
|
|
689
|
+
h("div", { style: mono }, "整合包:" + ((props.status && props.status.paths && props.status.paths.packs) || "?")),
|
|
690
|
+
h("div", { style: mono }, "缓存与暂存:" + ((props.status && props.status.paths && props.status.paths.vendor) || "?")),
|
|
691
|
+
h("div", { style: mono }, "卸载临时文件:删掉 vendor 目录即可,装好的插件不受影响。")),
|
|
692
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px" } },
|
|
693
|
+
h("div", { style: strong }, "最近记录"),
|
|
694
|
+
history.length === 0 ? h("div", { style: hint }, "还没有记录。") : history.map((item, i) => h("div", { key: i, style: { ...mono, borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "4px" } },
|
|
695
|
+
"[" + (item.kind || "?") + "] " + (item.name || item.pack || "") + " · " + when(item.at) + (item.size ? " · " + bytes(item.size) : "") + (item.ok === false ? " · 失败" : "")))),
|
|
696
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
697
|
+
h("div", { style: strong }, "显示位置"),
|
|
698
|
+
h("div", { style: hint }, "三处互相独立,一点就生效,不用重启。关掉只是不挂载入口,功能与接口都还在。至少留一处:只剩一个时,那个开关会变灰、点不动。"),
|
|
699
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } },
|
|
700
|
+
h(Switch, { checked: cfg.showInSettings !== false, disabled: placementLocked("showInSettings"), label: "在设置里显示(插件设置页内一栏「整合包」)" + (placementLocked("showInSettings") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSettings", v) }),
|
|
701
|
+
h(Switch, { checked: cfg.showInSidebar !== false, disabled: placementLocked("showInSidebar"), label: "在侧边栏显示(左侧栏「整合包」入口)" + (placementLocked("showInSidebar") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSidebar", v) }),
|
|
702
|
+
h(Switch, { checked: cfg.showInPluginsTab === true, disabled: placementLocked("showInPluginsTab"), label: "在插件页内显示(与插件市场同一位置,单开一栏「整合包」)" + (placementLocked("showInPluginsTab") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInPluginsTab", v) })),
|
|
703
|
+
saved ? h("span", { style: hint }, saved) : null),
|
|
704
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
705
|
+
h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
|
|
706
|
+
h("div", { style: hint }, (() => {
|
|
707
|
+
const c = props.status && props.status.catalog
|
|
708
|
+
if (!c || !c.present) return "本地还没有目录索引;要按分类找插件、要搜索时,先在这里或打包页建一次。"
|
|
709
|
+
return "本地索引:" + c.count + " 条 · 来源 " + (c.sourceLabel || c.source || "?") + " · 建于 " + when(c.builtAt) + (c.stale ? "(偏旧了,建议更新)" : "")
|
|
710
|
+
})()),
|
|
711
|
+
h("div", { style: row },
|
|
712
|
+
h("span", { style: label }, "每页条数"),
|
|
713
|
+
h("input", { style: { ...input, width: "78px" }, type: "number", min: "5", max: "100", value: cfg.catalogPageSize || 20, onChange: (e) => setField("catalogPageSize", Number(e.target.value)) }),
|
|
714
|
+
h("span", { style: label }, "自动更新(小时)"),
|
|
715
|
+
h("input", { style: { ...input, width: "78px" }, type: "number", min: "1", max: "168", value: cfg.catalogRefreshHours || 24, onChange: (e) => setField("catalogRefreshHours", Number(e.target.value)) }),
|
|
716
|
+
h("button", { style: btn, disabled: busy, onClick: () => patch({ catalogPageSize: cfg.catalogPageSize, catalogRefreshHours: cfg.catalogRefreshHours }) }, "保存目录设置")),
|
|
717
|
+
h("div", { style: hint }, "目录就是插件市场自己发布的那份 dsh-plugin-catalog:CDN 优先,失败退回 npm 包。分类与词条都照它来,本插件不另造一套。"))
|
|
718
|
+
)
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function Home(props) {
|
|
722
|
+
const [tab, setTab] = useState("pack")
|
|
723
|
+
const status = props.status
|
|
724
|
+
const tabs = [
|
|
725
|
+
["pack", "打包"],
|
|
726
|
+
["install", "安装 / 导入"],
|
|
727
|
+
["settings", "设置与记录"],
|
|
728
|
+
]
|
|
729
|
+
const tabBtn = (key, text) => h("button", {
|
|
730
|
+
key,
|
|
731
|
+
onClick: () => setTab(key),
|
|
732
|
+
style: {
|
|
733
|
+
...btn,
|
|
734
|
+
borderColor: tab === key ? "transparent" : "var(--dsw-alias-border-l2)",
|
|
735
|
+
background: tab === key ? "var(--dsw-alias-fill-primary, #3b6cf6)" : "transparent",
|
|
736
|
+
color: tab === key ? "#fff" : "var(--dsw-alias-label-primary)",
|
|
737
|
+
},
|
|
738
|
+
}, text)
|
|
739
|
+
|
|
740
|
+
return h("div", { style: { height: "100%", overflow: "auto", boxSizing: "border-box", padding: "22px 26px 44px", color: "var(--dsw-alias-label-primary)" } },
|
|
741
|
+
h("div", { style: { maxWidth: "1020px", margin: "0 auto", display: "flex", flexDirection: "column", gap: "14px" } },
|
|
742
|
+
h("div", { style: { display: "flex", alignItems: "baseline", gap: "10px", flexWrap: "wrap" } },
|
|
743
|
+
h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
|
|
744
|
+
h("span", { style: hint }, "把多个插件打成一个 .dshpack:完整版自带本体,轻量版联网取包")),
|
|
745
|
+
h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)),
|
|
746
|
+
h("span", { style: { ...hint, marginLeft: "auto" } },
|
|
747
|
+
status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")),
|
|
748
|
+
tab === "pack" ? h(PackPanel, { status }) : null,
|
|
749
|
+
tab === "install" ? h(InstallPanel, { status }) : null,
|
|
750
|
+
tab === "settings" ? h(SettingsPanel, { status }) : null,
|
|
751
|
+
h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。"))
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function Icon(props) {
|
|
756
|
+
const size = (props && props.size) || 16
|
|
757
|
+
return h("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
|
|
758
|
+
h("path", { d: "M2.2 5.2 8 2.3l5.8 2.9v5.6L8 13.7l-5.8-2.9z" }),
|
|
759
|
+
h("path", { d: "M2.2 5.2 8 8.1l5.8-2.9M8 8.1v5.6" }))
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** 用一个小组件包住面板,进入时拉一次状态,之后交给子面板。 */
|
|
763
|
+
function Page(props) {
|
|
764
|
+
const [status, setStatus] = useState(null)
|
|
765
|
+
const [error, setError] = useState("")
|
|
766
|
+
const reload = useCallback(async () => {
|
|
767
|
+
try {
|
|
768
|
+
const data = await api("/status")
|
|
769
|
+
if (data && data.ok) {
|
|
770
|
+
setStatus(data)
|
|
771
|
+
setError("")
|
|
772
|
+
if (data.placements) setPlacement(data.placements)
|
|
773
|
+
} else setError((data && data.error) || "读取状态失败")
|
|
774
|
+
} catch (e) { setError(String((e && e.message) || e)) }
|
|
775
|
+
}, [])
|
|
776
|
+
useEffect(() => { reload() }, [reload])
|
|
777
|
+
if (error) return h("div", { style: { padding: "24px", color: "#ff6b6b", fontSize: "13px" } }, "整合包没起来:" + error)
|
|
778
|
+
if (!status) return h("div", { style: { padding: "24px", color: "var(--dsw-alias-label-tertiary)", fontSize: "13px" } }, "整合包:读取环境…")
|
|
779
|
+
return h(Home, { status, surface: (props && props.surface) || "sidebar" })
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const inject = ["slots"]
|
|
783
|
+
|
|
784
|
+
// 三处显示位各自注册什么。开关一翻就整组挂上 / 整组撤掉,不动别的插件。
|
|
785
|
+
const PLACEMENT_MOUNTS = {
|
|
786
|
+
settings: () => [
|
|
787
|
+
{ slot: "settings.section", spec: { name: "settings.section", id: "dsh-modpack-kit", order: 45, label: () => "整合包" }, Comp: () => h(Page, { surface: "settings" }) },
|
|
788
|
+
{ slot: "settings.plugins.tab", spec: { name: "settings.plugins.tab", id: "dsh-modpack-kit", order: 70, label: () => "整合包" }, Comp: () => h(Page, { surface: "plugins" }) },
|
|
789
|
+
],
|
|
790
|
+
pluginsTab: () => [
|
|
791
|
+
{ slot: "plugins.tab", spec: { name: "plugins.tab", id: "dsh-modpack-kit", order: 1, label: () => "整合包" }, Comp: () => h(Page, { surface: "plugins" }) },
|
|
792
|
+
],
|
|
793
|
+
sidebar: () => [
|
|
794
|
+
{ slot: "sidebar.panellist", spec: { name: "sidebar.panellist", id: "dsh-modpack-kit", order: 60, label: () => "整合包" }, Comp: Icon },
|
|
795
|
+
{ slot: "main", spec: { name: "main", key: "dsh-modpack-kit" }, Comp: () => h(Page, { surface: "sidebar" }) },
|
|
796
|
+
],
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function apply(ctx) {
|
|
800
|
+
const mounted = new Map()
|
|
801
|
+
const mount = (group, item) => {
|
|
802
|
+
const key = group + ":" + item.slot
|
|
803
|
+
if (mounted.has(key)) return
|
|
804
|
+
try {
|
|
805
|
+
const off = ctx.slots.inject(item.slot, () => ctx.slots.register(item.spec, item.Comp))
|
|
806
|
+
mounted.set(key, typeof off === "function" ? off : () => {})
|
|
807
|
+
} catch (e) {
|
|
808
|
+
// 某个宿主版本没有这个槽位时跳过,别的显示位照常
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
const unmount = (key) => {
|
|
812
|
+
const off = mounted.get(key)
|
|
813
|
+
if (!off) return
|
|
814
|
+
mounted.delete(key)
|
|
815
|
+
try { off() } catch {}
|
|
816
|
+
}
|
|
817
|
+
const sync = (value) => {
|
|
818
|
+
const want = normalizePlacement(value)
|
|
819
|
+
for (const group of Object.keys(PLACEMENT_MOUNTS)) {
|
|
820
|
+
const items = PLACEMENT_MOUNTS[group]()
|
|
821
|
+
if (want[group]) for (const item of items) mount(group, item)
|
|
822
|
+
else for (const item of items) unmount(group + ":" + item.slot)
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
ctx.effect(() => {
|
|
826
|
+
const unsubscribe = subscribePlacement(sync)
|
|
827
|
+
sync(placement.value)
|
|
828
|
+
return () => { unsubscribe(); for (const key of [...mounted.keys()]) unmount(key) }
|
|
829
|
+
}, "dsh-modpack-kit: 三处显示位")
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
exports.apply = apply
|
|
833
|
+
exports.inject = inject
|
|
834
|
+
exports.Page = Page
|
|
835
|
+
exports.Home = Home
|
|
836
|
+
exports.Icon = Icon
|
|
837
|
+
|
|
838
|
+
return module.exports
|
|
839
|
+
},
|
|
840
|
+
})
|