dsh-modpack-kit 0.2.2 → 0.2.4
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.md +119 -15
- package/assets/install-stub.mjs +21 -3
- package/client.js +1484 -30
- package/docs/CODE-MAP.md +431 -0
- package/docs/DETAIL.md +87 -4
- package/docs/MARKET.txt +19 -0
- package/index.js +743 -10
- package/lib/community.mjs +66 -0
- package/lib/compat.mjs +12 -11
- package/lib/github.mjs +289 -0
- package/lib/groups.mjs +25 -11
- package/lib/install.mjs +25 -5
- package/lib/manifest.mjs +3 -1
- package/lib/market-catalog.mjs +11 -5
- package/lib/modpack-catalog.mjs +382 -0
- package/lib/net.mjs +4 -3
- package/lib/pack.mjs +20 -14
- package/lib/profile.mjs +5 -2
- package/lib/repack.mjs +57 -0
- package/lib/store.mjs +6 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-modpack —— 客户端半边:左侧栏「整合包」。
|
|
2
|
+
* dsh-modpack-kit —— 客户端半边:左侧栏「整合包」。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 改之前先看 docs/CODE-MAP.md(功能 → 符号 → grep 示例)。
|
|
5
|
+
*
|
|
6
|
+
* 四个页签:打包(挑插件、策略三选一、检测报告)、安装 / 导入(链接/本机包、预览、落地)、
|
|
7
|
+
* 社区资源(浏览别人传的整合包,下载后交回安装页)、设置与记录(显示位置、市场、目录、历史)。
|
|
8
|
+
* 数据全部来自 /dsh-modpack-kit/api/*(同源 fetch),与 host 端共用同一份状态;这里不碰文件,也不直接发网络请求(市场 AI 搜索除外,它转发给插件市场)。
|
|
7
9
|
*
|
|
8
10
|
* 制作通告:本文件在 DeepSeek Harness(DSH)会话中由 AI 助手与作者 Vesna-Strivozha-cn 协作产出。
|
|
9
11
|
*/
|
|
@@ -35,9 +37,10 @@ window.__ModuleLoader__.load({
|
|
|
35
37
|
const LEVEL_COLOR = { high: "#ff6b6b", error: "#ff6b6b", medium: "#ffb020", warn: "#ffb020", low: "#8a8f98", info: "#8a8f98" }
|
|
36
38
|
const FORMAT_TEXT = { full: "完整版(含插件本体)", lite: "轻量版(联网取包)", hybrid: "混合包(联网取包 + 配置)" }
|
|
37
39
|
// 三种打包策略的介绍:服务端 /pack/plan 会给可用性与不可用原因,这里只做兜底展示
|
|
40
|
+
// ===== [区块] 打包策略与常量:STRATEGY_INFO =====
|
|
38
41
|
const STRATEGY_INFO = [
|
|
39
42
|
{ id: "full", title: "完整包(懒人包)", online: false, note: "插件本体一起装进包,不联网也能装。有网时按市场版本装,装完依赖是 ^版本,插件市场认成市场版;离线才退回包内副本(显示本地安装)。可以带自定义配置与数据。" },
|
|
40
|
-
{ id: "lite", title: "
|
|
43
|
+
{ id: "lite", title: "轻量包(轻量包)", online: true, note: "只记 名字@版本,体积最小。安装时必须联网从市场取包,不带自定义配置与数据,插件市场按版本认成市场版。" },
|
|
41
44
|
{ id: "hybrid", title: "混合包(轻量为主 + 必要的完整)", online: true, note: "能按版本装的就只记 名字@版本(安装时联网取包);没有确定版本、或者要带走本机改动的插件,连本体一起打进来(这部分安装时不用联网)。配置/数据/补丁片段照样带。" },
|
|
42
45
|
]
|
|
43
46
|
// 分类以插件市场为准:id 与市场目录一致,中文名由 host 从市场目录里带回来。
|
|
@@ -66,6 +69,54 @@ window.__ModuleLoader__.load({
|
|
|
66
69
|
return () => placement.subs.delete(fn)
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
// 「社区资源」这一栏开不开:设置里一关,标签要立刻消失,不能等重新拉状态。
|
|
73
|
+
// host 端的 /status 才是权威值,界面上先乐观一次,下次拉状态再对齐。
|
|
74
|
+
const marketVis = { value: true, subs: new Set() }
|
|
75
|
+
function readMarketVisible() { return marketVis.value !== false }
|
|
76
|
+
function setMarketVisible(on) {
|
|
77
|
+
const next = on !== false
|
|
78
|
+
const same = marketVis.value === next
|
|
79
|
+
marketVis.value = next
|
|
80
|
+
if (same) return
|
|
81
|
+
for (const fn of [...marketVis.subs]) { try { fn(next) } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
|
|
82
|
+
}
|
|
83
|
+
function subscribeMarketVisible(fn) {
|
|
84
|
+
marketVis.subs.add(fn)
|
|
85
|
+
return () => marketVis.subs.delete(fn)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 社区资源这一层切页签时会整个卸载:搜索框里的字、分类、页码、已经读到的列表、
|
|
89
|
+
// 打开着的整合包详情,都要留着——回来不该重搜一遍。存在模块里,退出程序前都在。
|
|
90
|
+
// 详情页里每个插件的介绍取自插件市场目录(dsh-plugin-catalog),按名字缓存一份,
|
|
91
|
+
// 同一个插件反复打开详情不必再问一遍。
|
|
92
|
+
const pluginDescCache = new Map()
|
|
93
|
+
function hasPluginDesc(name) {
|
|
94
|
+
return pluginDescCache.has(name)
|
|
95
|
+
}
|
|
96
|
+
function cachedPluginDesc(name) {
|
|
97
|
+
const hit = pluginDescCache.get(name)
|
|
98
|
+
return hit && hit.description ? hit.description : ""
|
|
99
|
+
}
|
|
100
|
+
const marketUi = { value: { kind: "modpack", pack: null, plugin: null } }
|
|
101
|
+
function readMarketUi() {
|
|
102
|
+
return marketUi.value || { kind: "modpack", pack: null, plugin: null }
|
|
103
|
+
}
|
|
104
|
+
function saveMarketUi(slice, next) {
|
|
105
|
+
const cur = readMarketUi()
|
|
106
|
+
marketUi.value = { ...cur, [slice]: { ...(cur[slice] || {}), ...next } }
|
|
107
|
+
}
|
|
108
|
+
function saveMarketKind(kind) {
|
|
109
|
+
marketUi.value = { ...readMarketUi(), kind: kind === "plugin" ? "plugin" : "modpack" }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 最近一次确认过的配置:设置页来回切时会重新挂载,只读 props.status 会退回旧值
|
|
113
|
+
// (比如关掉「社区资源」再切回来,开关又亮着)。这里存一份,挂载时并上去。
|
|
114
|
+
const liveCfg = { value: null }
|
|
115
|
+
function mergeLiveConfig(next) {
|
|
116
|
+
if (!next || typeof next !== "object") return
|
|
117
|
+
liveCfg.value = { ...(liveCfg.value || {}), ...next }
|
|
118
|
+
}
|
|
119
|
+
|
|
69
120
|
// 打包结果(含下载按钮)放在模块里:切页签、关掉面板都不丢,留到退出程序为止。
|
|
70
121
|
const packStore = { value: null, subs: new Set() }
|
|
71
122
|
function readPackValue() {
|
|
@@ -92,6 +143,17 @@ window.__ModuleLoader__.load({
|
|
|
92
143
|
return () => packStore.subs.delete(fn)
|
|
93
144
|
}
|
|
94
145
|
|
|
146
|
+
// 页面级快照:离开插件页(切到别的页签、被卸载)再回来,原来选到哪儿、填了什么都在。
|
|
147
|
+
// 只有上传用的 GitHub token 例外——那份按规矩每次重进都要重新填,见 UploadPanel 的卸载清理。
|
|
148
|
+
const pageUi = { tab: "pack", pack: { query: "", category: "all" }, install: { source: null, options: null } }
|
|
149
|
+
function readPageUi() {
|
|
150
|
+
return pageUi
|
|
151
|
+
}
|
|
152
|
+
function setPageUi(slice, value) {
|
|
153
|
+
pageUi[slice] = value
|
|
154
|
+
}
|
|
155
|
+
const PAGE_TABS = ["pack", "install", "settings", "market"]
|
|
156
|
+
|
|
95
157
|
// 插件市场的 AI 搜索:市场新版本用 POST /dsh-market/ai-search,让「你在 DSH 里配的模型」从目录里挑插件。
|
|
96
158
|
// 我们不重复实现模型调用:旧版市场(或没装)没有这条路由,界面自动退回纯关键词搜索。
|
|
97
159
|
const AI_SEARCH_KEY = "dsh-modpack-kit:ai-search"
|
|
@@ -188,6 +250,10 @@ window.__ModuleLoader__.load({
|
|
|
188
250
|
}
|
|
189
251
|
let data = null
|
|
190
252
|
try { data = await res.json() } catch {
|
|
253
|
+
// 宿主还跑着旧代码时,新接口会返回 404/405 且不是 JSON:把话说清楚,别只丢一句技术错误
|
|
254
|
+
if (res.status === 404 || res.status === 405) {
|
|
255
|
+
throw new Error("这个接口在当前运行的 DSH 里还没加载(HTTP " + res.status + "):重启一次 DSH 后生效")
|
|
256
|
+
}
|
|
191
257
|
throw new Error("服务端返回了非 JSON(HTTP " + res.status + ")")
|
|
192
258
|
}
|
|
193
259
|
if (!res.ok) {
|
|
@@ -370,6 +436,7 @@ window.__ModuleLoader__.load({
|
|
|
370
436
|
|
|
371
437
|
// 一整块可以折叠的区域:标题行常驻,点标题或「展开/收起」都行。
|
|
372
438
|
// 默认收起,只有真有问题(高危 / 阻断)才默认摊开。
|
|
439
|
+
// ===== [区块] 通用折叠容器:FoldBox =====
|
|
373
440
|
function FoldBox(props) {
|
|
374
441
|
const [open, setOpen] = useState(props.defaultOpen === true)
|
|
375
442
|
const summary = Array.isArray(props.summary) ? props.summary : [props.summary]
|
|
@@ -386,6 +453,7 @@ window.__ModuleLoader__.load({
|
|
|
386
453
|
open ? props.children : (props.collapsedNote ? h("div", { style: hint }, props.collapsedNote) : null))
|
|
387
454
|
}
|
|
388
455
|
|
|
456
|
+
// ===== [区块] 安全检测报告(可折叠):ScanReport =====
|
|
389
457
|
function ScanReport(props) {
|
|
390
458
|
const scan = props.scan
|
|
391
459
|
const counts = (scan && scan.counts) || { high: 0, medium: 0, low: 0 }
|
|
@@ -429,6 +497,7 @@ window.__ModuleLoader__.load({
|
|
|
429
497
|
h("div", { style: hint }, props.footNote || "命中内容只在内存里比对,报告只保留类型、位置与掩码,原文不落盘。"))
|
|
430
498
|
}
|
|
431
499
|
|
|
500
|
+
// ===== [区块] 兼容性列表(可折叠):CompatList =====
|
|
432
501
|
function CompatList(props) {
|
|
433
502
|
const compat = props.compat
|
|
434
503
|
if (!compat) return null
|
|
@@ -447,7 +516,7 @@ window.__ModuleLoader__.load({
|
|
|
447
516
|
f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
|
|
448
517
|
}
|
|
449
518
|
|
|
450
|
-
const JOB_KIND_LABEL = { pack: "打包", install: "安装" }
|
|
519
|
+
const JOB_KIND_LABEL = { pack: "打包", install: "安装", upload: "上传" }
|
|
451
520
|
const JOB_STATUS_TEXT = { running: "进行中", paused: "等决定", acked: "已确认", done: "完成", failed: "失败", cancelled: "已取消" }
|
|
452
521
|
|
|
453
522
|
function useJobs(intervalMs) {
|
|
@@ -556,6 +625,7 @@ window.__ModuleLoader__.load({
|
|
|
556
625
|
return { width, height }
|
|
557
626
|
}
|
|
558
627
|
|
|
628
|
+
// ===== [区块] 悬浮进度窗(拖动 / 召回 / 终止):JobDock =====
|
|
559
629
|
function JobDock(props) {
|
|
560
630
|
const given = Array.isArray(props.jobs) ? props.jobs : []
|
|
561
631
|
// 「清空进程」之后,就算服务端还残留一条,也在界面上立刻拿掉
|
|
@@ -822,11 +892,20 @@ window.__ModuleLoader__.load({
|
|
|
822
892
|
onClick: () => { if (typeof props.onOpenResult === "function") props.onOpenResult(job) },
|
|
823
893
|
}, "下载安装包")
|
|
824
894
|
: null,
|
|
895
|
+
job.kind === "upload" && job.status === "done" && job.data && job.data.pr && job.data.pr.url
|
|
896
|
+
? h("a", {
|
|
897
|
+
style: { ...chipBtn, color: "#4C7DF0", borderColor: "#4C7DF0", textDecoration: "none" },
|
|
898
|
+
href: job.data.pr.url,
|
|
899
|
+
target: "_blank",
|
|
900
|
+
rel: "noreferrer",
|
|
901
|
+
title: "在 GitHub 上打开这个 PR",
|
|
902
|
+
}, "打开 PR #" + (job.data.pr.number || ""))
|
|
903
|
+
: null,
|
|
825
904
|
job.canAck
|
|
826
905
|
? h("button", { style: { ...chipBtn, color: "#ff6b6b", borderColor: "#ff6b6b" }, title: "忽略风险,在同一个任务里接着跑完", onClick: () => ack(job.id) }, "我知道在干什么")
|
|
827
906
|
: null,
|
|
828
907
|
job.status !== "running" && job.status !== "paused"
|
|
829
|
-
? h("button", { style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" }, title: "从列表里删掉这条记录", onClick: () => dismiss(job.id) }, "删除该进程")
|
|
908
|
+
? h("button", { style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" }, title: "从列表里删掉这条记录", onClick: () => dismiss(job.id) }, job.status === "failed" ? "我已知晓" : "删除该进程")
|
|
830
909
|
: null,
|
|
831
910
|
job.error && job.status !== "paused" ? h("span", { style: { ...hint, color: "#ff6b6b" } }, job.error) : null)))))
|
|
832
911
|
: h("div", { style: { ...hint, fontSize: "10.5px" } },
|
|
@@ -839,6 +918,21 @@ window.__ModuleLoader__.load({
|
|
|
839
918
|
}
|
|
840
919
|
|
|
841
920
|
// —— 打包 ——
|
|
921
|
+
// ===== [区块] 页签一:打包:PackPanel =====
|
|
922
|
+
// 分类胶囊行:打包页与「社区资源 → 插件」共用,省得两套样式各写一遍。
|
|
923
|
+
function CategoryChips(props) {
|
|
924
|
+
const chips = props.chips || []
|
|
925
|
+
if (chips.length === 0) return null
|
|
926
|
+
return h("div", { style: { ...row, rowGap: "4px", maxHeight: "78px", overflow: "auto" } },
|
|
927
|
+
chips.map((c) => h("button", {
|
|
928
|
+
key: "chip-" + c.id,
|
|
929
|
+
type: "button",
|
|
930
|
+
style: props.value === c.id ? chipOn : chipBtn,
|
|
931
|
+
onClick: () => props.onChange(c.id),
|
|
932
|
+
title: "只看「" + c.label + "」" + (c.count ? ",市场内 " + c.count + " 个" : ""),
|
|
933
|
+
}, c.label + (c.count ? " " + c.count : ""))))
|
|
934
|
+
}
|
|
935
|
+
|
|
842
936
|
function PackPanel(props) {
|
|
843
937
|
const status = props.status
|
|
844
938
|
const jobs = Array.isArray(props.jobs) ? props.jobs : []
|
|
@@ -1198,7 +1292,7 @@ window.__ModuleLoader__.load({
|
|
|
1198
1292
|
// 停在风险点的任务:按插件分栏列出命中项,确认/删除都在这里做
|
|
1199
1293
|
const pausedRiskNodes = []
|
|
1200
1294
|
if (pausedJobs.length > 0) {
|
|
1201
|
-
pausedRiskNodes.push(h("div", { key: "title", style: { ...strong, color: "#ff6b6b" } },
|
|
1295
|
+
pausedRiskNodes.push(h("div", { key: "title", style: { ...strong, color: "#ff6b6b" } }, `打包停在风险点(${pausedJobs.length} 个任务)`))
|
|
1202
1296
|
pausedRiskNodes.push(h("div", { key: "hint", style: hint }, "下面是每个插件自己的命中项。确认后原任务从这个检测点接着跑完,不再重复检测。"))
|
|
1203
1297
|
for (const job of pausedJobs) {
|
|
1204
1298
|
const groupNodes = (job.risk.groups || []).map((group, index) => {
|
|
@@ -1342,7 +1436,7 @@ window.__ModuleLoader__.load({
|
|
|
1342
1436
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
|
|
1343
1437
|
h(Notice, null,
|
|
1344
1438
|
h("b", null, "打包:将所选插件封装为一个 .dshpack 文件"),
|
|
1345
|
-
"
|
|
1439
|
+
" 三种策略:完整包自带插件本体、不联网也能装;轻量包只记版本、体积最小;混合包带版本与配置片段、体积接近轻量包。完整包与混合包在安装前均不允许修改 profile 内容。",
|
|
1346
1440
|
status && status.market && status.market.installed
|
|
1347
1441
|
? h("div", { style: { ...hint, marginTop: "6px" } }, "已检测到插件市场 v" + status.market.version + ":本插件与其共用目录源与安装链路,但不依赖该插件,移除后打包与安装功能不受影响。")
|
|
1348
1442
|
: h("div", { style: { ...hint, marginTop: "6px" } }, "未检测到插件市场,功能不受影响:打包、安装与检测均在本地完成。建议先安装 dshmarket 以获得分类、搜索与「切换市场版」入口;未安装时,首次使用请点击「建立目录索引」。"),
|
|
@@ -1372,13 +1466,7 @@ window.__ModuleLoader__.load({
|
|
|
1372
1466
|
h("button", { style: btn, disabled: !!syncing, onClick: buildCatalog }, syncing || "建立目录索引(5~30 秒)"))
|
|
1373
1467
|
: null,
|
|
1374
1468
|
catalog.present && syncing ? h("div", { style: hint }, syncing) : null,
|
|
1375
|
-
catalog.present ? h(
|
|
1376
|
-
chips.map((c) => h("button", {
|
|
1377
|
-
key: c.id,
|
|
1378
|
-
style: category === c.id ? chipOn : chipBtn,
|
|
1379
|
-
onClick: () => setCategory(c.id),
|
|
1380
|
-
title: "只看「" + c.label + "」" + (c.count ? ",市场内 " + c.count + " 个" : ""),
|
|
1381
|
-
}, c.label + (c.count ? " " + c.count : "")))) : null,
|
|
1469
|
+
catalog.present ? h(CategoryChips, { chips, value: category, onChange: setCategory }) : null,
|
|
1382
1470
|
aiReady === false ? h("div", { style: hint }, "当前装的插件市场没有 AI 搜索(旧版本或未安装):这里只做关键词搜索。装新版 dshmarket 后开关会自动出现。") : null,
|
|
1383
1471
|
aiRun ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px", borderColor: aiRun.error ? "#ff6b6b" : "var(--dsw-alias-border-l2)" } },
|
|
1384
1472
|
h("div", { style: row },
|
|
@@ -1460,8 +1548,8 @@ window.__ModuleLoader__.load({
|
|
|
1460
1548
|
h("input", { style: { ...input, width: "100%" }, placeholder: "一句话描述(可空)", value: options.description, onChange: (e) => setOptions({ ...options, description: e.target.value }) }),
|
|
1461
1549
|
h(Switch, { checked: options.confirmLicense, label: "我确认所选插件的许可证允许再分发,或已获得作者授权", onChange: (v) => setOptions({ ...options, confirmLicense: v }) }),
|
|
1462
1550
|
h("div", { style: row },
|
|
1463
|
-
h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "start" || Boolean(currentBlocked), onClick: doPack }, busy === "start" ? "提交中…" : (currentBlocked ? "先换个可用的策略" :
|
|
1464
|
-
started ? h("span", { style: hint }, "已开始:" + started + "
|
|
1551
|
+
h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "start" || Boolean(currentBlocked), onClick: doPack }, busy === "start" ? "提交中…" : (currentBlocked ? "先换个可用的策略" : `打包 ${picked.length} 个插件`)),
|
|
1552
|
+
started ? h("span", { style: hint }, "已开始:" + started + "(进度在悬浮窗,可以接着选别的再打一个)") : null,
|
|
1465
1553
|
status ? h("span", { style: hint }, "DSH " + (status.dshVersion || "?") + " · profile " + status.profile) : null)),
|
|
1466
1554
|
pausedRiskNodes.length ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px", borderColor: "#d9534f" } }, pausedRiskNodes) : null,
|
|
1467
1555
|
error ? h(Notice, { tone: "bad" }, error) : null,
|
|
@@ -1484,7 +1572,7 @@ window.__ModuleLoader__.load({
|
|
|
1484
1572
|
result.manifest && result.manifest.plugins && result.manifest.plugins.length
|
|
1485
1573
|
? h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
|
|
1486
1574
|
result.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
|
|
1487
|
-
"· " + p.name + "@" + p.version + " " + (p.size ? bytes(p.size) : "") + ((p.mode === "local" || p.localEdits) ? " [本地改动]" : " [基础配置]") + (p.configIncluded ? " [含配置]" : ""))))
|
|
1575
|
+
"· " + p.name + (p.latest ? "@市场最新" : "@" + p.version) + " " + (p.size ? bytes(p.size) : "") + ((p.mode === "local" || p.localEdits) ? " [本地改动]" : " [基础配置]") + (p.configIncluded ? " [含配置]" : ""))))
|
|
1488
1576
|
: null,
|
|
1489
1577
|
result.compat ? h(CompatList, { compat: result.compat }) : null,
|
|
1490
1578
|
result.notes && result.notes.length ? h("div", { style: { ...hint, maxHeight: "110px", overflow: "auto" } }, result.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
|
|
@@ -1497,8 +1585,16 @@ window.__ModuleLoader__.load({
|
|
|
1497
1585
|
}
|
|
1498
1586
|
|
|
1499
1587
|
// —— 安装 / 导入 ——
|
|
1588
|
+
// ===== [区块] 页签二:安装 / 导入:InstallPanel =====
|
|
1589
|
+
// 安装页草稿:只活在内存里(刷新 / 重启即重置),离开插件页再回来不丢。
|
|
1590
|
+
const installDraft = { source: { kind: "url", url: "", file: "" }, options: null }
|
|
1591
|
+
function readInstallDraft() {
|
|
1592
|
+
return installDraft
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1500
1595
|
function InstallPanel(props) {
|
|
1501
|
-
const
|
|
1596
|
+
const installSaved = readInstallDraft()
|
|
1597
|
+
const [source, setSource] = useState(() => (installSaved.source ? { ...installSaved.source } : { kind: "url", url: "", file: "" }))
|
|
1502
1598
|
const [packs, setPacks] = useState([])
|
|
1503
1599
|
const [dirInput, setDirInput] = useState((props.status && props.status.paths && props.status.paths.packs) || "")
|
|
1504
1600
|
const [dirInfo, setDirInfo] = useState({ dir: (props.status && props.status.paths && props.status.paths.packs) || "", error: "" })
|
|
@@ -1506,7 +1602,9 @@ window.__ModuleLoader__.load({
|
|
|
1506
1602
|
const [busy, setBusy] = useState("")
|
|
1507
1603
|
const [error, setError] = useState("")
|
|
1508
1604
|
const [done, setDone] = useState(null)
|
|
1509
|
-
const [options, setOptions] = useState({ keepLocal: true, applyConfig: true, force: false, dryRun: false, preferMarket: !!((props.status && props.status.config && props.status.config.preferMarketOnInstall !== false)), enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) })
|
|
1605
|
+
const [options, setOptions] = useState(() => (installSaved.options ? { ...installSaved.options } : { keepLocal: true, applyConfig: true, force: false, dryRun: false, preferMarket: !!((props.status && props.status.config && props.status.config.preferMarketOnInstall !== false)), enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) }))
|
|
1606
|
+
useEffect(() => { installDraft.options = options }, [options])
|
|
1607
|
+
useEffect(() => { installDraft.source = source }, [source])
|
|
1510
1608
|
// 安装也走任务队列:进度直接显示在左下角那个窗里,这里留一份给页面内看
|
|
1511
1609
|
const [progress, setProgress] = useState(null)
|
|
1512
1610
|
const [deferred, setDeferred] = useState([])
|
|
@@ -1528,6 +1626,28 @@ window.__ModuleLoader__.load({
|
|
|
1528
1626
|
setError("")
|
|
1529
1627
|
}), [])
|
|
1530
1628
|
|
|
1629
|
+
// 从「社区资源」点「下载并安装」过来:包已经在后端取回、校验并换成 token,
|
|
1630
|
+
// 这里接住直接读一遍预览,后面的勾选、扫描、兼容提示走的是同一条安装流程。
|
|
1631
|
+
useEffect(() => subscribeInstallRequest((payload) => {
|
|
1632
|
+
if (!payload || !payload.token) return
|
|
1633
|
+
installRequest.value = null
|
|
1634
|
+
setSource({ kind: "token", token: payload.token, url: "", file: "" })
|
|
1635
|
+
// 下载时服务端会在 packs 目录留一份,列表顺手刷新一下就能在「已下载」里看到
|
|
1636
|
+
reloadPacks()
|
|
1637
|
+
setError("")
|
|
1638
|
+
setDone(null)
|
|
1639
|
+
setDeferred([])
|
|
1640
|
+
setAskReplace(false)
|
|
1641
|
+
setBusy("import")
|
|
1642
|
+
api("/inspect", { token: payload.token })
|
|
1643
|
+
.then((data) => {
|
|
1644
|
+
if (data && data.ok) setPreview(data)
|
|
1645
|
+
else { setPreview(null); setError((data && data.error) || "读取失败") }
|
|
1646
|
+
})
|
|
1647
|
+
.catch((e) => { setPreview(null); setError((e && e.message) || String(e)) })
|
|
1648
|
+
.finally(() => setBusy(""))
|
|
1649
|
+
}), [])
|
|
1650
|
+
|
|
1531
1651
|
const fileRef = useRef(null)
|
|
1532
1652
|
|
|
1533
1653
|
// 用「打开文件」的方式挑一个 .dshpack:字节直接读,不要求你写路径
|
|
@@ -1561,6 +1681,32 @@ window.__ModuleLoader__.load({
|
|
|
1561
1681
|
} finally { setBusy("") }
|
|
1562
1682
|
}
|
|
1563
1683
|
|
|
1684
|
+
// 已下载:社区资源里下过的包会留在插件自己的 packs 目录里。
|
|
1685
|
+
// 这里只做「读磁盘 + 交给同一条安装流程」,不碰网络。
|
|
1686
|
+
const pickDownloaded = async (item) => {
|
|
1687
|
+
if (!item || !item.path) return
|
|
1688
|
+
setBusy("import"); setError(""); setDone(null); setDeferred([]); setAskReplace(false)
|
|
1689
|
+
try {
|
|
1690
|
+
const data = await api("/inspect", { file: item.path })
|
|
1691
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "这个包读不了,可能在下载时被删掉了")
|
|
1692
|
+
setSource({ kind: "file", file: item.path, token: "", url: "" })
|
|
1693
|
+
setPreview(data)
|
|
1694
|
+
} catch (e) {
|
|
1695
|
+
setError((e && e.message) || String(e))
|
|
1696
|
+
} finally { setBusy("") }
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
const removeDownloaded = async (item) => {
|
|
1700
|
+
if (!item || !item.name) return
|
|
1701
|
+
try {
|
|
1702
|
+
const data = await api("/packs/remove", { name: item.name })
|
|
1703
|
+
if (data && Array.isArray(data.items)) setPacks(data.items)
|
|
1704
|
+
else await reloadPacks()
|
|
1705
|
+
} catch (e) {
|
|
1706
|
+
setError("删不掉:" + ((e && e.message) || e))
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1564
1710
|
// 原生目录选择器:拿到绝对路径就填进去并列出该目录的 .dshpack
|
|
1565
1711
|
const browseFolder = async () => {
|
|
1566
1712
|
if (typeof pickDirectoryHost !== "function") {
|
|
@@ -1597,7 +1743,7 @@ window.__ModuleLoader__.load({
|
|
|
1597
1743
|
const bodyFor = () => {
|
|
1598
1744
|
if (source.kind === "url") return { url: source.url.trim() }
|
|
1599
1745
|
if (source.kind === "token") return { token: source.token }
|
|
1600
|
-
return { file: source.file }
|
|
1746
|
+
return { file: source.file, sourcePackFile: source.file }
|
|
1601
1747
|
}
|
|
1602
1748
|
|
|
1603
1749
|
const inspect = async () => {
|
|
@@ -1738,6 +1884,19 @@ window.__ModuleLoader__.load({
|
|
|
1738
1884
|
item.fileName ? h("div", { style: { ...hint, fontSize: "10px" } }, item.fileName) : null))))
|
|
1739
1885
|
: null,
|
|
1740
1886
|
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
1887
|
+
// 已下载:社区资源里下载的包会留在插件自己的 packs 目录
|
|
1888
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px" } },
|
|
1889
|
+
h("div", { style: row },
|
|
1890
|
+
h("div", { style: strong }, "已下载的整合包"),
|
|
1891
|
+
h("span", { style: hint }, packs.length > 0 ? "共 " + packs.length + " 份 · " + (dirInfo.dir || "插件自己的 packs 目录") : "还没有")),
|
|
1892
|
+
packs.length === 0
|
|
1893
|
+
? h("div", { style: hint }, "在「社区资源」里点「下载并安装」,包会留一份在插件自己的 packs 目录;重启 DSH 之后也能从这里直接选。")
|
|
1894
|
+
: h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "170px", overflow: "auto" } },
|
|
1895
|
+
packs.map((p) => h("div", { key: p.path || p.name, style: row },
|
|
1896
|
+
h("span", { style: { ...label, flex: "1 1 auto" } }, p.name),
|
|
1897
|
+
h("span", { style: hint }, bytes(p.size) + " · " + when(p.mtime)),
|
|
1898
|
+
h("button", { style: btn, disabled: busy !== "", onClick: () => pickDownloaded(p) }, source.kind === "file" && source.file === p.path ? "当前选中" : "选择"),
|
|
1899
|
+
h("button", { style: { ...btn, color: "#ff6b6b" }, disabled: busy !== "", onClick: () => removeDownloaded(p) }, "删除"))))),
|
|
1741
1900
|
h("div", { style: row },
|
|
1742
1901
|
h("button", { style: source.kind === "url" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "url" }) }, "从链接读取"),
|
|
1743
1902
|
h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "从本机文件读取"),
|
|
@@ -1816,7 +1975,7 @@ window.__ModuleLoader__.load({
|
|
|
1816
1975
|
return h("div", { key: p.name, style: { display: "flex", gap: "8px", alignItems: "center", flexWrap: "wrap", padding: "4px 0", borderTop: "0.5px solid var(--dsw-alias-border-l2)" } },
|
|
1817
1976
|
h("input", { type: "checkbox", checked, onChange: () => setPickedNames((prev) => ({ ...prev, [p.name]: !checked })) }),
|
|
1818
1977
|
h("div", { style: { flex: "1 1 220px", minWidth: "170px" } },
|
|
1819
|
-
h("div", { style: label }, p.name, " ", h("span", { style: hint }, "@" + (p.version || "?"))),
|
|
1978
|
+
h("div", { style: label }, p.name, " ", h("span", { style: hint }, p.latest ? "@市场最新(装的时候按名字取)" : "@" + (p.version || "?"))),
|
|
1820
1979
|
h("div", { style: hint }, [p.localEdits ? "含本机修改" : "", p.configIncluded ? "有配置" : "", p.dataIncluded ? "有数据快照" : ""].filter(Boolean).join(" · ")),
|
|
1821
1980
|
row.problems.length ? h("div", { style: { ...hint, color: row.problems.some((f) => f.level === "error") ? "#ff6b6b" : "#ffb020" } },
|
|
1822
1981
|
row.problems.slice(0, 3).map((f) => "· " + f.message).join(";") + (row.problems.length > 3 ? "(还有 " + (row.problems.length - 3) + " 条)" : "")) : null),
|
|
@@ -1839,7 +1998,7 @@ window.__ModuleLoader__.load({
|
|
|
1839
1998
|
h("div", { style: hint }, "要保留本机版本就直接完成;要换成包内版本点下面这个(会覆盖本机那份)。"),
|
|
1840
1999
|
h("div", { style: row },
|
|
1841
2000
|
h("button", { style: btn, disabled: busy !== "", onClick: () => { setAskReplace(false) } }, "直接完成(保留本机版本)"),
|
|
1842
|
-
h("button", { style: btnPrimary, disabled: busy !== "", onClick: () => replaceDeferred(deferred.map((d) => d.name)) },
|
|
2001
|
+
h("button", { style: btnPrimary, disabled: busy !== "", onClick: () => replaceDeferred(deferred.map((d) => d.name)) }, `重新装一下这 ${deferred.length} 个(用包内版本)`)))
|
|
1843
2002
|
: null,
|
|
1844
2003
|
done ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1845
2004
|
h("div", { style: row },
|
|
@@ -1882,8 +2041,20 @@ window.__ModuleLoader__.load({
|
|
|
1882
2041
|
h("span", null, "如果这个插件省了时间,顺手点个 Star,能让更多人找到它。"))
|
|
1883
2042
|
}
|
|
1884
2043
|
|
|
2044
|
+
// ===== [区块] 页签四:设置与记录:SettingsPanel =====
|
|
1885
2045
|
function SettingsPanel(props) {
|
|
1886
|
-
const [cfg, setCfg] = useState(props.status
|
|
2046
|
+
const [cfg, setCfg] = useState(() => ({ ...((props.status && props.status.config) || {}), ...(liveCfg.value || {}) }))
|
|
2047
|
+
const packsDirLine = ((props.status || {}).paths || {}).packs || ""
|
|
2048
|
+
const [folderMsg, setFolderMsg] = useState("")
|
|
2049
|
+
const openPackFolder = async () => {
|
|
2050
|
+
try {
|
|
2051
|
+
const data = await api("/packs/open", {})
|
|
2052
|
+
if (data && data.ok) setFolderMsg("已打开:" + (data.dir || packsDirLine))
|
|
2053
|
+
else setFolderMsg((data && data.error) || "打不开")
|
|
2054
|
+
} catch (e) {
|
|
2055
|
+
setFolderMsg("打不开:" + ((e && e.message) || e))
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
1887
2058
|
const [saved, setSaved] = useState("")
|
|
1888
2059
|
const [busy, setBusy] = useState(false)
|
|
1889
2060
|
const [scanNag, fireScanNag] = useNag()
|
|
@@ -1912,7 +2083,13 @@ window.__ModuleLoader__.load({
|
|
|
1912
2083
|
setBusy(true); setSaved("")
|
|
1913
2084
|
try {
|
|
1914
2085
|
const data = await api("/settings", { patch: p })
|
|
1915
|
-
if (data && data.ok) {
|
|
2086
|
+
if (data && data.ok) {
|
|
2087
|
+
setCfg(data.config)
|
|
2088
|
+
mergeLiveConfig(data.config)
|
|
2089
|
+
// 「社区资源」这一栏的开关键在这里:一关,标签立刻消失,不用等重新拉状态
|
|
2090
|
+
if (Object.prototype.hasOwnProperty.call(p, "showModpackMarket")) setMarketVisible(data.config.showModpackMarket !== false)
|
|
2091
|
+
setSaved("已保存")
|
|
2092
|
+
}
|
|
1916
2093
|
else setSaved((data && data.error) || "保存失败")
|
|
1917
2094
|
} catch (e) {
|
|
1918
2095
|
setSaved(e.message || String(e))
|
|
@@ -2007,6 +2184,9 @@ window.__ModuleLoader__.load({
|
|
|
2007
2184
|
}, "保存数值"),
|
|
2008
2185
|
h("span", { style: hint }, "默认 256 MB,可填 16~4096"),
|
|
2009
2186
|
saved ? h("span", { style: hint }, saved) : null)),
|
|
2187
|
+
),
|
|
2188
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2189
|
+
h("div", { style: strong }, "网络与请求上限"),
|
|
2010
2190
|
h("div", { style: row },
|
|
2011
2191
|
h("span", { style: label }, "网络超时(秒)"),
|
|
2012
2192
|
h("input", { style: { ...input, width: "70px" }, type: "number", min: "5", max: "120", value: String(cfg.netTimeoutSeconds || 20), onChange: (e) => setField("netTimeoutSeconds", Number(e.target.value)) }),
|
|
@@ -2083,6 +2263,31 @@ window.__ModuleLoader__.load({
|
|
|
2083
2263
|
h("div", { style: hint }, "只关市场自己的,不动整合包:改的是它存在 .dsh-market/state.json 里的 sidebarEntry,不动它的安装,也不动整合包的入口。"),
|
|
2084
2264
|
marketSidebarMsg ? h("div", { style: hint }, marketSidebarMsg) : null,
|
|
2085
2265
|
saved ? h("span", { style: hint }, saved) : null),
|
|
2266
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2267
|
+
h("div", { style: strong }, "社区资源(附属功能)"),
|
|
2268
|
+
h("div", { style: hint }, "这是「整合包」的附属小插件:自己一层代码(community/)、自己一套接口;关掉只是把它的接口和这一栏一起下线,打包/安装/进度窗都不受影响。"),
|
|
2269
|
+
h(Switch, {
|
|
2270
|
+
checked: cfg.showModpackMarket !== false,
|
|
2271
|
+
label: "显示「社区资源」这一栏",
|
|
2272
|
+
title: "插件自带、默认开启;关掉只是不显示这一栏",
|
|
2273
|
+
onChange: (v) => patch({ showModpackMarket: v }),
|
|
2274
|
+
}),
|
|
2275
|
+
h("div", { style: hint }, "关掉只是不显示这一栏,已经下载与安装的整合包不受影响。目录来自自建仓库 " + (((props.status || {}).modpackMarket || {}).repo || "Vesna-Strivozha-cn/dsh-modpack-catalog") + ",CI 每天重建一次。"),
|
|
2276
|
+
h("div", { style: row },
|
|
2277
|
+
h("span", { style: label }, "自动更新(小时)"),
|
|
2278
|
+
h("input", { style: { ...input, width: "78px" }, type: "number", min: "1", max: "168", value: cfg.modpackRefreshHours || 24, onChange: (e) => setField("modpackRefreshHours", Number(e.target.value)) }),
|
|
2279
|
+
h("button", { style: btn, disabled: busy, onClick: () => patch({ modpackRefreshHours: cfg.modpackRefreshHours }) }, "保存")),
|
|
2280
|
+
h("div", { style: { ...hint, borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "8px", marginTop: "2px" } }, "下载与安装包:"),
|
|
2281
|
+
h(Switch, {
|
|
2282
|
+
checked: cfg.autoClearPack === true,
|
|
2283
|
+
label: "装完自动清除安装包(默认关闭)",
|
|
2284
|
+
title: "只删插件自己 packs 目录里、由社区下载留下的那份 .dshpack;别处的文件不碰",
|
|
2285
|
+
onChange: (v) => patch({ autoClearPack: v }),
|
|
2286
|
+
}),
|
|
2287
|
+
h("div", { style: row },
|
|
2288
|
+
h("button", { type: "button", style: btn, disabled: busy, onClick: openPackFolder }, "打开整合包下载文件夹"),
|
|
2289
|
+
h("span", { style: hint }, packsDirLine || "")),
|
|
2290
|
+
h("div", { style: hint }, "搜索、分类、详情与下载码都在「社区资源」那一栏里;上传方式与规则点那一栏右上角。")),
|
|
2086
2291
|
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2087
2292
|
h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
|
|
2088
2293
|
h("div", { style: hint }, (() => {
|
|
@@ -2101,8 +2306,1210 @@ window.__ModuleLoader__.load({
|
|
|
2101
2306
|
)
|
|
2102
2307
|
}
|
|
2103
2308
|
|
|
2309
|
+
// —— 社区资源 ——
|
|
2310
|
+
// 「从市场下载」到「安装页」之间只有一次交接:市场负责下载、校验、把 token 递过去,
|
|
2311
|
+
// 识别 / 扫描 / 兼容 / 许可证 / 安装这些仍然由安装页那条老路做,不另起一套。
|
|
2312
|
+
const installRequest = { value: null, subs: new Set() }
|
|
2313
|
+
const requestInstall = (payload) => {
|
|
2314
|
+
installRequest.value = payload || null
|
|
2315
|
+
for (const fn of [...installRequest.subs]) {
|
|
2316
|
+
try { fn(installRequest.value) } catch (e) { }
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
const subscribeInstallRequest = (fn) => {
|
|
2320
|
+
installRequest.subs.add(fn)
|
|
2321
|
+
if (installRequest.value) {
|
|
2322
|
+
try { fn(installRequest.value) } catch (e) { }
|
|
2323
|
+
}
|
|
2324
|
+
return () => { installRequest.subs.delete(fn) }
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
const MARKET_SORTS = [["new", "最新"], ["downloads", "下载量"], ["size", "体积"], ["name", "名称"]]
|
|
2328
|
+
const MARKET_RULES = [
|
|
2329
|
+
"两条提交方式,内容一样:插件里一键上传(不用命令行),或者自己 fork 提 PR。",
|
|
2330
|
+
"只收两种包:轻量包(lite,只记版本、十几 KB,装的人联网按版本取)与混合包(hybrid,部分插件连本体一起带走,常见几十 MB)。完整包(full)不收,请自己放发布页。",
|
|
2331
|
+
"清单里的 customization 是必填项:轻量包写 none(词条「无修改」),混合包写 custom(词条「有自定义」)。填的和包里的 format 对不上,构建会挡下。",
|
|
2332
|
+
"方式一·第 1 步:社区资源 → 整合包 → 上传我的整合包,填一次自己的 GitHub token(classic 勾 repo;fine-grained 给 contents 与 pull requests 读写)。凭据只在内存里,离开上传页或上传结束就清掉,下次重填。",
|
|
2333
|
+
"方式一·第 2 步:选包(选择文件… 或 浏览文件夹…);可以顺手改名称 / 作者 / 简介 / 主页——改了会写回包内清单并重算 sha256。",
|
|
2334
|
+
"方式一·第 3 步:封面可选。选图后在框里拖动、缩放,挑出要的那块;输出 256×256 或 512×512,只上传框里那一块(PNG,300 KB 以内),存成 covers/<id>.png。",
|
|
2335
|
+
"方式一·第 4 步:选放哪——放进目录仓库(插件算 sha256、写条目、fork 本仓库、开 PR,一次带包 + 条目 + 可选封面);或者放进我的 Release(包传到你自己的 Release 资产,条目写 host: release、repo、tag,目录读资产的 download_count,列表能显示真实下载量)。",
|
|
2336
|
+
"方式一·第 5 步:提交是后台任务,进度在左下角悬浮窗;完成给「打开 PR #N」,出错给「我已知晓」。合并后每天一轮或手动 Run workflow。",
|
|
2337
|
+
"方式二·手动:打包页出包 → 算 sha256(Windows:certutil -hashfile 名字.dshpack SHA256;macOS/Linux:shasum -a 256)与字节数(≤ 64 MB)→ fork 本仓库、切分支 → 把包放 packs/、写 data/packs/<id>.json、封面放 covers/ → 本地 node scripts/build.mjs → 提 PR;合并后每天 03:17 UTC 自动重建,也可以在 Actions 里 Run workflow 立刻扫一轮。",
|
|
2338
|
+
"条目只写定位:id、category、customization、file、sha256、size、createdAt、updatedAt、homepage,可选 cover、repo、host、tag。条目里不要写介绍、名称、作者、插件清单——目录直接显示包内 dsh-modpack.json(打包那一刻填的内容),写了两边会不一致,构建会挡下。",
|
|
2339
|
+
"封面可选:png/jpg,≤ 300 KB,建议正方形;没有封面时列表显示分类色块 + 名字前两字。",
|
|
2340
|
+
"分类按使用场景:工作办公、性能优化、界面美化、实用功能、开发调试、娱乐休闲、学习资料、水槽(插件横跨三类以上会自动归这里)、其它。",
|
|
2341
|
+
"下载量指的是这个 .dshpack 安装文件本身被下载的次数,不是包里插件的 npm 下载量。放 Git 仓库没有逐文件计数,显示「下载量未统计」;想要真实计数就放 Release 并写 host/tag。",
|
|
2342
|
+
"收录门槛:存放包文件的仓库(默认本目录仓库,写了 repo 就查那个)必须建满 24 小时,跟插件市场同一条,挡当天开号刷包。",
|
|
2343
|
+
"混合包请在包里写清楚哪些插件带本体(离线能装)、哪些只记版本(要联网),装的人才不会拔了网才发现缺东西。",
|
|
2344
|
+
"只提交你自己打的包,或者你有权再分发的插件组合;作者没写许可证的组合请先问作者。",
|
|
2345
|
+
]
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
// 附属件(apiVersion 1):接口全在 /market 与 /upload 下,关掉就整层下线,主体不受影响
|
|
2349
|
+
// 两层:外层管左侧「插件 / 整合包」两个大类,里层各自是独立的浏览面板。
|
|
2350
|
+
// 整合包这层就是原来的整包浏览(列表 / 详情 / 上传规则)。
|
|
2351
|
+
// ===== [区块] 社区资源小插件:MarketPanel =====
|
|
2352
|
+
function MarketPanel(props) {
|
|
2353
|
+
const [kind, setKind] = useState(() => (readMarketUi().kind === "plugin" ? "plugin" : "modpack"))
|
|
2354
|
+
useEffect(() => { saveMarketKind(kind) }, [kind])
|
|
2355
|
+
const market = (props.status && props.status.market) || null
|
|
2356
|
+
const installed = Boolean(market && market.installed)
|
|
2357
|
+
const railBtn = (id, text, note) => h("button", {
|
|
2358
|
+
type: "button",
|
|
2359
|
+
key: "rail-" + id,
|
|
2360
|
+
onClick: () => setKind(id),
|
|
2361
|
+
style: {
|
|
2362
|
+
display: "flex",
|
|
2363
|
+
flexDirection: "column",
|
|
2364
|
+
alignItems: "flex-start",
|
|
2365
|
+
gap: "2px",
|
|
2366
|
+
width: "100%",
|
|
2367
|
+
padding: "9px 10px",
|
|
2368
|
+
borderRadius: "8px",
|
|
2369
|
+
border: kind === id ? "1px solid #4C7DF0" : "1px solid transparent",
|
|
2370
|
+
background: kind === id ? "rgba(76, 125, 240, 0.12)" : "transparent",
|
|
2371
|
+
color: "inherit",
|
|
2372
|
+
cursor: "pointer",
|
|
2373
|
+
textAlign: "left",
|
|
2374
|
+
fontSize: "13px",
|
|
2375
|
+
fontWeight: kind === id ? 600 : 400,
|
|
2376
|
+
},
|
|
2377
|
+
},
|
|
2378
|
+
h("span", null, text),
|
|
2379
|
+
note ? h("span", { style: { ...hint, fontSize: "11px", lineHeight: "15px" } }, note) : null)
|
|
2380
|
+
const rail = h("div", {
|
|
2381
|
+
style: {
|
|
2382
|
+
width: "152px",
|
|
2383
|
+
flexShrink: 0,
|
|
2384
|
+
display: "flex",
|
|
2385
|
+
flexDirection: "column",
|
|
2386
|
+
gap: "4px",
|
|
2387
|
+
borderRight: "0.5px solid var(--dsw-alias-border-l2)",
|
|
2388
|
+
paddingRight: "10px",
|
|
2389
|
+
position: "sticky",
|
|
2390
|
+
top: 0,
|
|
2391
|
+
},
|
|
2392
|
+
},
|
|
2393
|
+
h("span", { style: { ...hint, padding: "0 2px 4px" } }, "大类"),
|
|
2394
|
+
railBtn("modpack", "整合包", "打包好的插件组合"),
|
|
2395
|
+
railBtn("plugin", "插件", installed ? "接入插件市场" : "需要插件市场"))
|
|
2396
|
+
return h("div", { style: { display: "flex", gap: "14px", alignItems: "flex-start" } },
|
|
2397
|
+
rail,
|
|
2398
|
+
h("div", { style: { flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2399
|
+
kind === "plugin" ? h(PluginBrowser, { status: props.status }) : h(ModpackBrowser, props)))
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
// 「插件」这一类不自己造目录:直接用插件市场的目录与检索(dsh-plugin-catalog),
|
|
2403
|
+
// 没装市场就没有这一层可看——所以先提示去装市场,而不是给一个空列表。
|
|
2404
|
+
function PluginBrowser(props) {
|
|
2405
|
+
const market = (props.status && props.status.market) || null
|
|
2406
|
+
const installed = Boolean(market && market.installed)
|
|
2407
|
+
const pluginSnap = readMarketUi().plugin || {}
|
|
2408
|
+
const [query, setQuery] = useState(typeof pluginSnap.query === "string" ? pluginSnap.query : "")
|
|
2409
|
+
const [category, setCategory] = useState(typeof pluginSnap.category === "string" ? pluginSnap.category : "all")
|
|
2410
|
+
const [sort, setSort] = useState(typeof pluginSnap.sort === "string" ? pluginSnap.sort : "market")
|
|
2411
|
+
const [items, setItems] = useState(Array.isArray(pluginSnap.items) ? pluginSnap.items : [])
|
|
2412
|
+
const [total, setTotal] = useState(Number(pluginSnap.total) || 0)
|
|
2413
|
+
const [page, setPage] = useState(Number(pluginSnap.page) || 1)
|
|
2414
|
+
const [hasMore, setHasMore] = useState(pluginSnap.hasMore === true)
|
|
2415
|
+
const [chips, setChips] = useState(Array.isArray(pluginSnap.chips) && pluginSnap.chips.length ? pluginSnap.chips : [{ id: "all", label: "全部", count: 0 }])
|
|
2416
|
+
const [loading, setLoading] = useState(false)
|
|
2417
|
+
const [error, setError] = useState("")
|
|
2418
|
+
const [view, setView] = useState(pluginSnap.view === "detail" && pluginSnap.detail ? "detail" : "list")
|
|
2419
|
+
const [detail, setDetail] = useState(pluginSnap.detail || null)
|
|
2420
|
+
const [installing, setInstalling] = useState("")
|
|
2421
|
+
const [installMsg, setInstallMsg] = useState("")
|
|
2422
|
+
// 第一屏如果有上次留下的列表,就别再打一次请求(会闪一下、还把页码冲回 1)
|
|
2423
|
+
const restoredPlugins = useRef(Array.isArray(pluginSnap.items) && pluginSnap.items.length > 0)
|
|
2424
|
+
const applyItems = (data, append) => {
|
|
2425
|
+
const next = Array.isArray(data.items) ? data.items : []
|
|
2426
|
+
setItems(append ? (prev) => prev.concat(next) : next)
|
|
2427
|
+
setTotal(Number(data.total) || 0)
|
|
2428
|
+
setHasMore(Boolean(data.hasMore))
|
|
2429
|
+
if (Array.isArray(data.categories)) {
|
|
2430
|
+
setChips([{ id: "all", label: "全部", count: (data.summary && data.summary.count) || Number(data.total) || 0 }]
|
|
2431
|
+
.concat(data.categories.map((c) => ({ id: c.label, label: c.label, count: c.count || 0 }))))
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
// 分类直接沿用插件市场目录的口径:服务端按 label 过滤,前端只拿一页
|
|
2435
|
+
// 退出程序前一直留着:搜索框文字、分类、排序、页码与已读到的列表
|
|
2436
|
+
useEffect(() => {
|
|
2437
|
+
saveMarketUi("plugin", { query, category, sort, items, total, page, hasMore, chips, view, detail })
|
|
2438
|
+
}, [query, category, sort, items, total, page, hasMore, chips, view, detail])
|
|
2439
|
+
useEffect(() => {
|
|
2440
|
+
if (!installed) return undefined
|
|
2441
|
+
if (restoredPlugins.current) { restoredPlugins.current = false; return undefined }
|
|
2442
|
+
let alive = true
|
|
2443
|
+
const timer = setTimeout(() => {
|
|
2444
|
+
setLoading(true)
|
|
2445
|
+
api("/catalog/search", { query, category, sort, page: 1, pageSize: 20 })
|
|
2446
|
+
.then((data) => {
|
|
2447
|
+
if (!alive) return
|
|
2448
|
+
applyItems(data, false)
|
|
2449
|
+
setPage(1)
|
|
2450
|
+
setError(data && data.ok === false ? (data.error || "") : "")
|
|
2451
|
+
})
|
|
2452
|
+
.catch((e) => { if (alive) setError((e && e.message) || String(e)) })
|
|
2453
|
+
.finally(() => { if (alive) setLoading(false) })
|
|
2454
|
+
}, 220)
|
|
2455
|
+
return () => { alive = false; clearTimeout(timer) }
|
|
2456
|
+
}, [installed, query, category, sort])
|
|
2457
|
+
const loadMore = async () => {
|
|
2458
|
+
if (!hasMore || loading) return
|
|
2459
|
+
setLoading(true)
|
|
2460
|
+
try {
|
|
2461
|
+
const data = await api("/catalog/search", { query, category, sort, page: page + 1, pageSize: 20 })
|
|
2462
|
+
if (data && data.ok) { applyItems(data, true); setPage(page + 1) }
|
|
2463
|
+
} catch (e) {
|
|
2464
|
+
setError((e && e.message) || String(e))
|
|
2465
|
+
} finally {
|
|
2466
|
+
setLoading(false)
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
// 装 / 更新:同一来源(npm 上的 name@version),服务端优先走宿主插件管理器,失败退回命令行
|
|
2470
|
+
const installOne = async (item) => {
|
|
2471
|
+
if (!item || !item.name || installing) return
|
|
2472
|
+
setInstalling(item.name)
|
|
2473
|
+
setInstallMsg("")
|
|
2474
|
+
try {
|
|
2475
|
+
const data = await api("/plugin/install", { name: item.name, version: item.version || "" })
|
|
2476
|
+
if (data && data.ok) {
|
|
2477
|
+
const wasUpdate = item.installed && item.updateAvailable
|
|
2478
|
+
setInstallMsg((wasUpdate ? "已更新:" : "已装好:") + item.name + (data.restartRequired ? "(重启 DSH 后生效)" : "(已生效)"))
|
|
2479
|
+
const fresh = await api("/catalog/search", { query, category, sort, page: 1, pageSize: 20 })
|
|
2480
|
+
if (fresh) {
|
|
2481
|
+
applyItems(fresh, false)
|
|
2482
|
+
setPage(1)
|
|
2483
|
+
const after = (Array.isArray(fresh.items) ? fresh.items : []).find((row) => row.name === item.name)
|
|
2484
|
+
if (after) setDetail((prev) => (prev && prev.name === item.name ? after : prev))
|
|
2485
|
+
}
|
|
2486
|
+
} else {
|
|
2487
|
+
setInstallMsg("没装成:" + ((data && (data.error || data.application)) || "未知原因"))
|
|
2488
|
+
}
|
|
2489
|
+
} catch (e) {
|
|
2490
|
+
setInstallMsg("没装成:" + ((e && e.message) || String(e)))
|
|
2491
|
+
} finally {
|
|
2492
|
+
setInstalling("")
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
const isLatest = (item) => Boolean(item.installed && item.version && item.localVersion && item.version === item.localVersion)
|
|
2496
|
+
const installLabel = (item) => {
|
|
2497
|
+
if (installing === item.name) return "安装中…"
|
|
2498
|
+
if (!item.installed) return "下载并安装"
|
|
2499
|
+
if (item.updateAvailable) return "更新到 " + item.version
|
|
2500
|
+
if (isLatest(item)) return "重新安装"
|
|
2501
|
+
return "重新安装"
|
|
2502
|
+
}
|
|
2503
|
+
const versionLine = (item) => {
|
|
2504
|
+
if (!item.installed) return "本机还没装;市场版 v" + (item.version || "未知")
|
|
2505
|
+
if (isLatest(item)) return "已是当前最新版(v" + item.version + ")"
|
|
2506
|
+
if (item.updateAvailable) return "本机 v" + (item.localVersion || "?") + ",市场有新版 v" + item.version
|
|
2507
|
+
return "本机已装 v" + (item.localVersion || item.version || "?")
|
|
2508
|
+
}
|
|
2509
|
+
const openDetail = (item) => { setDetail(item); setView("detail"); setInstallMsg("") }
|
|
2510
|
+
if (view === "detail" && detail) {
|
|
2511
|
+
const item = detail
|
|
2512
|
+
const latest = isLatest(item)
|
|
2513
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2514
|
+
h("div", { style: row },
|
|
2515
|
+
h("button", { type: "button", style: chipBtn, onClick: () => setView("list") }, "← 返回列表"),
|
|
2516
|
+
h("span", { style: { ...strong, fontSize: "15px" } }, item.title || item.name),
|
|
2517
|
+
h(Tag, null, item.categoryLabel || item.category || "其它"),
|
|
2518
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, item.name)),
|
|
2519
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "14px", display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2520
|
+
h("div", { style: row },
|
|
2521
|
+
h("span", { style: { ...hint, color: latest ? "#2bb673" : (item.updateAvailable ? "#4C7DF0" : "inherit") } }, versionLine(item)),
|
|
2522
|
+
item.owner ? h("span", { style: hint }, "作者 " + item.owner) : null,
|
|
2523
|
+
item.publishedAt ? h("span", { style: hint }, "发布 " + item.publishedAt) : null,
|
|
2524
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, item.version ? "市场版 v" + item.version : "")),
|
|
2525
|
+
h("div", { style: { fontSize: "12.5px", lineHeight: "20px" } }, item.description || "插件市场里没写说明。"),
|
|
2526
|
+
item.homepage || item.repository ? h("span", { style: { ...hint, wordBreak: "break-all" } }, item.homepage || item.repository) : null,
|
|
2527
|
+
h("div", { style: row },
|
|
2528
|
+
h("button", {
|
|
2529
|
+
type: "button",
|
|
2530
|
+
style: { ...(latest ? btn : btnPrimary), padding: "7px 20px", fontSize: "13px", fontWeight: 600 },
|
|
2531
|
+
disabled: Boolean(installing),
|
|
2532
|
+
title: item.name + (item.version ? "@" + item.version : "") + "(来源与插件市场一致)",
|
|
2533
|
+
onClick: () => installOne(item),
|
|
2534
|
+
}, installLabel(item)),
|
|
2535
|
+
latest ? h("span", { style: hint }, "已是当前最新版;想再装一遍也可以。") : null,
|
|
2536
|
+
item.updateAvailable ? h("span", { style: { ...hint, color: "#4C7DF0" } }, "本机 v" + (item.localVersion || "?") + " → v" + item.version) : null),
|
|
2537
|
+
installMsg ? h("div", { style: { ...hint, color: /没装成/u.test(installMsg) ? "#ff6b6b" : "#2bb673" } }, installMsg) : null,
|
|
2538
|
+
h("div", { style: hint }, "装完插件市场认成市场版(依赖写成 名字@版本);卸载仍去插件市场里做。")),
|
|
2539
|
+
h("div", { style: hint }, "点「返回列表」回到刚才那页,搜索与分类都还在。"))
|
|
2540
|
+
}
|
|
2541
|
+
if (!installed) {
|
|
2542
|
+
return h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "16px", display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2543
|
+
h("span", { style: strong }, "请先安装插件市场"),
|
|
2544
|
+
h("span", { style: hint }, "「插件」这一类直接读插件市场(dshmarket)的目录与检索,功能基于插件市场;没装就没有这一层可看。"),
|
|
2545
|
+
h("span", { style: hint }, "装好插件市场后回到这里,左边这一项会变成「接入插件市场」,列表也就有了。"))
|
|
2546
|
+
}
|
|
2547
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2548
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2549
|
+
h("div", { style: { ...row, justifyContent: "space-between" } },
|
|
2550
|
+
h("span", { style: { ...strong, fontSize: "13px" } }, "搜索插件"),
|
|
2551
|
+
h("span", { style: hint }, "跟打包页同一套:分类、搜索、已装优先;目录与检索都来自插件市场(dsh-plugin-catalog)")),
|
|
2552
|
+
h("div", { style: { display: "grid", gridTemplateColumns: "minmax(160px, 1fr) 160px 120px", gap: "8px", alignItems: "center" } },
|
|
2553
|
+
h("input", {
|
|
2554
|
+
type: "search",
|
|
2555
|
+
value: query,
|
|
2556
|
+
placeholder: "插件名 / 作者 / 描述(例如 记忆、壁纸、侧边栏)",
|
|
2557
|
+
onChange: (event) => setQuery(event.target.value),
|
|
2558
|
+
style: { height: "30px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "inherit", fontSize: "12.5px", padding: "0 8px" },
|
|
2559
|
+
}),
|
|
2560
|
+
h("select", {
|
|
2561
|
+
value: sort,
|
|
2562
|
+
onChange: (event) => setSort(event.target.value),
|
|
2563
|
+
style: { height: "30px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "inherit", fontSize: "12.5px" },
|
|
2564
|
+
}, [["market", "按相关度"], ["new", "最新发布"], ["name", "按名字"]].map(([value, text]) => h("option", { key: value, value }, text))),
|
|
2565
|
+
h("span", { style: { ...hint, textAlign: "right" } }, loading ? "搜索中…" : "共 " + total + " 个")),
|
|
2566
|
+
h(CategoryChips, { chips, value: category, onChange: setCategory })),
|
|
2567
|
+
error ? h("div", { style: { ...hint, color: "#ff6b6b", lineHeight: "19px" } }, String(error)) : null,
|
|
2568
|
+
loading && items.length === 0 ? h("div", { style: { ...hint, padding: "14px 2px" } }, "正在读取插件目录…") : null,
|
|
2569
|
+
!loading && items.length === 0 && !error
|
|
2570
|
+
? h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "16px", display: "flex", flexDirection: "column", gap: "6px" } },
|
|
2571
|
+
h("span", { style: strong }, query ? "没有匹配的插件" : "插件目录还是空的"),
|
|
2572
|
+
h("span", { style: hint }, query ? "换个说法试试:插件名、作者名、描述里的词都能搜。" : "插件市场还没建过目录索引:去插件市场里刷一次,或等它自己更新。"))
|
|
2573
|
+
: null,
|
|
2574
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", overflow: "hidden" } },
|
|
2575
|
+
items.map((item) => h("div", {
|
|
2576
|
+
key: "plug-" + item.name,
|
|
2577
|
+
onClick: () => openDetail(item),
|
|
2578
|
+
title: "点开看详情与下载",
|
|
2579
|
+
style: { display: "flex", flexDirection: "column", gap: "3px", padding: "9px 12px", borderBottom: "0.5px solid var(--dsw-alias-border-l2)", cursor: "pointer" },
|
|
2580
|
+
},
|
|
2581
|
+
h("div", { style: row },
|
|
2582
|
+
h("span", { style: { fontSize: "13px", fontWeight: 600 } }, item.title || item.name),
|
|
2583
|
+
h(Tag, null, item.categoryLabel || item.category || "其它"),
|
|
2584
|
+
item.installed ? h("span", { style: { ...hint, color: "#2bb673" } }, "本机已装" + (item.updateAvailable ? "(市场版 " + item.version + " 更新)" : "")) : null,
|
|
2585
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, item.version ? "v" + item.version : ""),
|
|
2586
|
+
h("span", { style: { ...hint, flexShrink: 0, color: item.updateAvailable ? "#4C7DF0" : undefined } }, isLatest(item) ? "已是最新版本" : (item.installed ? "可更新" : "")),
|
|
2587
|
+
h("span", { style: { ...chipBtn, flexShrink: 0 } }, "查看 ›")),
|
|
2588
|
+
h("span", { style: hint }, item.description || "作者没写说明。"),
|
|
2589
|
+
h("span", { style: { ...hint, fontSize: "11.5px" } }, item.name)))),
|
|
2590
|
+
hasMore ? h("div", { style: row },
|
|
2591
|
+
h("button", { type: "button", style: btn, disabled: loading, onClick: loadMore }, loading ? "读取中…" : "加载更多")) : null,
|
|
2592
|
+
installMsg ? h("div", { style: { ...hint, color: /没装成/u.test(installMsg) ? "#ff6b6b" : "#2bb673" } }, installMsg) : null,
|
|
2593
|
+
h("div", { style: hint }, "装与更新就在这里做:来源跟插件市场一致(npm 上的 名字@版本),装完市场认成市场版;卸载仍去插件市场里做。"))
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
// ===== [区块] 社区资源:一键上传(别人也能用,不需要 LLM token) =====
|
|
2597
|
+
const UPLOAD_CATEGORIES = ["工作办公", "性能优化", "界面美化", "实用功能", "开发调试", "娱乐休闲", "学习资料", "其它", "水槽"]
|
|
2598
|
+
|
|
2599
|
+
function bytesToBase64(buffer) {
|
|
2600
|
+
const bytes = new Uint8Array(buffer)
|
|
2601
|
+
let binary = ""
|
|
2602
|
+
const chunk = 0x8000
|
|
2603
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
2604
|
+
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk))
|
|
2605
|
+
}
|
|
2606
|
+
return window.btoa(binary)
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
function UploadPanel(props) {
|
|
2610
|
+
// 凭据不跟着页面走:离开这一页就请服务端把它从内存里丢掉,下次进来必须重新填
|
|
2611
|
+
useEffect(() => () => {
|
|
2612
|
+
api("/upload/token", { token: "" }).catch(() => {})
|
|
2613
|
+
}, [])
|
|
2614
|
+
const [status, setStatus] = useState(null)
|
|
2615
|
+
const [token, setToken] = useState("")
|
|
2616
|
+
const [busy, setBusy] = useState("")
|
|
2617
|
+
const [error, setError] = useState("")
|
|
2618
|
+
const [msg, setMsg] = useState("")
|
|
2619
|
+
const [fileBase64, setFileBase64] = useState("")
|
|
2620
|
+
const [filePath, setFilePath] = useState("")
|
|
2621
|
+
const [fileName, setFileName] = useState("")
|
|
2622
|
+
const [preview, setPreview] = useState(null)
|
|
2623
|
+
const [fields, setFields] = useState({ name: "", author: "", description: "", homepage: "" })
|
|
2624
|
+
const [category, setCategory] = useState("实用功能")
|
|
2625
|
+
const [host, setHost] = useState("repo")
|
|
2626
|
+
const [repoInput, setRepoInput] = useState("")
|
|
2627
|
+
const [tagInput, setTagInput] = useState("")
|
|
2628
|
+
const [cover, setCover] = useState("")
|
|
2629
|
+
const [coverSrc, setCoverSrc] = useState("") // 原图(还没裁)
|
|
2630
|
+
const [coverZoom, setCoverZoom] = useState(1)
|
|
2631
|
+
const [coverOffset, setCoverOffset] = useState({ x: 0, y: 0 })
|
|
2632
|
+
const [coverSize, setCoverSize] = useState(512)
|
|
2633
|
+
const coverDrag = useRef(null)
|
|
2634
|
+
const coverFrameRef = useRef(null)
|
|
2635
|
+
const [coverErr, setCoverErr] = useState("")
|
|
2636
|
+
const [localPack, setLocalPack] = useState(null)
|
|
2637
|
+
const [previewBusy, setPreviewBusy] = useState("")
|
|
2638
|
+
const coverRef = useRef(null)
|
|
2639
|
+
const [dir, setDir] = useState("")
|
|
2640
|
+
const [dirItems, setDirItems] = useState([])
|
|
2641
|
+
const [dirErr, setDirErr] = useState("")
|
|
2642
|
+
const fileRef = useRef(null)
|
|
2643
|
+
|
|
2644
|
+
const load = async () => {
|
|
2645
|
+
try {
|
|
2646
|
+
const data = await api("/upload/status")
|
|
2647
|
+
setStatus(data)
|
|
2648
|
+
} catch (e) {
|
|
2649
|
+
setError((e && e.message) || String(e))
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
useEffect(() => { load() }, [])
|
|
2653
|
+
|
|
2654
|
+
const saveToken = async () => {
|
|
2655
|
+
setBusy("token"); setError(""); setMsg("")
|
|
2656
|
+
try {
|
|
2657
|
+
const data = await api("/upload/token", { token: token.trim() })
|
|
2658
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "没存上")
|
|
2659
|
+
setToken("")
|
|
2660
|
+
setMsg(data.configured ? "已放进内存:登录为 " + data.login + "(不写盘,上传结束立刻清除;下次上传要重填)" : "已清掉内存里的凭据")
|
|
2661
|
+
await load()
|
|
2662
|
+
} catch (e) {
|
|
2663
|
+
setError((e && e.message) || String(e))
|
|
2664
|
+
} finally { setBusy("") }
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
const readPreview = async (body) => {
|
|
2668
|
+
const data = await api("/upload/preview", body, 60000)
|
|
2669
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "读不了这个包")
|
|
2670
|
+
setPreview(data)
|
|
2671
|
+
setFields({
|
|
2672
|
+
name: String((data.fields && data.fields.name) || ""),
|
|
2673
|
+
author: String((data.fields && data.fields.author) || ""),
|
|
2674
|
+
description: String((data.fields && data.fields.description) || ""),
|
|
2675
|
+
homepage: String((data.fields && data.fields.homepage) || ""),
|
|
2676
|
+
})
|
|
2677
|
+
if (data.fileName) setFileName(data.fileName)
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
const readFile = async (picked) => {
|
|
2681
|
+
if (!picked) return
|
|
2682
|
+
if (!/\.dshpack$/iu.test(picked.name || "")) { setError("只认 .dshpack 整合包"); return }
|
|
2683
|
+
setBusy("read"); setError(""); setMsg(""); setPreview(null)
|
|
2684
|
+
setFilePath("")
|
|
2685
|
+
try {
|
|
2686
|
+
const buffer = await picked.arrayBuffer()
|
|
2687
|
+
const base64 = bytesToBase64(buffer)
|
|
2688
|
+
setFileBase64(base64)
|
|
2689
|
+
setFileName(picked.name)
|
|
2690
|
+
await readPreview({ fileName: picked.name, base64 })
|
|
2691
|
+
} catch (e) {
|
|
2692
|
+
setError((e && e.message) || String(e))
|
|
2693
|
+
setPreview(null)
|
|
2694
|
+
} finally { setBusy("") }
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
const readPath = async (target) => {
|
|
2698
|
+
if (!target) return
|
|
2699
|
+
setBusy("read"); setError(""); setMsg(""); setPreview(null)
|
|
2700
|
+
setFileBase64("")
|
|
2701
|
+
try {
|
|
2702
|
+
await readPreview({ file: target })
|
|
2703
|
+
setFilePath(target)
|
|
2704
|
+
setFileName(String(target).split(/[\\/]/u).pop() || target)
|
|
2705
|
+
} catch (e) {
|
|
2706
|
+
setError((e && e.message) || String(e))
|
|
2707
|
+
setPreview(null)
|
|
2708
|
+
} finally { setBusy("") }
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
const browseFolder = async () => {
|
|
2712
|
+
if (typeof pickDirectoryHost !== "function") {
|
|
2713
|
+
setDirErr("这个环境没有系统目录选择器:用「选择文件…」或者把包放进插件自己的 packs 目录")
|
|
2714
|
+
return
|
|
2715
|
+
}
|
|
2716
|
+
setBusy("dir"); setDirErr("")
|
|
2717
|
+
try {
|
|
2718
|
+
const picked = await pickDirectoryHost()
|
|
2719
|
+
if (!picked) return
|
|
2720
|
+
setDir(picked)
|
|
2721
|
+
const data = await api("/packs", { dir: picked })
|
|
2722
|
+
setDirItems(Array.isArray(data.items) ? data.items : [])
|
|
2723
|
+
setDirErr(String(data.error || ""))
|
|
2724
|
+
} catch (e) {
|
|
2725
|
+
setDirErr((e && e.message) || String(e))
|
|
2726
|
+
} finally { setBusy("") }
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2729
|
+
const clearFile = () => {
|
|
2730
|
+
setFileBase64(""); setFilePath(""); setFileName(""); setPreview(null)
|
|
2731
|
+
setFields({ name: "", author: "", description: "", homepage: "" })
|
|
2732
|
+
setDirItems([]); setError(""); setMsg("")
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
// 封面:只收 PNG/JPG,读成 data URL,前端先拦一遍大小(服务端还会再拦一次)
|
|
2736
|
+
const pickCover = async (picked) => {
|
|
2737
|
+
if (!picked) return
|
|
2738
|
+
setCoverErr("")
|
|
2739
|
+
if (!/image\/(png|jpeg)/iu.test(picked.type || "")) { setCoverErr("只收 PNG 或 JPG"); return }
|
|
2740
|
+
if (picked.size > 300 * 1024) { setCoverErr("图片 " + Math.round(picked.size / 1024) + " KB,超过 300 KB;建议 512×512 以内"); return }
|
|
2741
|
+
try {
|
|
2742
|
+
const url = await new Promise((resolve, reject) => {
|
|
2743
|
+
const reader = new FileReader()
|
|
2744
|
+
reader.onload = () => resolve(String(reader.result || ""))
|
|
2745
|
+
reader.onerror = () => reject(new Error("读不了这张图"))
|
|
2746
|
+
reader.readAsDataURL(picked)
|
|
2747
|
+
})
|
|
2748
|
+
setCoverSrc(url)
|
|
2749
|
+
setCoverZoom(1)
|
|
2750
|
+
setCoverOffset({ x: 0, y: 0 })
|
|
2751
|
+
setCover("")
|
|
2752
|
+
} catch (e) {
|
|
2753
|
+
setCoverErr((e && e.message) || String(e))
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
// 预览:把这份本地包临时当成社区里的一条,走同一条下载 → 安装路径(不联网、不开 PR)
|
|
2758
|
+
// —— 封面裁切:框里拖动挑位置、滑块缩放,应用时只把框里那块导出成正方形 ——
|
|
2759
|
+
const COVER_FRAME = 240
|
|
2760
|
+
const coverImgStyle = () => ({
|
|
2761
|
+
position: "absolute",
|
|
2762
|
+
left: "50%",
|
|
2763
|
+
top: "50%",
|
|
2764
|
+
transform: "translate(-50%, -50%) translate(" + coverOffset.x + "px, " + coverOffset.y + "px) scale(" + coverZoom + ")",
|
|
2765
|
+
transformOrigin: "center center",
|
|
2766
|
+
maxWidth: "none",
|
|
2767
|
+
width: "100%",
|
|
2768
|
+
height: "100%",
|
|
2769
|
+
objectFit: "cover",
|
|
2770
|
+
pointerEvents: "none",
|
|
2771
|
+
userSelect: "none",
|
|
2772
|
+
})
|
|
2773
|
+
const resetCover = () => { setCoverZoom(1); setCoverOffset({ x: 0, y: 0 }) }
|
|
2774
|
+
const coverDown = (event) => {
|
|
2775
|
+
coverDrag.current = { x: event.clientX, y: event.clientY, ox: coverOffset.x, oy: coverOffset.y }
|
|
2776
|
+
if (event.currentTarget && event.currentTarget.setPointerCapture) { try { event.currentTarget.setPointerCapture(event.pointerId) } catch (e) { } }
|
|
2777
|
+
}
|
|
2778
|
+
const coverMove = (event) => {
|
|
2779
|
+
const drag = coverDrag.current
|
|
2780
|
+
if (!drag) return
|
|
2781
|
+
setCoverOffset({ x: drag.ox + (event.clientX - drag.x), y: drag.oy + (event.clientY - drag.y) })
|
|
2782
|
+
}
|
|
2783
|
+
const coverUp = () => { coverDrag.current = null }
|
|
2784
|
+
const applyCover = () => {
|
|
2785
|
+
setCoverErr("")
|
|
2786
|
+
if (!coverSrc) { setCoverErr("先选一张图"); return }
|
|
2787
|
+
const image = new window.Image()
|
|
2788
|
+
image.onload = () => {
|
|
2789
|
+
try {
|
|
2790
|
+
const size = coverSize
|
|
2791
|
+
const canvas = window.document.createElement("canvas")
|
|
2792
|
+
canvas.width = size
|
|
2793
|
+
canvas.height = size
|
|
2794
|
+
const ctx = canvas.getContext("2d")
|
|
2795
|
+
if (!ctx) throw new Error("浏览器不支持 canvas")
|
|
2796
|
+
const frame = COVER_FRAME
|
|
2797
|
+
const scale = Math.max(size / image.naturalWidth, size / image.naturalHeight) * coverZoom
|
|
2798
|
+
const width = image.naturalWidth * scale
|
|
2799
|
+
const height = image.naturalHeight * scale
|
|
2800
|
+
const left = size / 2 - width / 2 + (coverOffset.x / frame) * size
|
|
2801
|
+
const top = size / 2 - height / 2 + (coverOffset.y / frame) * size
|
|
2802
|
+
ctx.fillStyle = "#000"
|
|
2803
|
+
ctx.fillRect(0, 0, size, size)
|
|
2804
|
+
ctx.drawImage(image, left, top, width, height)
|
|
2805
|
+
const url = canvas.toDataURL("image/png")
|
|
2806
|
+
const bytes = Math.round((url.length - "data:image/png;base64,".length) * 3 / 4)
|
|
2807
|
+
if (bytes > 300 * 1024) { setCoverErr("裁出来的图 " + Math.round(bytes / 1024) + " KB,超过 300 KB;换小一点的规格或缩小一点再试"); return }
|
|
2808
|
+
setCover(url)
|
|
2809
|
+
} catch (e) {
|
|
2810
|
+
setCoverErr((e && e.message) || String(e))
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
image.onerror = () => setCoverErr("这张图读不出来")
|
|
2814
|
+
image.src = coverSrc
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
const previewLocal = async () => {
|
|
2818
|
+
if (!fileBase64 && !filePath) { setError("先选一个 .dshpack"); return }
|
|
2819
|
+
setPreviewBusy("preview"); setError(""); setMsg(""); setLocalPack(null)
|
|
2820
|
+
try {
|
|
2821
|
+
const data = await api("/market/preview", {
|
|
2822
|
+
...(fileBase64 ? { base64: fileBase64 } : { file: filePath }),
|
|
2823
|
+
fileName,
|
|
2824
|
+
name: fields.name,
|
|
2825
|
+
description: fields.description,
|
|
2826
|
+
category,
|
|
2827
|
+
cover: cover || undefined,
|
|
2828
|
+
}, 120000)
|
|
2829
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "预览失败")
|
|
2830
|
+
setLocalPack(data.pack)
|
|
2831
|
+
if (typeof props.onPreview === "function") props.onPreview(data.pack)
|
|
2832
|
+
setMsg("下面就是它在社区里的样子(本地模拟,还没上传);两个按钮都走真实的下载与安装流程")
|
|
2833
|
+
} catch (e) {
|
|
2834
|
+
setError((e && e.message) || String(e))
|
|
2835
|
+
} finally { setPreviewBusy("") }
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
const previewDownload = async (saveOnly) => {
|
|
2839
|
+
if (!localPack) return
|
|
2840
|
+
setPreviewBusy(saveOnly ? "save" : "install"); setError(""); setMsg("")
|
|
2841
|
+
try {
|
|
2842
|
+
const data = await api("/market/download", saveOnly ? { id: localPack.id, saveOnly: true } : { id: localPack.id }, 180000)
|
|
2843
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "下载失败")
|
|
2844
|
+
if (saveOnly) { setMsg("已下到本机:" + (data.savedName || localPack.name)); return }
|
|
2845
|
+
requestInstall({ token: data.token, fileName: data.fileName, packName: localPack.name })
|
|
2846
|
+
setMsg("已下载并读取:" + localPack.name + ",转到安装页")
|
|
2847
|
+
if (typeof props.onGoInstall === "function") props.onGoInstall()
|
|
2848
|
+
} catch (e) {
|
|
2849
|
+
setError((e && e.message) || String(e))
|
|
2850
|
+
} finally { setPreviewBusy("") }
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
const submit = async (dryRun) => {
|
|
2854
|
+
if (!preview) { setError("先选一个包"); return }
|
|
2855
|
+
if (!category) { setError("选一个类型"); return }
|
|
2856
|
+
setBusy("submit"); setError(""); setMsg("")
|
|
2857
|
+
try {
|
|
2858
|
+
const data = await api("/upload/submit", {
|
|
2859
|
+
fileName,
|
|
2860
|
+
...(fileBase64 ? { base64: fileBase64 } : { file: filePath }),
|
|
2861
|
+
category,
|
|
2862
|
+
edits: fields,
|
|
2863
|
+
homepage: fields.homepage,
|
|
2864
|
+
host,
|
|
2865
|
+
...(dryRun ? { dryRun: true } : {}),
|
|
2866
|
+
...(cover ? { cover } : {}),
|
|
2867
|
+
...(host === "release" ? { repo: repoInput.trim(), tag: tagInput.trim() } : {}),
|
|
2868
|
+
}, 60000)
|
|
2869
|
+
if (!data || data.ok !== true) throw new Error((data && data.error) || "没提交成功")
|
|
2870
|
+
const job = (data && data.job) || null
|
|
2871
|
+
setMsg("已开始" + (job && job.id ? "(任务 " + job.id + ")" : "") + ":进度显示在左下角悬浮窗;完成后那一行会变成「打开 PR」,卡住会出现「我已知晓」。")
|
|
2872
|
+
setToken("")
|
|
2873
|
+
await load()
|
|
2874
|
+
} catch (e) {
|
|
2875
|
+
setError((e && e.message) || String(e))
|
|
2876
|
+
} finally { setBusy("") }
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
const configured = Boolean(status && status.configured)
|
|
2880
|
+
const repo = (status && status.repo) || "Vesna-Strivozha-cn/dsh-modpack-catalog"
|
|
2881
|
+
const changed = preview ? ["name", "author", "description", "homepage"].filter((key) => String(fields[key] || "").trim() !== String((preview.fields && preview.fields[key]) || "").trim()) : []
|
|
2882
|
+
const fmt = preview ? (preview.format === "hybrid" ? "混合包" : "轻量包") : ""
|
|
2883
|
+
const sum = (preview && preview.summary) || {}
|
|
2884
|
+
const pluginItems = (preview && Array.isArray(preview.pluginList)) ? preview.pluginList : []
|
|
2885
|
+
const addLabel = preview ? (preview.format === "hybrid" ? "有自定义" : "无修改") : ""
|
|
2886
|
+
|
|
2887
|
+
// 步骤外壳:编号圆点 + 标题 + 右侧状态
|
|
2888
|
+
const stepCard = (no, title, statusNode, body) => h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px", background: "var(--dsw-alias-bg-l2, transparent)" } },
|
|
2889
|
+
h("div", { style: { ...row, gap: "8px" } },
|
|
2890
|
+
h("div", { style: { width: "20px", height: "20px", borderRadius: "10px", background: "#4C7DF0", color: "#fff", fontSize: "11px", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 700, flexShrink: 0 } }, String(no)),
|
|
2891
|
+
h("div", { style: { ...strong, fontSize: "13px" } }, title),
|
|
2892
|
+
h("span", { style: { marginLeft: "auto" } }, statusNode)),
|
|
2893
|
+
body)
|
|
2894
|
+
|
|
2895
|
+
const pluginRow = (item) => h("div", { style: { ...row, gap: "6px", padding: "5px 0", borderTop: "0.5px solid var(--dsw-alias-border-l2)" } },
|
|
2896
|
+
h("span", { style: { ...strong, fontSize: "12.5px" } }, item.name),
|
|
2897
|
+
h("span", { style: hint }, item.latest ? "市场最新(装的时候按名字取)" : "@" + item.version),
|
|
2898
|
+
item.group ? h(Tag, { color: "#4C7DF0" }, "组:" + item.group) : null,
|
|
2899
|
+
h(Tag, { color: item.configMode === "custom" ? "#ffb020" : undefined }, item.configMode === "custom" ? "自定义配置" + (item.configKeys ? " · " + item.configKeys + " 项" : "") : "默认配置"),
|
|
2900
|
+
item.dataIncluded ? h(Tag, { color: "#2bb673" }, "带数据" + (item.dataRedacted ? " · 擦除 " + item.dataRedacted + " 处" : "")) : null,
|
|
2901
|
+
item.embedded ? h(Tag, null, "本体在包里") : null)
|
|
2902
|
+
|
|
2903
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "12px" } },
|
|
2904
|
+
h("div", { style: row },
|
|
2905
|
+
h("button", { type: "button", style: chipBtn, onClick: props.onBack }, "← 返回"),
|
|
2906
|
+
h("span", { style: { ...strong, fontSize: "15px" } }, "上传我的整合包"),
|
|
2907
|
+
h(Tag, null, "一键提 PR"),
|
|
2908
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, "目录:" + repo)),
|
|
2909
|
+
h("div", { style: hint }, "打包好一份轻量包或混合包,在这里选它:插件自己算 sha256、写条目,再用你的 GitHub 账号 fork 目录仓库、开一个 PR。全程本机发请求,不消耗模型 token。凭据只在内存里,上传结束(成功或失败)立刻丢掉,所以每次都要重填。"),
|
|
2910
|
+
|
|
2911
|
+
stepCard(1, "GitHub 凭据",
|
|
2912
|
+
configured ? h(Tag, { color: "#2bb673" }, "已就绪") : h(Tag, null, "待填"),
|
|
2913
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2914
|
+
h("div", { style: hint }, configured ? ("本次已放进内存" + (status && status.login ? ":登录为 " + status.login : "") + "(上传结束就会清掉)") : "classic token 勾 repo 就够;fine-grained 要 contents 与 pull requests 读写。只放内存,不写盘"),
|
|
2915
|
+
h("div", { style: row },
|
|
2916
|
+
h("input", {
|
|
2917
|
+
type: "password",
|
|
2918
|
+
style: { ...input, flex: "1 1 320px" },
|
|
2919
|
+
placeholder: configured ? "要换一个就粘贴新的 token" : "ghp_… 或 github_pat_…",
|
|
2920
|
+
value: token,
|
|
2921
|
+
onChange: (e) => setToken(e.target.value),
|
|
2922
|
+
}),
|
|
2923
|
+
h("button", { type: "button", style: btnPrimary, disabled: busy !== "" || !token.trim(), onClick: saveToken }, busy === "token" ? "保存中…" : "保存"),
|
|
2924
|
+
configured ? h("button", { type: "button", style: btn, disabled: busy !== "", onClick: () => { setToken(""); saveToken() } }, "清除") : null))),
|
|
2925
|
+
|
|
2926
|
+
stepCard(2, "选包",
|
|
2927
|
+
preview ? h(Tag, { color: "#2bb673" }, "已读取") : h(Tag, null, busy === "read" ? "读取中" : "待选"),
|
|
2928
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2929
|
+
h("div", { style: row },
|
|
2930
|
+
h("input", {
|
|
2931
|
+
type: "file",
|
|
2932
|
+
accept: ".dshpack",
|
|
2933
|
+
ref: fileRef,
|
|
2934
|
+
style: { display: "none" },
|
|
2935
|
+
onChange: (e) => {
|
|
2936
|
+
const picked = e && e.target && e.target.files ? e.target.files[0] : null
|
|
2937
|
+
readFile(picked)
|
|
2938
|
+
if (e && e.target) e.target.value = ""
|
|
2939
|
+
},
|
|
2940
|
+
}),
|
|
2941
|
+
h("button", { type: "button", style: btn, disabled: busy !== "", onClick: () => { if (fileRef.current) fileRef.current.click() } }, busy === "read" ? "读取中…" : (preview ? "换一个文件…" : "选择文件…")),
|
|
2942
|
+
h("button", { type: "button", style: btn, disabled: busy !== "", onClick: browseFolder }, "浏览文件夹…"),
|
|
2943
|
+
preview ? h("button", { type: "button", style: btn, disabled: busy !== "", onClick: clearFile }, "清除") : null),
|
|
2944
|
+
preview
|
|
2945
|
+
? h("div", { style: { ...box, padding: "10px 12px", background: "var(--dsw-alias-bg-l1, transparent)", display: "flex", flexDirection: "column", gap: "6px" } },
|
|
2946
|
+
h("div", { style: row },
|
|
2947
|
+
h("span", { style: { ...strong, fontSize: "13px" } }, fileName),
|
|
2948
|
+
h(Tag, { color: preview.format === "hybrid" ? "#a855f7" : "#4C7DF0" }, fmt),
|
|
2949
|
+
h(Tag, null, addLabel),
|
|
2950
|
+
h(Tag, null, (preview.plugins || 0) + " 个插件")),
|
|
2951
|
+
h("div", { style: hint }, Math.round((preview.size || 0) / 1024) + " KB · sha256 " + String(preview.sha256 || "").slice(0, 16) + "… · " + (pluginItems.filter((item) => item.embedded).length > 0 ? "带本体 " + pluginItems.filter((item) => item.embedded).length + " 个" : "不带本体,装的时候按版本取")))
|
|
2952
|
+
: h("div", { style: hint }, busy === "read" ? "正在读清单…" : "还没选包:可以直接选文件,也可以用「浏览文件夹…」从某个目录里挑(跟安装页一样)"),
|
|
2953
|
+
dirItems.length > 0
|
|
2954
|
+
? h("div", { style: { display: "flex", flexDirection: "column", gap: "4px" } },
|
|
2955
|
+
h("div", { style: hint }, "这个目录里的整合包(点一个就读):" + (dir ? " " + dir : "")),
|
|
2956
|
+
dirItems.slice(0, 8).map((item) => h("button", {
|
|
2957
|
+
key: "dir-" + item.name,
|
|
2958
|
+
type: "button",
|
|
2959
|
+
style: { ...chipBtn, textAlign: "left" },
|
|
2960
|
+
onClick: () => readPath(item.path),
|
|
2961
|
+
}, item.name + " · " + Math.round(Number(item.size || 0) / 1024) + " KB")))
|
|
2962
|
+
: null,
|
|
2963
|
+
dirErr ? h("div", { style: { ...hint, color: "#ff6b6b" } }, dirErr) : null)),
|
|
2964
|
+
|
|
2965
|
+
preview
|
|
2966
|
+
? h(FoldBox, {
|
|
2967
|
+
title: "这个包里大致有什么",
|
|
2968
|
+
defaultOpen: true,
|
|
2969
|
+
summary: [h(Tag, { color: preview.format === "hybrid" ? "#a855f7" : "#4C7DF0" }, fmt), h(Tag, null, (preview.plugins || 0) + " 个插件")],
|
|
2970
|
+
hint: "展开",
|
|
2971
|
+
collapsedNote: (preview.plugins || 0) + " 个插件" + (sum.configMode === "custom" ? " · " + sum.configCount + " 个带自定义配置" : " · 全部默认配置") + (sum.dataCount ? " · " + sum.dataCount + " 个带数据" : "") + (sum.redacted ? " · 擦除 " + sum.redacted + " 处凭据" : "") + "(点标题展开)",
|
|
2972
|
+
},
|
|
2973
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "4px" } },
|
|
2974
|
+
h("div", { style: row },
|
|
2975
|
+
h(Tag, { color: sum.configMode === "custom" ? "#ffb020" : "#2bb673" }, sum.configMode === "custom" ? "有自定义配置:" + sum.configCount + " 个" : "全部默认配置"),
|
|
2976
|
+
sum.dataCount ? h(Tag, { color: "#2bb673" }, "带数据:" + sum.dataCount + " 个") : h(Tag, null, "不带数据"),
|
|
2977
|
+
sum.redacted ? h(Tag, { color: "#ffb020" }, "擦除凭据:" + sum.redacted + " 处") : null,
|
|
2978
|
+
(sum.groups && sum.groups.length) ? h(Tag, { color: "#4C7DF0" }, "分组:" + sum.groups.join("、")) : null),
|
|
2979
|
+
h("div", { style: { ...hint, marginTop: "4px" } }, "每个插件默认都是「默认配置」;打包时单独选成「自定义配置」或带上了数据/凭据的,会在下面单独标出来。这里只数清单里的顶层插件,插件自己带的组件不算。"),
|
|
2980
|
+
pluginItems.length > 0
|
|
2981
|
+
? pluginItems.map((item) => h("div", { key: "pv-" + item.name }, pluginRow(item)))
|
|
2982
|
+
: h("div", { style: hint }, "清单里没有插件?这个包可能不是用本插件打的。")))
|
|
2983
|
+
: null,
|
|
2984
|
+
|
|
2985
|
+
preview
|
|
2986
|
+
? stepCard(3, "改一下词条", changed.length > 0 ? h(Tag, { color: "#4C7DF0" }, "将改 " + changed.length + " 项") : h(Tag, null, "不改"),
|
|
2987
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
2988
|
+
h("div", { style: hint }, "名称、作者、简介、主页如果改过,会写回包里的 dsh-modpack.json,再重算 sha256 与条目——目录里显示的、别人装到的都是改后的内容。"),
|
|
2989
|
+
h("div", { style: row },
|
|
2990
|
+
h("input", { style: { ...input, flex: "1 1 220px" }, placeholder: "名称", value: fields.name, onChange: (e) => setFields({ ...fields, name: e.target.value }) }),
|
|
2991
|
+
h("input", { style: { ...input, flex: "1 1 160px" }, placeholder: "作者", value: fields.author, onChange: (e) => setFields({ ...fields, author: e.target.value }) })),
|
|
2992
|
+
h("textarea", {
|
|
2993
|
+
style: { ...input, minHeight: "76px", resize: "vertical", padding: "6px 8px", lineHeight: "18px" },
|
|
2994
|
+
placeholder: "简介:这包是做什么的、适合谁",
|
|
2995
|
+
value: fields.description,
|
|
2996
|
+
onChange: (e) => setFields({ ...fields, description: e.target.value }),
|
|
2997
|
+
}),
|
|
2998
|
+
h("div", { style: row },
|
|
2999
|
+
h("input", { style: { ...input, flex: "1 1 240px" }, placeholder: "项目主页(可不填)", value: fields.homepage, onChange: (e) => setFields({ ...fields, homepage: e.target.value }) }),
|
|
3000
|
+
h("select", { style: { ...input, maxWidth: "200px" }, value: category, onChange: (e) => setCategory(e.target.value) },
|
|
3001
|
+
UPLOAD_CATEGORIES.map((name) => h("option", { key: "cat-" + name, value: name }, name)))),
|
|
3002
|
+
changed.length > 0
|
|
3003
|
+
? h("div", { style: { ...hint, color: "#4C7DF0" } }, "会改:" + changed.map((key) => (({ name: "名称", author: "作者", description: "简介", homepage: "主页" })[key])).join("、"))
|
|
3004
|
+
: h("div", { style: hint }, "没改任何一项:按包里的清单原样提交。")))
|
|
3005
|
+
: null,
|
|
3006
|
+
|
|
3007
|
+
stepCard(5, "封面图(可选)", h(Tag, null, cover ? "已裁好 " + coverSize + "×" + coverSize : (coverSrc ? "待裁切" : "没有封面")),
|
|
3008
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3009
|
+
h("div", { style: hint }, "PNG / JPG。先选图,再在框里拖动、缩放挑出要上传的部分;上传时只传框里这一块(输出 " + coverSize + "×" + coverSize + ",PNG,300 KB 以内)。它会出现在社区列表与详情里。"),
|
|
3010
|
+
h("div", { style: row },
|
|
3011
|
+
h("input", { ref: coverRef, type: "file", accept: "image/png,image/jpeg", style: { display: "none" }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (coverRef.current) coverRef.current.value = ""; pickCover(f) } }),
|
|
3012
|
+
h("button", { type: "button", style: btn, onClick: () => { if (coverRef.current) coverRef.current.click() } }, coverSrc ? "换一张" : "选择图片…"),
|
|
3013
|
+
h("span", { style: hint }, "规格"),
|
|
3014
|
+
h("select", { style: { ...input, maxWidth: "120px" }, value: String(coverSize), onChange: (e) => setCoverSize(Number(e.target.value)) },
|
|
3015
|
+
[256, 512].map((size) => h("option", { key: "cs-" + size, value: String(size) }, size + "×" + size))),
|
|
3016
|
+
cover ? h("button", { type: "button", style: btn, onClick: () => { setCover(""); setCoverSrc("") } }, "去掉") : null),
|
|
3017
|
+
coverSrc
|
|
3018
|
+
? h("div", { style: { display: "flex", gap: "12px", alignItems: "flex-start", flexWrap: "wrap" } },
|
|
3019
|
+
h("div", {
|
|
3020
|
+
ref: coverFrameRef,
|
|
3021
|
+
onPointerDown: coverDown,
|
|
3022
|
+
onPointerMove: coverMove,
|
|
3023
|
+
onPointerUp: coverUp,
|
|
3024
|
+
onPointerCancel: coverUp,
|
|
3025
|
+
style: { position: "relative", width: COVER_FRAME + "px", height: COVER_FRAME + "px", overflow: "hidden", borderRadius: "10px", border: "1px solid #4C7DF0", background: "#000", cursor: "grab", touchAction: "none", flex: "0 0 auto" },
|
|
3026
|
+
},
|
|
3027
|
+
h("img", {
|
|
3028
|
+
src: coverSrc,
|
|
3029
|
+
alt: "",
|
|
3030
|
+
draggable: false,
|
|
3031
|
+
style: coverImgStyle(),
|
|
3032
|
+
}),
|
|
3033
|
+
h("div", { style: { position: "absolute", inset: 0, border: "2px dashed rgba(255,255,255,0.55)", borderRadius: "10px", pointerEvents: "none" } })),
|
|
3034
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "6px", minWidth: "180px" } },
|
|
3035
|
+
h("div", { style: hint }, "拖动图片挑位置;下面的滑块放大 / 缩小。"),
|
|
3036
|
+
h("input", { type: "range", min: "1", max: "3", step: "0.01", value: String(coverZoom), onChange: (e) => setCoverZoom(Number(e.target.value)) }),
|
|
3037
|
+
h("div", { style: row },
|
|
3038
|
+
h("button", { type: "button", style: btnPrimary, onClick: applyCover }, "应用这块"),
|
|
3039
|
+
h("button", { type: "button", style: btn, onClick: resetCover }, "复位")),
|
|
3040
|
+
h("div", { style: hint }, "预览:" + (cover ? "已按上面框里那块生成 " + coverSize + "×" + coverSize + " 的图" : "还没应用"))))
|
|
3041
|
+
: null,
|
|
3042
|
+
cover ? h("div", { style: row },
|
|
3043
|
+
h("img", { src: cover, alt: "", style: { height: "52px", width: "52px", objectFit: "cover", borderRadius: "6px", border: "0.5px solid var(--dsw-alias-border-l2)" } }),
|
|
3044
|
+
h("span", { style: hint }, "上传的就是这一张(列表 42×42、详情 88×88 都按它缩)")) : null,
|
|
3045
|
+
coverErr ? h("div", { style: { ...hint, color: "#ff6b6b" } }, coverErr) : null,
|
|
3046
|
+
h("div", { style: { ...hint, color: "#ff6b6b" } }, "严禁上传与整合包无关、侵权或违规的图片:目录是公开的,图片会随条目一起公开显示。"))),
|
|
3047
|
+
|
|
3048
|
+
stepCard(6, "预览",
|
|
3049
|
+
h(Tag, null, localPack ? "已放进社区列表" : "还没预览"),
|
|
3050
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3051
|
+
h("div", { style: hint }, "预览不是在这里看:会把这份包当成社区里的一条放进「整合包」列表顶部,带橙色「测试预览」标记。点进去能走真实的下载到本地 / 下载并安装,但不会上传、不开 PR、不联网。"),
|
|
3052
|
+
h("div", { style: row },
|
|
3053
|
+
h("button", { type: "button", style: btn, disabled: previewBusy !== "" || busy !== "", onClick: previewLocal }, previewBusy === "preview" ? "准备中…" : "在列表里预览")))),
|
|
3054
|
+
|
|
3055
|
+
stepCard(4, "放在哪",
|
|
3056
|
+
h(Tag, null, host === "release" ? "Release 资产" : "目录仓库"),
|
|
3057
|
+
h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3058
|
+
h("div", { style: row },
|
|
3059
|
+
h("button", { type: "button", style: host === "repo" ? btnPrimary : btn, onClick: () => setHost("repo") }, "放进目录仓库"),
|
|
3060
|
+
h("button", { type: "button", style: host === "release" ? btnPrimary : btn, onClick: () => setHost("release") }, "放进我的 Release(真实下载量)")),
|
|
3061
|
+
host === "release"
|
|
3062
|
+
? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px" } },
|
|
3063
|
+
h("div", { style: hint }, "会传到你自己仓库的 Release 资产里(你必须有这个仓库的写权限)。目录构建时读它的 download_count,列表里就能显示真实下载次数。"),
|
|
3064
|
+
h("div", { style: row },
|
|
3065
|
+
h("input", { style: { ...input, flex: "1 1 240px" }, placeholder: "你的仓库:owner/name", value: repoInput, onChange: (e) => setRepoInput(e.target.value) }),
|
|
3066
|
+
h("input", { style: { ...input, maxWidth: "200px" }, placeholder: "tag(默认 packs-<id>)", value: tagInput, onChange: (e) => setTagInput(e.target.value) })))
|
|
3067
|
+
: h("div", { style: hint }, "放进目录仓库最简单:只有这一次 PR,不占你自己的仓库;缺点是没有逐文件下载计数,列表里显示「下载量未统计」。"),
|
|
3068
|
+
h("div", { style: hint }, "只收轻量包(无修改)和混合包(有自定义);完整包请放到发布页。"))),
|
|
3069
|
+
|
|
3070
|
+
h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px", borderColor: "#4C7DF0" } },
|
|
3071
|
+
h("div", { style: row },
|
|
3072
|
+
h("button", { type: "button", style: { ...btnPrimary, height: "32px", padding: "0 16px", fontSize: "13px" }, disabled: busy !== "" || !preview || !configured, onClick: () => submit(false) }, busy === "submit" ? "提交中…" : "确认上传(开 PR)"),
|
|
3073
|
+
h("button", { type: "button", style: { ...chipBtn, height: "32px", padding: "0 14px", fontSize: "13px" }, disabled: busy !== "" || !preview, title: "把整套检查跑一遍(类型、读包、封面、条目),但不碰 GitHub、不开 PR、不需要凭据", onClick: () => submit(true) }, busy === "dry" ? "演练中…" : "演练一次(不真上传)"),
|
|
3074
|
+
h("span", { style: hint }, configured ? (preview ? ("将提交:" + (fields.name || fileName) + " · " + category + " · " + (host === "release" ? "Release" : "目录仓库") + (changed.length ? " · 改 " + changed.length + " 项词条" : " · 词条不改")) : "先选一个包") : "先保存凭据")),
|
|
3075
|
+
h("div", { style: hint }, "提交后进入任务队列:进度显示在左下角悬浮窗,完成给「打开 PR」,卡住给「我已知晓」。")),
|
|
3076
|
+
|
|
3077
|
+
msg ? h("div", { style: { ...box, padding: "10px 12px", borderColor: "#2bb673", color: "#2bb673", fontSize: "12.5px", lineHeight: "19px" } }, msg) : null,
|
|
3078
|
+
error ? h("div", { style: { ...box, padding: "10px 12px", borderColor: "#ff6b6b", color: "#ff6b6b", fontSize: "12.5px", lineHeight: "19px" } }, error) : null)
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
// ===== [区块] 社区资源小插件:整合包浏览(列表 / 详情 / 上传规则) ====
|
|
3082
|
+
function ModpackBrowser(props) {
|
|
3083
|
+
const packSnap = readMarketUi().pack || {}
|
|
3084
|
+
const [view, setView] = useState(packSnap.view === "detail" || packSnap.view === "rules" || packSnap.view === "upload" ? packSnap.view : "list")
|
|
3085
|
+
const [summary, setSummary] = useState(packSnap.summary || null)
|
|
3086
|
+
const [items, setItems] = useState(Array.isArray(packSnap.items) ? packSnap.items : [])
|
|
3087
|
+
const [total, setTotal] = useState(Number(packSnap.total) || 0)
|
|
3088
|
+
const [page, setPage] = useState(Number(packSnap.page) || 1)
|
|
3089
|
+
const [hasMore, setHasMore] = useState(packSnap.hasMore === true)
|
|
3090
|
+
const [query, setQuery] = useState(typeof packSnap.query === "string" ? packSnap.query : "")
|
|
3091
|
+
const [category, setCategory] = useState(typeof packSnap.category === "string" ? packSnap.category : "all")
|
|
3092
|
+
const [sort, setSort] = useState(typeof packSnap.sort === "string" ? packSnap.sort : "new")
|
|
3093
|
+
const [loading, setLoading] = useState(!(packSnap.dataReady === true))
|
|
3094
|
+
const [searching, setSearching] = useState(false)
|
|
3095
|
+
const [syncing, setSyncing] = useState(false)
|
|
3096
|
+
const [error, setError] = useState("")
|
|
3097
|
+
const [msg, setMsg] = useState("")
|
|
3098
|
+
const [detail, setDetail] = useState(packSnap.detail || null)
|
|
3099
|
+
// 本机情况一律按「目录里的插件清单 × 本机已装」算:不下载包、不额外请求
|
|
3100
|
+
const packPlugins = (detail && Array.isArray(detail.plugins)) ? detail.plugins : []
|
|
3101
|
+
const installedNames = new Set((((props.status || {}).installed) || []).map((item) => item.name))
|
|
3102
|
+
const packMissing = packPlugins.filter((item) => !installedNames.has(item.name))
|
|
3103
|
+
const packInstalledCount = packPlugins.length - packMissing.length
|
|
3104
|
+
|
|
3105
|
+
// 本地预览:把还没上传的包当成社区里的一条,放在列表最上面(只在这台机器上模拟)
|
|
3106
|
+
const [previewPack, setPreviewPack] = useState(null)
|
|
3107
|
+
const openPreview = (pack) => {
|
|
3108
|
+
setPreviewPack(pack ? { ...pack, preview: true } : null)
|
|
3109
|
+
setDetail(null)
|
|
3110
|
+
setView("list")
|
|
3111
|
+
setMsg(pack ? "预览:这份包现在放在列表最上面(橙色「测试预览」标记),点进去能试下载与安装;它不会真的上传。" : "")
|
|
3112
|
+
}
|
|
3113
|
+
const [descOpen, setDescOpen] = useState(packSnap.descOpen !== false)
|
|
3114
|
+
const [descTick, setDescTick] = useState(0)
|
|
3115
|
+
const [downloading, setDownloading] = useState(false)
|
|
3116
|
+
const [reloadKey, setReloadKey] = useState(0)
|
|
3117
|
+
const [searchTick, setSearchTick] = useState(0)
|
|
3118
|
+
const mounted = useRef(true)
|
|
3119
|
+
useEffect(() => () => { mounted.current = false }, [])
|
|
3120
|
+
// 退出程序前一直留着:搜索框文字、分类、排序、页码、读到的列表、打开着的详情/规则页
|
|
3121
|
+
useEffect(() => {
|
|
3122
|
+
saveMarketUi("pack", { view, summary, items, total, page, hasMore, query, category, sort, detail, dataReady: true })
|
|
3123
|
+
}, [view, summary, items, total, page, hasMore, query, category, sort, detail])
|
|
3124
|
+
|
|
3125
|
+
|
|
3126
|
+
// 打开详情时补齐插件介绍:包里写了就用包里的,没写就问插件市场的目录
|
|
3127
|
+
useEffect(() => {
|
|
3128
|
+
if (view !== "detail" || !detail) return undefined
|
|
3129
|
+
const plugins = Array.isArray(detail.plugins) ? detail.plugins : []
|
|
3130
|
+
const missing = plugins
|
|
3131
|
+
.filter((plugin) => plugin && plugin.name && !(plugin.description && String(plugin.description).trim()) && !hasPluginDesc(plugin.name))
|
|
3132
|
+
.map((plugin) => plugin.name)
|
|
3133
|
+
if (missing.length === 0) return undefined
|
|
3134
|
+
let alive = true
|
|
3135
|
+
api("/catalog/lookup", { names: missing.slice(0, 200) })
|
|
3136
|
+
.then((data) => {
|
|
3137
|
+
if (!alive) return
|
|
3138
|
+
const items = (data && data.items) || {}
|
|
3139
|
+
let hit = 0
|
|
3140
|
+
for (const name of missing) {
|
|
3141
|
+
const item = items[name]
|
|
3142
|
+
// 市场里没有的也记一笔空值:下次打开这份详情不再重复问
|
|
3143
|
+
pluginDescCache.set(name, item && item.description ? item : { description: "" })
|
|
3144
|
+
if (item && item.description) hit += 1
|
|
3145
|
+
}
|
|
3146
|
+
if (hit > 0) setDescTick((n) => n + 1)
|
|
3147
|
+
})
|
|
3148
|
+
.catch(() => {})
|
|
3149
|
+
return () => { alive = false }
|
|
3150
|
+
}, [view, detail])
|
|
3151
|
+
|
|
3152
|
+
const pluginDescOf = (plugin) => {
|
|
3153
|
+
if (plugin.description && String(plugin.description).trim()) return String(plugin.description)
|
|
3154
|
+
const cached = cachedPluginDesc(plugin.name)
|
|
3155
|
+
if (cached) return cached
|
|
3156
|
+
return "插件市场里没有它的介绍。"
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
const applyData = (data) => {
|
|
3160
|
+
if (!data) return
|
|
3161
|
+
if (data.summary) setSummary(data.summary)
|
|
3162
|
+
setItems(Array.isArray(data.items) ? data.items : [])
|
|
3163
|
+
setTotal(Number(data.total) || 0)
|
|
3164
|
+
setHasMore(Boolean(data.hasMore))
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
const restoredPack = useRef(packSnap.dataReady === true)
|
|
3168
|
+
useEffect(() => {
|
|
3169
|
+
if (restoredPack.current) { restoredPack.current = false; return undefined }
|
|
3170
|
+
let alive = true
|
|
3171
|
+
setLoading(true)
|
|
3172
|
+
api("/market").then((data) => {
|
|
3173
|
+
if (!alive) return
|
|
3174
|
+
applyData(data)
|
|
3175
|
+
setError("")
|
|
3176
|
+
}).catch((e) => { if (alive) setError((e && e.message) || String(e)) }).finally(() => { if (alive) setLoading(false) })
|
|
3177
|
+
return () => { alive = false }
|
|
3178
|
+
}, [reloadKey])
|
|
3179
|
+
|
|
3180
|
+
const retry = () => { setError(""); setMsg(""); setLoading(true); setReloadKey((n) => n + 1) }
|
|
3181
|
+
|
|
3182
|
+
// 搜索 / 分类 / 排序都走服务端分页:客户端只拿一页,目录再大也不卡
|
|
3183
|
+
const skipFirstSearch = useRef(packSnap.dataReady === true)
|
|
3184
|
+
useEffect(() => {
|
|
3185
|
+
if (loading) return undefined
|
|
3186
|
+
// 回来时上次的列表还在,没必要为同一组条件再查一遍
|
|
3187
|
+
if (skipFirstSearch.current) { skipFirstSearch.current = false; return undefined }
|
|
3188
|
+
let alive = true
|
|
3189
|
+
const timer = setTimeout(() => {
|
|
3190
|
+
setSearching(true)
|
|
3191
|
+
api("/market/search", { query, category, sort, page: 1, pageSize: 20 })
|
|
3192
|
+
.then((data) => { if (alive) { applyData(data); setError(data && data.ok === false ? (data.error || "") : "") } })
|
|
3193
|
+
.catch((e) => { if (alive) setError((e && e.message) || String(e)) })
|
|
3194
|
+
.finally(() => { if (alive) setSearching(false) })
|
|
3195
|
+
}, 240)
|
|
3196
|
+
return () => { alive = false; clearTimeout(timer) }
|
|
3197
|
+
}, [query, category, sort, searchTick])
|
|
3198
|
+
|
|
3199
|
+
const loadMore = async () => {
|
|
3200
|
+
if (!hasMore || searching) return
|
|
3201
|
+
setSearching(true)
|
|
3202
|
+
try {
|
|
3203
|
+
const data = await api("/market/search", { query, category, sort, page: page + 1, pageSize: 20 })
|
|
3204
|
+
if (data && data.ok) {
|
|
3205
|
+
setItems((prev) => prev.concat(data.items))
|
|
3206
|
+
setPage(page + 1)
|
|
3207
|
+
setHasMore(Boolean(data.hasMore))
|
|
3208
|
+
}
|
|
3209
|
+
} catch (e) {
|
|
3210
|
+
setError((e && e.message) || String(e))
|
|
3211
|
+
} finally {
|
|
3212
|
+
setSearching(false)
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
const syncNow = async () => {
|
|
3217
|
+
setSyncing(true); setError(""); setMsg("")
|
|
3218
|
+
try {
|
|
3219
|
+
const data = await api("/market/sync", { force: true })
|
|
3220
|
+
if (data && data.ok) { applyData(data); setMsg("目录已更新") } else { setError((data && data.error) || "更新失败") }
|
|
3221
|
+
} catch (e) {
|
|
3222
|
+
setError((e && e.message) || String(e))
|
|
3223
|
+
} finally {
|
|
3224
|
+
setSyncing(false)
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
const download = async (pack, saveOnly) => {
|
|
3229
|
+
setDownloading(true); setError(""); setMsg("")
|
|
3230
|
+
try {
|
|
3231
|
+
const data = await api("/market/download", saveOnly ? { id: pack.id, saveOnly: true } : { id: pack.id })
|
|
3232
|
+
if (saveOnly) {
|
|
3233
|
+
if (!data || data.ok !== true) { setError((data && data.error) || "下载失败"); return }
|
|
3234
|
+
setMsg("已下到本机:" + (data.savedName || pack.name) + "(在插件自己的 packs 目录,安装页「已下载的整合包」里能选到)")
|
|
3235
|
+
return
|
|
3236
|
+
}
|
|
3237
|
+
if (!data || data.ok !== true) { setError((data && data.error) || "下载失败"); return }
|
|
3238
|
+
requestInstall({ token: data.token, fileName: data.fileName, packName: pack.name })
|
|
3239
|
+
setMsg("已下载并读取:" + pack.name + (data && data.savedName ? "(也存了一份:" + data.savedName + ")" : "") + ",正在转到安装页")
|
|
3240
|
+
if (typeof props.onGoInstall === "function") props.onGoInstall()
|
|
3241
|
+
} catch (e) {
|
|
3242
|
+
setError((e && e.message) || String(e))
|
|
3243
|
+
} finally {
|
|
3244
|
+
setDownloading(false)
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// 封面:目录条目里存 covers/<id>.png 这种相对路径,这里拼 CDN(取不到就看 raw)
|
|
3249
|
+
const coverUrl = (pack) => {
|
|
3250
|
+
const rel = pack && typeof pack.cover === "string" ? pack.cover.trim() : ""
|
|
3251
|
+
if (!rel) return ""
|
|
3252
|
+
if (rel.startsWith("data:image/")) return rel
|
|
3253
|
+
const repo = (pack && pack.repo) || ((props.status || {}).modpackMarket || {}).repo || "Vesna-Strivozha-cn/dsh-modpack-catalog"
|
|
3254
|
+
return "https://cdn.jsdelivr.net/gh/" + repo + "@main/" + rel.split("/").map(encodeURIComponent).join("/")
|
|
3255
|
+
}
|
|
3256
|
+
const coverImg = (pack, size) => {
|
|
3257
|
+
const url = coverUrl(pack)
|
|
3258
|
+
if (!url) return null
|
|
3259
|
+
return h("img", {
|
|
3260
|
+
src: url,
|
|
3261
|
+
alt: "",
|
|
3262
|
+
style: { width: size + "px", height: size + "px", borderRadius: "6px", objectFit: "cover", border: "0.5px solid var(--dsw-alias-border-l2)", flex: "0 0 auto" },
|
|
3263
|
+
})
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
// 分类英文名(目录里只存中文 label,英文界面在这里映射)
|
|
3267
|
+
const catLabel = (name) => name
|
|
3268
|
+
const CATEGORY_TINT = { 工作办公: "#4C7DF0", 性能优化: "#2bb673", 界面美化: "#a855f7", 实用功能: "#0ea5e9", 开发调试: "#f59e0b", 娱乐休闲: "#ec4899", 学习资料: "#14b8a6", 水槽: "#7c3aed", 其它: "#64748b" }
|
|
3269
|
+
const initialsOf = (name) => String(name || "?").replace(/\s+/gu, "").slice(0, 2) || "?"
|
|
3270
|
+
// 体量词条:不靠作者写,按插件总数自动算(0-3 轻量 / 4-8 中型 / 9-12 大型 / 13+ 大宗)
|
|
3271
|
+
const TIER_LABELS = { small: "轻量", medium: "中型", large: "大型", huge: "大宗" }
|
|
3272
|
+
const TIER_COLORS = { small: "#2bb673", medium: "#0ea5e9", large: "#f59e0b", huge: "#ec4899" }
|
|
3273
|
+
const tierInfo = (pack) => {
|
|
3274
|
+
const count = Array.isArray(pack.plugins) ? pack.plugins.length : 0
|
|
3275
|
+
const id = pack.tier || (count >= 13 ? "huge" : count >= 9 ? "large" : count >= 4 ? "medium" : "small")
|
|
3276
|
+
return { id, color: TIER_COLORS[id] || "#64748b", text: TIER_LABELS[id] || "轻量" }
|
|
3277
|
+
}
|
|
3278
|
+
const tierTag = (pack) => {
|
|
3279
|
+
const info = tierInfo(pack)
|
|
3280
|
+
return h("span", { key: "tier-" + pack.id, style: { ...hint, color: info.color, border: "0.5px solid " + info.color, borderRadius: "99px", padding: "0 6px", lineHeight: "16px" } }, info.text)
|
|
3281
|
+
}
|
|
3282
|
+
const categories = (summary && summary.categories) || []
|
|
3283
|
+
const chips = [{ id: "all", label: "全部", count: (summary && summary.count) || 0 }].concat(
|
|
3284
|
+
categories.map((c) => ({ id: c.label, label: catLabel(c.label), count: c.count || 0 })),
|
|
3285
|
+
)
|
|
3286
|
+
const present = Boolean(summary && summary.present)
|
|
3287
|
+
const sizeText = (bytes) => (bytes >= 1024 * 1024 ? Math.round((bytes / 1024 / 1024) * 10) / 10 + " MB" : Math.max(1, Math.round(bytes / 1024)) + " KB")
|
|
3288
|
+
const compact = (value) => {
|
|
3289
|
+
const n = Number(value) || 0
|
|
3290
|
+
return n >= 10000 ? (n / 10000).toFixed(1) + " 万" : String(n)
|
|
3291
|
+
}
|
|
3292
|
+
// 目录里没有图片资源,就用名字前两个字做一块底色方块,跟 PCL 那种「占位图标」一个意思
|
|
3293
|
+
const descOf = (pack) => {
|
|
3294
|
+
const d = (pack && pack.description) || {}
|
|
3295
|
+
const text = d.zh || d.en
|
|
3296
|
+
return text || "作者没写说明。"
|
|
3297
|
+
}
|
|
3298
|
+
const renderRow = (pack) => {
|
|
3299
|
+
const tint = CATEGORY_TINT[pack.category] || "#64748b"
|
|
3300
|
+
const plugins = pack.plugins || []
|
|
3301
|
+
const meta = []
|
|
3302
|
+
meta.push(plugins.length + " 个插件")
|
|
3303
|
+
meta.push(sizeText(pack.size))
|
|
3304
|
+
meta.push(pack.downloads === null || pack.downloads === undefined ? "下载量未统计" : "下载 " + compact(pack.downloads))
|
|
3305
|
+
if (pack.updatedAt) meta.push("更新 " + String(pack.updatedAt).slice(0, 10))
|
|
3306
|
+
else if (pack.createdAt) meta.push("创建 " + String(pack.createdAt).slice(0, 10))
|
|
3307
|
+
if (pack.author) meta.push("作者 " + pack.author)
|
|
3308
|
+
return h("div", {
|
|
3309
|
+
key: "pack-" + pack.id,
|
|
3310
|
+
onClick: () => { setDetail(pack); setView("detail"); setError(""); setMsg("") },
|
|
3311
|
+
style: { display: "flex", gap: "10px", padding: "10px 12px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", cursor: "pointer", alignItems: "flex-start" },
|
|
3312
|
+
},
|
|
3313
|
+
coverImg(pack, 42) || h("div", {
|
|
3314
|
+
style: {
|
|
3315
|
+
width: "42px", height: "42px", flexShrink: 0, borderRadius: "8px",
|
|
3316
|
+
background: tint, color: "#fff", fontSize: "13px", fontWeight: 600,
|
|
3317
|
+
display: "flex", alignItems: "center", justifyContent: "center", letterSpacing: "0.5px",
|
|
3318
|
+
},
|
|
3319
|
+
}, initialsOf(pack.name)),
|
|
3320
|
+
h("div", { style: { flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: "3px" } },
|
|
3321
|
+
h("div", { style: row },
|
|
3322
|
+
h("span", { style: { fontWeight: 600, fontSize: "13.5px" } }, pack.name),
|
|
3323
|
+
h(Tag, null, catLabel(pack.category || "其它")),
|
|
3324
|
+
tierTag(pack),
|
|
3325
|
+
h(Tag, { title: pack.customization === "custom" ? "这份包带着作者本地的配置或改动" : "只记版本,没有任何本地改动" }, pack.customization === "custom" ? "有自定义" : "无修改"),
|
|
3326
|
+
pack.version ? h(Tag, null, "v" + pack.version) : null,
|
|
3327
|
+
pack.preview ? h(Tag, { color: "#f59e0b", title: "只在这台机器上模拟,没有上传" }, "测试预览") : null,
|
|
3328
|
+
),
|
|
3329
|
+
h("span", { style: { ...hint, display: "-webkit-box", WebkitLineClamp: 2, WebkitBoxOrient: "vertical", overflow: "hidden", lineHeight: "18px" } }, descOf(pack)),
|
|
3330
|
+
pack.preview ? h("span", { style: { ...hint, color: "#b45309" } }, "测试预览 · 没上传,也没开 PR") : null,
|
|
3331
|
+
h("div", { style: { ...row, gap: "14px" } }, meta.map((line, index) => h("span", { key: "meta-" + pack.id + "-" + index, style: hint }, line)))))
|
|
3332
|
+
}
|
|
3333
|
+
const rows = previewPack ? [previewPack].concat(items.filter((item) => item.id !== previewPack.id)) : items
|
|
3334
|
+
const resetFilters = () => { setQuery(""); setCategory("all"); setSort("new"); setPage(1); setSearchTick((n) => n + 1) }
|
|
3335
|
+
|
|
3336
|
+
const head = h("div", { style: { ...row, justifyContent: "space-between" } },
|
|
3337
|
+
h("div", { style: row },
|
|
3338
|
+
h("span", { style: { ...strong, fontSize: "14px" } }, "社区资源"),
|
|
3339
|
+
present ? h(Tag, null, total + " 个") : null,
|
|
3340
|
+
present ? h("span", { style: hint }, "目录来自 " + (summary.repo || "dsh-modpack-catalog") + (summary.builtAt ? " · 构建于 " + String(summary.builtAt).slice(0, 10) : "")) : null),
|
|
3341
|
+
h("div", { style: row },
|
|
3342
|
+
h("button", { type: "button", style: chipBtn, onClick: () => { setView("upload"); setDetail(null) } }, "上传我的整合包"),
|
|
3343
|
+
h("button", { type: "button", style: chipBtn, onClick: () => { setView("rules"); setDetail(null) } }, "上传方式与规则"),
|
|
3344
|
+
h("button", { type: "button", style: chipBtn, disabled: syncing, onClick: syncNow }, syncing ? "更新中…" : "更新目录")))
|
|
3345
|
+
|
|
3346
|
+
if (view === "upload") {
|
|
3347
|
+
return h(UploadPanel, { onBack: () => setView("list"), onPreview: openPreview })
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
if (view === "rules") {
|
|
3351
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
3352
|
+
h("div", { style: row },
|
|
3353
|
+
h("button", { type: "button", style: chipBtn, onClick: () => setView("list") }, "← 返回市场"),
|
|
3354
|
+
h("span", { style: { ...strong, fontSize: "14px" } }, "上传方式与规则")),
|
|
3355
|
+
h("div", { style: { ...hint, lineHeight: "20px" } }, "收轻量包(无修改)与混合包(有自定义);审核与出问题下架都靠 PR 与 issue,和插件市场一样。"),
|
|
3356
|
+
h("ol", { style: { margin: 0, paddingLeft: "18px", display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3357
|
+
MARKET_RULES.map((line, index) => h("li", { key: "rule-" + index, style: { fontSize: "12.5px", lineHeight: "19px" } }, line))),
|
|
3358
|
+
h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "8px", padding: "10px", display: "flex", flexDirection: "column", gap: "4px" } },
|
|
3359
|
+
h("span", { style: strong }, "清单长这样"),
|
|
3360
|
+
h("code", { style: { fontSize: "11.5px", whiteSpace: "pre-wrap", lineHeight: "17px" } },
|
|
3361
|
+
'{\n "id": "bili-trio",\n "category": "实用功能",\n "file": "bili-trio-lite.dshpack",\n "sha256": "…64 位…",\n "createdAt": "2026-11-27",\n "updatedAt": "2026-11-27",\n "homepage": ""\n}\n\n// 名称、作者、介绍、插件清单不写在这里:\n// 全部取包里的 dsh-modpack.json(打包时填的)')),
|
|
3362
|
+
h("div", { style: hint }, "仓库:github.com/" + (summary && summary.repo ? summary.repo : "Vesna-Strivozha-cn/dsh-modpack-catalog") + " · 照着上面 1~5 步走:包进 packs/、清单进 data/packs/、本地 build 过了再提 PR;合并后每天 03:17 UTC 重建,也可以在 Actions 手动 Run workflow。"))
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
if (view === "detail" && detail) {
|
|
3366
|
+
const pack = detail
|
|
3367
|
+
const plugins = pack.plugins || []
|
|
3368
|
+
const downloadCode = [pack.url || "", "sha256: " + (pack.sha256 || ""), "size: " + pack.size + " 字节"].join("\n")
|
|
3369
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
3370
|
+
h("div", { style: row },
|
|
3371
|
+
h("button", { type: "button", style: chipBtn, onClick: () => { setView("list"); setDetail(null) } }, "← 返回列表"),
|
|
3372
|
+
h("span", { style: { ...strong, fontSize: "15px" } }, pack.name),
|
|
3373
|
+
h(Tag, null, catLabel(pack.category || "其它")),
|
|
3374
|
+
tierTag(pack),
|
|
3375
|
+
h(Tag, { title: pack.customization === "custom" ? "这份包带着作者本地的配置或改动" : "只记版本,没有任何本地改动" }, pack.customization === "custom" ? "有自定义" : "无修改"),
|
|
3376
|
+
pack.preview ? h(Tag, { color: "#f59e0b", title: "只在这台机器上模拟,没有上传" }, "测试预览") : null,
|
|
3377
|
+
h("span", { style: hint }, (pack.version ? "v" + pack.version + " · " : "") + "作者 " + (pack.author || "?") + " · " + sizeText(pack.size) + " · " + plugins.length + " 个插件")),
|
|
3378
|
+
coverImg(pack, 88) || null,
|
|
3379
|
+
h("div", { style: { ...hint, lineHeight: "20px" } },
|
|
3380
|
+
pack.downloads === null || pack.downloads === undefined
|
|
3381
|
+
? "下载量:暂无统计(安装文件放在 Git 仓库里,没有逐文件计数;放进 GitHub Release 资源才拿得到真实下载数)"
|
|
3382
|
+
: "下载 " + Number(pack.downloads) + " 次(这个安装文件本身的下载量,不是里面插件的)"
|
|
3383
|
+
+ " · 创建 " + (pack.createdAt ? String(pack.createdAt).slice(0, 10) : "未记录")
|
|
3384
|
+
+ " · 上次更新 " + (pack.updatedAt ? String(pack.updatedAt).slice(0, 10) : (pack.createdAt ? String(pack.createdAt).slice(0, 10) : "未记录"))),
|
|
3385
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3386
|
+
h("span", { style: strong }, "这个整合包是做什么的"),
|
|
3387
|
+
h("div", { style: { fontSize: "12.5px", lineHeight: "20px" } }, descOf(pack)),
|
|
3388
|
+
),
|
|
3389
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "6px" } },
|
|
3390
|
+
h("div", { style: row },
|
|
3391
|
+
h("span", { style: strong }, "本机情况"),
|
|
3392
|
+
h(Tag, { title: "只数包里清单列的顶层插件;壁纸引擎那类组件不算" }, "已装 " + packInstalledCount + " / " + packPlugins.length),
|
|
3393
|
+
packMissing.length
|
|
3394
|
+
? h(Tag, { title: "这些插件在你本机还没装" }, "缺 " + packMissing.length + " 个")
|
|
3395
|
+
: h("span", { style: { ...hint, color: "#2bb673" } }, "都装了")),
|
|
3396
|
+
packMissing.length
|
|
3397
|
+
? h("div", { style: { fontSize: "12.5px", lineHeight: "19px" } }, "本机还没装:" + packMissing.map((item) => item.name + (item.latest !== false ? "(装的时候取市场最新)" : (item.version ? "@" + item.version : ""))).join("、"))
|
|
3398
|
+
: h("div", { style: { ...hint, color: "#2bb673" } }, "包里的插件本机都有,无需安装"),
|
|
3399
|
+
detail.hasSpecialConfig
|
|
3400
|
+
? h("div", { style: { fontSize: "12.5px", lineHeight: "19px" } }, "包里带了特殊配置:" + (detail.configPlugins || []).map((item) => item.name + "(" + item.keys + " 个键)").join("、") + ";安装时可以选择「包内配置」或「保持本机」。")
|
|
3401
|
+
: h("div", { style: hint }, "包里没有单独的配置改动:插件都用各自的默认配置。"),
|
|
3402
|
+
detail.hasData ? h("div", { style: hint }, "还带着数据快照(安装时默认不覆盖你已有的文件,会问你要不要写回)。") : null,
|
|
3403
|
+
detail.redactedTotal ? h("div", { style: hint }, "其中 " + detail.redactedTotal + " 处疑似凭据已被替换成 ${REDACTED},装完要自己重填。") : null,
|
|
3404
|
+
detail.groups && detail.groups.length ? h("div", { style: hint }, "带了分组:" + detail.groups.join("、") + "(本机装了插件市场就并进同名组)") : null),
|
|
3405
|
+
h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "6px" } },
|
|
3406
|
+
h("div", { style: { ...row, justifyContent: "space-between" } },
|
|
3407
|
+
h("span", { style: strong }, "包含的插件(这些插件会干什么)"),
|
|
3408
|
+
plugins.length === 0 ? null : h("button", {
|
|
3409
|
+
type: "button",
|
|
3410
|
+
style: chipBtn,
|
|
3411
|
+
title: descOpen ? "只留插件名与版本" : "显示每个插件在插件市场里的介绍",
|
|
3412
|
+
onClick: () => setDescOpen(!descOpen),
|
|
3413
|
+
}, descOpen ? "收起介绍" : "显示介绍")),
|
|
3414
|
+
plugins.length === 0
|
|
3415
|
+
? h("span", { style: hint }, "清单里没有插件记录。")
|
|
3416
|
+
: plugins.map((plugin) => h("div", { key: "p-" + plugin.name, style: { display: "flex", flexDirection: "column", gap: "2px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "6px" } },
|
|
3417
|
+
h("div", { style: row },
|
|
3418
|
+
h("span", { style: { fontSize: "12.5px", fontWeight: 600 } }, plugin.name),
|
|
3419
|
+
h(Tag, null, plugin.version ? "@" + plugin.version : "@市场最新")),
|
|
3420
|
+
descOpen ? h("span", { style: hint }, pluginDescOf(plugin)) : null)),
|
|
3421
|
+
h("span", { style: hint }, "安装时按上面的版本从插件市场取包;取不到就明确报错,不会拿别的东西顶替。"),
|
|
3422
|
+
h("span", { style: hint }, "这里只数清单里的顶层插件;像壁纸引擎那样由插件自己带的一组组件不算在里面,装好后由那个插件自己管理。")),
|
|
3423
|
+
h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "6px" } },
|
|
3424
|
+
h("span", { style: strong }, "下载码"),
|
|
3425
|
+
h("code", { style: { fontSize: "11.5px", whiteSpace: "pre-wrap", lineHeight: "17px", wordBreak: "break-all" } }, downloadCode),
|
|
3426
|
+
h("span", { style: hint }, "下载码就是包的直链 + sha256:谁拿到都能自己下载核对,不依赖这个界面。")),
|
|
3427
|
+
error ? h("div", { style: { ...hint, color: "#ff6b6b" } }, error) : null,
|
|
3428
|
+
msg ? h("div", { style: hint }, msg) : null,
|
|
3429
|
+
h("div", { style: row },
|
|
3430
|
+
h("button", { type: "button", style: btn, disabled: downloading, onClick: () => download(pack, true) }, downloading ? "下载中…" : "下载到本地"),
|
|
3431
|
+
h("button", { type: "button", style: btnPrimary, disabled: downloading, onClick: () => download(pack, false) }, downloading ? "下载中…" : "下载并安装"),
|
|
3432
|
+
h("span", { style: hint }, "下载后在内存里校验 sha256、跑一遍安全检测,再转到安装页读取;半成品不会留在磁盘上。")))
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
const searchCard = h("div", {
|
|
3436
|
+
style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "10px" },
|
|
3437
|
+
},
|
|
3438
|
+
h("div", { style: { ...row, justifyContent: "space-between" } },
|
|
3439
|
+
h("span", { style: { ...strong, fontSize: "13px" } }, "搜索整合包"),
|
|
3440
|
+
h("span", { style: hint }, "目录里现在有 " + ((summary && summary.count) || 0) + " 个" + (summary && summary.builtAt ? " · 构建于 " + String(summary.builtAt).slice(0, 10) : ""))),
|
|
3441
|
+
h("div", { style: { display: "grid", gridTemplateColumns: "56px minmax(160px, 1fr) 56px 150px 56px 130px", gap: "8px 10px", alignItems: "center" } },
|
|
3442
|
+
h("span", { style: hint }, "名称"),
|
|
3443
|
+
h("input", {
|
|
3444
|
+
type: "search",
|
|
3445
|
+
value: query,
|
|
3446
|
+
placeholder: "整合包名 / 作者 / 插件名(例如 B站、壁纸、记忆)",
|
|
3447
|
+
onChange: (event) => { setQuery(event.target.value); setPage(1) },
|
|
3448
|
+
style: { height: "30px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "inherit", padding: "0 8px", fontSize: "12.5px" },
|
|
3449
|
+
}),
|
|
3450
|
+
h("span", { style: hint }, "类型"),
|
|
3451
|
+
h("select", {
|
|
3452
|
+
value: category,
|
|
3453
|
+
onChange: (event) => { setCategory(event.target.value); setPage(1) },
|
|
3454
|
+
style: { height: "30px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "inherit", fontSize: "12.5px" },
|
|
3455
|
+
}, chips.map((chip) => h("option", { key: "sel-" + chip.id, value: chip.id }, chip.label + "(" + (chip.count || 0) + ")"))),
|
|
3456
|
+
h("span", { style: hint }, "排序"),
|
|
3457
|
+
h("select", {
|
|
3458
|
+
value: sort,
|
|
3459
|
+
onChange: (event) => { setSort(event.target.value); setPage(1) },
|
|
3460
|
+
style: { height: "30px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "inherit", fontSize: "12.5px" },
|
|
3461
|
+
}, MARKET_SORTS.map(([value, text]) => h("option", { key: value, value }, text)))),
|
|
3462
|
+
h("div", { style: row },
|
|
3463
|
+
h("button", { type: "button", style: { ...btn, minWidth: "96px" }, disabled: searching, onClick: () => setSearchTick((n) => n + 1) }, searching ? "搜索中…" : "搜索"),
|
|
3464
|
+
h("button", { type: "button", style: { ...btn, minWidth: "96px" }, onClick: resetFilters }, "重置条件"),
|
|
3465
|
+
h("button", { type: "button", style: { ...btn, minWidth: "128px" }, onClick: () => { if (typeof props.onGoInstall === "function") props.onGoInstall() } }, "安装已有整合包"),
|
|
3466
|
+
h("span", { style: { ...hint, marginLeft: "auto" } }, "共 " + total + " 个")))
|
|
3467
|
+
|
|
3468
|
+
const emptyCard = h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "16px", display: "flex", flexDirection: "column", gap: "8px" } },
|
|
3469
|
+
h("span", { style: strong }, query ? "没有匹配的整合包" : present ? "这个类型下还没有整合包" : "还没有整合包目录"),
|
|
3470
|
+
h("span", { style: hint }, query
|
|
3471
|
+
? "换个说法试试:整合包名、作者名、插件名都能搜。"
|
|
3472
|
+
: present
|
|
3473
|
+
? "目录是通的,只是这一类还没有人提交;换个类型看看,或去「上传方式与规则」自己提交一个。"
|
|
3474
|
+
: "第一次用要先从目录仓库拉一次清单(只有几百 KB)。"),
|
|
3475
|
+
h("div", { style: row },
|
|
3476
|
+
query ? h("button", { type: "button", style: btn, onClick: resetFilters }, "清空条件") : null,
|
|
3477
|
+
h("button", { type: "button", style: { ...btn, minWidth: "96px" }, disabled: syncing || loading, onClick: syncNow }, syncing ? "更新中…" : "更新目录"),
|
|
3478
|
+
h("button", { type: "button", style: btn, disabled: loading, onClick: retry }, "重试"),
|
|
3479
|
+
h("button", { type: "button", style: chipBtn, onClick: () => { setView("rules"); setDetail(null) } }, "上传方式与规则")),
|
|
3480
|
+
/重启|HTTP 40[45]|连不上/u.test(String(error || ""))
|
|
3481
|
+
? h("span", { style: { ...hint, lineHeight: "19px" } }, "网络正常但接口报 404/405 的话,是宿主还跑着旧代码:把 DSH 完全退出再打开,这一栏就会生效。")
|
|
3482
|
+
: null)
|
|
3483
|
+
|
|
3484
|
+
const listBox = rows.length > 0
|
|
3485
|
+
? h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", overflow: "hidden" } },
|
|
3486
|
+
previewPack
|
|
3487
|
+
? h("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "7px 12px", background: "#fff7ed", borderBottom: "0.5px solid #fed7aa", color: "#b45309", fontSize: "11.5px" } },
|
|
3488
|
+
h(Tag, { color: "#f59e0b" }, "测试预览"),
|
|
3489
|
+
h("span", null, "这一条只在本机模拟:没上传、没开 PR,也不会出现在别人的社区列表里"),
|
|
3490
|
+
h("button", { type: "button", style: chipBtn, onClick: () => { setPreviewPack(null); setMsg("") } }, "移除预览"))
|
|
3491
|
+
: null,
|
|
3492
|
+
rows.map(renderRow))
|
|
3493
|
+
: null
|
|
3494
|
+
|
|
3495
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
|
|
3496
|
+
head,
|
|
3497
|
+
searchCard,
|
|
3498
|
+
loading && items.length === 0 ? h("div", { style: { ...hint, padding: "14px 2px" } }, "正在读取整合包目录…") : null,
|
|
3499
|
+
error ? h("div", { style: { ...hint, color: "#ff6b6b", lineHeight: "19px" } }, String(error)) : null,
|
|
3500
|
+
msg ? h("div", { style: hint }, msg) : null,
|
|
3501
|
+
listBox,
|
|
3502
|
+
!loading && rows.length === 0 ? emptyCard : null,
|
|
3503
|
+
hasMore ? h("button", { type: "button", style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : "加载更多") : null)
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
// ===== [区块] 外壳:页签、刷新、彩蛋、进度窗挂载:Home =====
|
|
2104
3507
|
function Home(props) {
|
|
2105
|
-
const [tab, setTab] = useState(
|
|
3508
|
+
const [tab, setTab] = useState(() => {
|
|
3509
|
+
const saved = readPageUi().tab
|
|
3510
|
+
return PAGE_TABS.includes(saved) ? saved : "pack"
|
|
3511
|
+
})
|
|
3512
|
+
useEffect(() => { setPageUi("tab", tab) }, [tab])
|
|
2106
3513
|
const jobs = useJobs()
|
|
2107
3514
|
const status = props.status
|
|
2108
3515
|
const surface = (props && props.surface) || "sidebar"
|
|
@@ -2141,6 +3548,9 @@ window.__ModuleLoader__.load({
|
|
|
2141
3548
|
return () => { alive = false }
|
|
2142
3549
|
}, [forceHideMarket])
|
|
2143
3550
|
useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
|
|
3551
|
+
// 「社区资源」这一栏开不开:用模块级状态,设置里一关标签立刻消失,切回设置也不会又亮着
|
|
3552
|
+
const [marketOn, setMarketOn] = useState(() => readMarketVisible())
|
|
3553
|
+
useEffect(() => subscribeMarketVisible((on) => { setMarketOn(on) }), [])
|
|
2144
3554
|
const savePackResult = (value) => {
|
|
2145
3555
|
setPackValue(value)
|
|
2146
3556
|
setPackResult(value)
|
|
@@ -2189,14 +3599,47 @@ window.__ModuleLoader__.load({
|
|
|
2189
3599
|
title: "把进度窗叫回右下角的默认位置(拖到角落挡住了界面就用这个)",
|
|
2190
3600
|
onClick: () => { requestDockReset() },
|
|
2191
3601
|
}, "召回进度窗")
|
|
3602
|
+
const [eggMsg, setEggMsg] = useState("")
|
|
3603
|
+
const eggClicks = useRef([])
|
|
3604
|
+
const eggTimer = useRef(0)
|
|
3605
|
+
useEffect(() => () => { if (eggTimer.current) clearTimeout(eggTimer.current) }, [])
|
|
3606
|
+
const spotEgg = () => {
|
|
3607
|
+
const now = Date.now()
|
|
3608
|
+
eggClicks.current = eggClicks.current.concat(now).filter((at) => now - at < 1500)
|
|
3609
|
+
if (eggClicks.current.length < 5) return
|
|
3610
|
+
eggClicks.current = []
|
|
3611
|
+
setEggMsg("不不不,我资源无疑是贫乏的")
|
|
3612
|
+
if (eggTimer.current) clearTimeout(eggTimer.current)
|
|
3613
|
+
eggTimer.current = setTimeout(() => { eggTimer.current = 0; setEggMsg("") }, 1000)
|
|
3614
|
+
}
|
|
3615
|
+
const eggNode = eggMsg
|
|
3616
|
+
? h("div", {
|
|
3617
|
+
style: {
|
|
3618
|
+
position: "fixed",
|
|
3619
|
+
left: "50%",
|
|
3620
|
+
bottom: "88px",
|
|
3621
|
+
transform: "translateX(-50%)",
|
|
3622
|
+
background: "rgba(18, 20, 26, 0.92)",
|
|
3623
|
+
color: "#fff",
|
|
3624
|
+
padding: "9px 16px",
|
|
3625
|
+
borderRadius: "10px",
|
|
3626
|
+
fontSize: "13px",
|
|
3627
|
+
letterSpacing: "0.02em",
|
|
3628
|
+
boxShadow: "0 8px 24px rgba(0, 0, 0, 0.28)",
|
|
3629
|
+
pointerEvents: "none",
|
|
3630
|
+
zIndex: 80,
|
|
3631
|
+
},
|
|
3632
|
+
}, eggMsg)
|
|
3633
|
+
: null
|
|
2192
3634
|
const tabs = [
|
|
2193
3635
|
["pack", "打包"],
|
|
2194
3636
|
["install", "安装 / 导入"],
|
|
3637
|
+
...(marketOn ? [["market", "社区资源"]] : []),
|
|
2195
3638
|
["settings", "设置与记录"],
|
|
2196
3639
|
]
|
|
2197
3640
|
const tabBtn = (key, text) => h("button", {
|
|
2198
3641
|
key,
|
|
2199
|
-
onClick: () => setTab(key),
|
|
3642
|
+
onClick: () => { setTab(key); if (key === "market") spotEgg() },
|
|
2200
3643
|
style: {
|
|
2201
3644
|
...btn,
|
|
2202
3645
|
fontSize: embedded ? "12px" : btn.fontSize,
|
|
@@ -2210,9 +3653,11 @@ window.__ModuleLoader__.load({
|
|
|
2210
3653
|
const panels = [
|
|
2211
3654
|
tab === "pack" ? h(PackPanel, { key: "pack-" + gen, status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
|
|
2212
3655
|
tab === "install" ? h(InstallPanel, { key: "install-" + gen, status }) : null,
|
|
3656
|
+
tab === "market" ? h(MarketPanel, { key: "market-" + gen, status, onGoInstall: () => setTab("install") }) : null,
|
|
2213
3657
|
tab === "settings" ? h(SettingsPanel, { key: "settings-" + gen, status }) : null,
|
|
2214
3658
|
]
|
|
2215
|
-
|
|
3659
|
+
// 这段是打包/安装的安全说明,社区资源里不该出现(那里是逛目录,不是打包)
|
|
3660
|
+
const footNote = tab === "market" ? null : h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")
|
|
2216
3661
|
const unlagNode = unlag
|
|
2217
3662
|
? h("div", { style: row },
|
|
2218
3663
|
h("button", {
|
|
@@ -2245,8 +3690,8 @@ window.__ModuleLoader__.load({
|
|
|
2245
3690
|
},
|
|
2246
3691
|
h("div", { style: { maxWidth: "1020px", margin: "0 auto", width: "100%", display: "flex", flexDirection: "column", gap: "10px" } },
|
|
2247
3692
|
h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
|
|
3693
|
+
eggNode,
|
|
2248
3694
|
unlagNode,
|
|
2249
|
-
unlagNode,
|
|
2250
3695
|
panels,
|
|
2251
3696
|
footNote,
|
|
2252
3697
|
h(RepoFooter, null)),
|
|
@@ -2262,6 +3707,7 @@ window.__ModuleLoader__.load({
|
|
|
2262
3707
|
h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
|
|
2263
3708
|
h("span", { style: hint }, ((status && status.config && status.config.tagline) || "谁说 dsh 不能整整合包呢?(你说这几个插件整一块不牛逼坏了)"))),
|
|
2264
3709
|
h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)), envLine, refreshNote ? h("span", { style: hint }, refreshNote) : null, refreshMsg ? h("span", { style: { ...hint, color: "#ff6b6b" } }, refreshMsg) : null, recallBtn, refreshBtn),
|
|
3710
|
+
eggNode,
|
|
2265
3711
|
panels,
|
|
2266
3712
|
footNote,
|
|
2267
3713
|
h(RepoFooter, null)),
|
|
@@ -2277,6 +3723,7 @@ window.__ModuleLoader__.load({
|
|
|
2277
3723
|
}
|
|
2278
3724
|
|
|
2279
3725
|
/** 用一个小组件包住面板,进入时拉一次状态,之后交给子面板。 */
|
|
3726
|
+
// ===== [区块] 页面入口:读 status、按显示位决定挂哪里:Page =====
|
|
2280
3727
|
function Page(props) {
|
|
2281
3728
|
const [status, setStatus] = useState(null)
|
|
2282
3729
|
const [error, setError] = useState("")
|
|
@@ -2293,6 +3740,7 @@ window.__ModuleLoader__.load({
|
|
|
2293
3740
|
if (data && data.ok) {
|
|
2294
3741
|
setStatus(data)
|
|
2295
3742
|
setError("")
|
|
3743
|
+
if (data.config) { mergeLiveConfig(data.config); setMarketVisible(data.config.showModpackMarket !== false) }
|
|
2296
3744
|
if (data.placements) setPlacement(data.placements)
|
|
2297
3745
|
setTries(0)
|
|
2298
3746
|
return
|
|
@@ -2388,6 +3836,7 @@ window.__ModuleLoader__.load({
|
|
|
2388
3836
|
try {
|
|
2389
3837
|
const data = await api("/status")
|
|
2390
3838
|
if (data && data.ok && data.placements) setPlacement(data.placements)
|
|
3839
|
+
if (data && data.ok && data.config) { mergeLiveConfig(data.config); setMarketVisible(data.config.showModpackMarket !== false) }
|
|
2391
3840
|
if (data && data.config && data.config.forceHideMarketSidebar === true) enforceMarketSidebarOff()
|
|
2392
3841
|
} catch (e) {
|
|
2393
3842
|
if (left > 0) setTimeout(() => { refreshPlacement(left - 1) }, 700 * (3 - left))
|
|
@@ -2408,6 +3857,11 @@ window.__ModuleLoader__.load({
|
|
|
2408
3857
|
}
|
|
2409
3858
|
|
|
2410
3859
|
exports.apply = apply
|
|
3860
|
+
exports.MarketPanel = MarketPanel
|
|
3861
|
+
// 自测用:社区资源那层「切页签也保留」的状态存在模块里,测试要能塞一份进去看恢复得对不对
|
|
3862
|
+
exports.__marketUi = marketUi
|
|
3863
|
+
exports.PluginBrowser = PluginBrowser
|
|
3864
|
+
exports.ModpackBrowser = ModpackBrowser
|
|
2411
3865
|
exports.inject = inject
|
|
2412
3866
|
exports.Page = Page
|
|
2413
3867
|
exports.Home = Home
|