dsh-modpack-kit 0.2.3 → 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/client.js CHANGED
@@ -143,6 +143,17 @@ window.__ModuleLoader__.load({
143
143
  return () => packStore.subs.delete(fn)
144
144
  }
145
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
+
146
157
  // 插件市场的 AI 搜索:市场新版本用 POST /dsh-market/ai-search,让「你在 DSH 里配的模型」从目录里挑插件。
147
158
  // 我们不重复实现模型调用:旧版市场(或没装)没有这条路由,界面自动退回纯关键词搜索。
148
159
  const AI_SEARCH_KEY = "dsh-modpack-kit:ai-search"
@@ -505,7 +516,7 @@ window.__ModuleLoader__.load({
505
516
  f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
506
517
  }
507
518
 
508
- const JOB_KIND_LABEL = { pack: "打包", install: "安装" }
519
+ const JOB_KIND_LABEL = { pack: "打包", install: "安装", upload: "上传" }
509
520
  const JOB_STATUS_TEXT = { running: "进行中", paused: "等决定", acked: "已确认", done: "完成", failed: "失败", cancelled: "已取消" }
510
521
 
511
522
  function useJobs(intervalMs) {
@@ -881,11 +892,20 @@ window.__ModuleLoader__.load({
881
892
  onClick: () => { if (typeof props.onOpenResult === "function") props.onOpenResult(job) },
882
893
  }, "下载安装包")
883
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,
884
904
  job.canAck
885
905
  ? h("button", { style: { ...chipBtn, color: "#ff6b6b", borderColor: "#ff6b6b" }, title: "忽略风险,在同一个任务里接着跑完", onClick: () => ack(job.id) }, "我知道在干什么")
886
906
  : null,
887
907
  job.status !== "running" && job.status !== "paused"
888
- ? 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" ? "我已知晓" : "删除该进程")
889
909
  : null,
890
910
  job.error && job.status !== "paused" ? h("span", { style: { ...hint, color: "#ff6b6b" } }, job.error) : null)))))
891
911
  : h("div", { style: { ...hint, fontSize: "10.5px" } },
@@ -1566,8 +1586,15 @@ window.__ModuleLoader__.load({
1566
1586
 
1567
1587
  // —— 安装 / 导入 ——
1568
1588
  // ===== [区块] 页签二:安装 / 导入:InstallPanel =====
1589
+ // 安装页草稿:只活在内存里(刷新 / 重启即重置),离开插件页再回来不丢。
1590
+ const installDraft = { source: { kind: "url", url: "", file: "" }, options: null }
1591
+ function readInstallDraft() {
1592
+ return installDraft
1593
+ }
1594
+
1569
1595
  function InstallPanel(props) {
1570
- const [source, setSource] = useState({ kind: "url", url: "", file: "" })
1596
+ const installSaved = readInstallDraft()
1597
+ const [source, setSource] = useState(() => (installSaved.source ? { ...installSaved.source } : { kind: "url", url: "", file: "" }))
1571
1598
  const [packs, setPacks] = useState([])
1572
1599
  const [dirInput, setDirInput] = useState((props.status && props.status.paths && props.status.paths.packs) || "")
1573
1600
  const [dirInfo, setDirInfo] = useState({ dir: (props.status && props.status.paths && props.status.paths.packs) || "", error: "" })
@@ -1575,7 +1602,9 @@ window.__ModuleLoader__.load({
1575
1602
  const [busy, setBusy] = useState("")
1576
1603
  const [error, setError] = useState("")
1577
1604
  const [done, setDone] = useState(null)
1578
- 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])
1579
1608
  // 安装也走任务队列:进度直接显示在左下角那个窗里,这里留一份给页面内看
1580
1609
  const [progress, setProgress] = useState(null)
1581
1610
  const [deferred, setDeferred] = useState([])
@@ -1603,6 +1632,8 @@ window.__ModuleLoader__.load({
1603
1632
  if (!payload || !payload.token) return
1604
1633
  installRequest.value = null
1605
1634
  setSource({ kind: "token", token: payload.token, url: "", file: "" })
1635
+ // 下载时服务端会在 packs 目录留一份,列表顺手刷新一下就能在「已下载」里看到
1636
+ reloadPacks()
1606
1637
  setError("")
1607
1638
  setDone(null)
1608
1639
  setDeferred([])
@@ -1650,6 +1681,32 @@ window.__ModuleLoader__.load({
1650
1681
  } finally { setBusy("") }
1651
1682
  }
1652
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
+
1653
1710
  // 原生目录选择器:拿到绝对路径就填进去并列出该目录的 .dshpack
1654
1711
  const browseFolder = async () => {
1655
1712
  if (typeof pickDirectoryHost !== "function") {
@@ -1686,7 +1743,7 @@ window.__ModuleLoader__.load({
1686
1743
  const bodyFor = () => {
1687
1744
  if (source.kind === "url") return { url: source.url.trim() }
1688
1745
  if (source.kind === "token") return { token: source.token }
1689
- return { file: source.file }
1746
+ return { file: source.file, sourcePackFile: source.file }
1690
1747
  }
1691
1748
 
1692
1749
  const inspect = async () => {
@@ -1827,6 +1884,19 @@ window.__ModuleLoader__.load({
1827
1884
  item.fileName ? h("div", { style: { ...hint, fontSize: "10px" } }, item.fileName) : null))))
1828
1885
  : null,
1829
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) }, "删除"))))),
1830
1900
  h("div", { style: row },
1831
1901
  h("button", { style: source.kind === "url" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "url" }) }, "从链接读取"),
1832
1902
  h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "从本机文件读取"),
@@ -1974,6 +2044,17 @@ window.__ModuleLoader__.load({
1974
2044
  // ===== [区块] 页签四:设置与记录:SettingsPanel =====
1975
2045
  function SettingsPanel(props) {
1976
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
+ }
1977
2058
  const [saved, setSaved] = useState("")
1978
2059
  const [busy, setBusy] = useState(false)
1979
2060
  const [scanNag, fireScanNag] = useNag()
@@ -2103,6 +2184,9 @@ window.__ModuleLoader__.load({
2103
2184
  }, "保存数值"),
2104
2185
  h("span", { style: hint }, "默认 256 MB,可填 16~4096"),
2105
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 }, "网络与请求上限"),
2106
2190
  h("div", { style: row },
2107
2191
  h("span", { style: label }, "网络超时(秒)"),
2108
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)) }),
@@ -2181,6 +2265,7 @@ window.__ModuleLoader__.load({
2181
2265
  saved ? h("span", { style: hint }, saved) : null),
2182
2266
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
2183
2267
  h("div", { style: strong }, "社区资源(附属功能)"),
2268
+ h("div", { style: hint }, "这是「整合包」的附属小插件:自己一层代码(community/)、自己一套接口;关掉只是把它的接口和这一栏一起下线,打包/安装/进度窗都不受影响。"),
2184
2269
  h(Switch, {
2185
2270
  checked: cfg.showModpackMarket !== false,
2186
2271
  label: "显示「社区资源」这一栏",
@@ -2192,6 +2277,16 @@ window.__ModuleLoader__.load({
2192
2277
  h("span", { style: label }, "自动更新(小时)"),
2193
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)) }),
2194
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 || "")),
2195
2290
  h("div", { style: hint }, "搜索、分类、详情与下载码都在「社区资源」那一栏里;上传方式与规则点那一栏右上角。")),
2196
2291
  h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
2197
2292
  h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
@@ -2231,21 +2326,29 @@ window.__ModuleLoader__.load({
2231
2326
 
2232
2327
  const MARKET_SORTS = [["new", "最新"], ["downloads", "下载量"], ["size", "体积"], ["name", "名称"]]
2233
2328
  const MARKET_RULES = [
2234
- "只收轻量包(strategy: lite):只记插件名与版本、不带插件本体,十几 KB;装的人联网按版本取包。",
2235
- "第 1 步:在本插件「打包」页选「轻量包」、勾插件、打包并下载成 <名字>-<日期>-lite.dshpack。",
2236
- "第 2 步:算 sha256(Windows:certutil -hashfile 名字.dshpack SHA256;macOS/Linux:shasum -a 256 名字.dshpack),再记下字节数(≤ 64 MB)。",
2237
- "第 3 步:fork github.com/Vesna-Strivozha-cn/dsh-modpack-catalog,切一个分支,把包放进 packs/,再写一份 data/packs/<id>.json(只写 id、类型、文件名、sha256、日期)。",
2238
- "第 4 步:本地跑 node scripts/build.mjs,看到「packs.json: N 个整合包」才算过;报「构建失败」按提示改(多半是 sha256/size 对不上或分类写错)。",
2239
- "第 5 步:提交、push、开 PR;CI 会重跑构建,合并后每天 03:17 UTC 自动重建目录,也可以在 Actions 里手动 Run workflow 立刻扫一轮。",
2240
- "条目里不要写介绍、名称、作者、插件清单:目录直接显示包内 dsh-modpack.json(也就是打包那一刻填的内容),写了两边会不一致,构建会挡下。",
2241
- "包内插件可以不写死版本:清单里写 { \"name\": \"dsh-context\", \"latest\": true },安装时按名字取市场最新版(插件市场认市场版);写 version 就必须是 x.y.z。",
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,建议正方形;没有封面时列表显示分类色块 + 名字前两字。",
2242
2340
  "分类按使用场景:工作办公、性能优化、界面美化、实用功能、开发调试、娱乐休闲、学习资料、水槽(插件横跨三类以上会自动归这里)、其它。",
2341
+ "下载量指的是这个 .dshpack 安装文件本身被下载的次数,不是包里插件的 npm 下载量。放 Git 仓库没有逐文件计数,显示「下载量未统计」;想要真实计数就放 Release 并写 host/tag。",
2342
+ "收录门槛:存放包文件的仓库(默认本目录仓库,写了 repo 就查那个)必须建满 24 小时,跟插件市场同一条,挡当天开号刷包。",
2343
+ "混合包请在包里写清楚哪些插件带本体(离线能装)、哪些只记版本(要联网),装的人才不会拔了网才发现缺东西。",
2243
2344
  "只提交你自己打的包,或者你有权再分发的插件组合;作者没写许可证的组合请先问作者。",
2244
2345
  ]
2245
2346
 
2246
- // ===== [区块] 页签三:社区资源:MarketPanel =====
2347
+
2348
+ // 附属件(apiVersion 1):接口全在 /market 与 /upload 下,关掉就整层下线,主体不受影响
2247
2349
  // 两层:外层管左侧「插件 / 整合包」两个大类,里层各自是独立的浏览面板。
2248
2350
  // 整合包这层就是原来的整包浏览(列表 / 详情 / 上传规则)。
2351
+ // ===== [区块] 社区资源小插件:MarketPanel =====
2249
2352
  function MarketPanel(props) {
2250
2353
  const [kind, setKind] = useState(() => (readMarketUi().kind === "plugin" ? "plugin" : "modpack"))
2251
2354
  useEffect(() => { saveMarketKind(kind) }, [kind])
@@ -2312,6 +2415,10 @@ window.__ModuleLoader__.load({
2312
2415
  const [chips, setChips] = useState(Array.isArray(pluginSnap.chips) && pluginSnap.chips.length ? pluginSnap.chips : [{ id: "all", label: "全部", count: 0 }])
2313
2416
  const [loading, setLoading] = useState(false)
2314
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("")
2315
2422
  // 第一屏如果有上次留下的列表,就别再打一次请求(会闪一下、还把页码冲回 1)
2316
2423
  const restoredPlugins = useRef(Array.isArray(pluginSnap.items) && pluginSnap.items.length > 0)
2317
2424
  const applyItems = (data, append) => {
@@ -2327,8 +2434,8 @@ window.__ModuleLoader__.load({
2327
2434
  // 分类直接沿用插件市场目录的口径:服务端按 label 过滤,前端只拿一页
2328
2435
  // 退出程序前一直留着:搜索框文字、分类、排序、页码与已读到的列表
2329
2436
  useEffect(() => {
2330
- saveMarketUi("plugin", { query, category, sort, items, total, page, hasMore, chips })
2331
- }, [query, category, sort, items, total, page, hasMore, chips])
2437
+ saveMarketUi("plugin", { query, category, sort, items, total, page, hasMore, chips, view, detail })
2438
+ }, [query, category, sort, items, total, page, hasMore, chips, view, detail])
2332
2439
  useEffect(() => {
2333
2440
  if (!installed) return undefined
2334
2441
  if (restoredPlugins.current) { restoredPlugins.current = false; return undefined }
@@ -2359,6 +2466,78 @@ window.__ModuleLoader__.load({
2359
2466
  setLoading(false)
2360
2467
  }
2361
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
+ }
2362
2541
  if (!installed) {
2363
2542
  return h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "16px", display: "flex", flexDirection: "column", gap: "8px" } },
2364
2543
  h("span", { style: strong }, "请先安装插件市场"),
@@ -2395,24 +2574,514 @@ window.__ModuleLoader__.load({
2395
2574
  h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", overflow: "hidden" } },
2396
2575
  items.map((item) => h("div", {
2397
2576
  key: "plug-" + item.name,
2398
- style: { display: "flex", flexDirection: "column", gap: "3px", padding: "9px 12px", borderBottom: "0.5px solid var(--dsw-alias-border-l2)" },
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" },
2399
2580
  },
2400
2581
  h("div", { style: row },
2401
2582
  h("span", { style: { fontSize: "13px", fontWeight: 600 } }, item.title || item.name),
2402
2583
  h(Tag, null, item.categoryLabel || item.category || "其它"),
2403
2584
  item.installed ? h("span", { style: { ...hint, color: "#2bb673" } }, "本机已装" + (item.updateAvailable ? "(市场版 " + item.version + " 更新)" : "")) : null,
2404
- h("span", { style: { ...hint, marginLeft: "auto" } }, item.version ? "v" + item.version : "")),
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 } }, "查看 ›")),
2405
2588
  h("span", { style: hint }, item.description || "作者没写说明。"),
2406
2589
  h("span", { style: { ...hint, fontSize: "11.5px" } }, item.name)))),
2407
2590
  hasMore ? h("div", { style: row },
2408
2591
  h("button", { type: "button", style: btn, disabled: loading, onClick: loadMore }, loading ? "读取中…" : "加载更多")) : null,
2409
- h("div", { style: hint }, "装 / 更新 / 卸载插件仍在插件市场里做:这一层只按它的目录浏览与检索,不重复实现一套安装。"))
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)
2410
3079
  }
2411
3080
 
2412
- // ===== [区块] 页签三:社区资源:整合包浏览(列表 / 详情 / 上传规则) =====
3081
+ // ===== [区块] 社区资源小插件:整合包浏览(列表 / 详情 / 上传规则) ====
2413
3082
  function ModpackBrowser(props) {
2414
3083
  const packSnap = readMarketUi().pack || {}
2415
- const [view, setView] = useState(packSnap.view === "detail" || packSnap.view === "rules" ? packSnap.view : "list")
3084
+ const [view, setView] = useState(packSnap.view === "detail" || packSnap.view === "rules" || packSnap.view === "upload" ? packSnap.view : "list")
2416
3085
  const [summary, setSummary] = useState(packSnap.summary || null)
2417
3086
  const [items, setItems] = useState(Array.isArray(packSnap.items) ? packSnap.items : [])
2418
3087
  const [total, setTotal] = useState(Number(packSnap.total) || 0)
@@ -2427,6 +3096,20 @@ window.__ModuleLoader__.load({
2427
3096
  const [error, setError] = useState("")
2428
3097
  const [msg, setMsg] = useState("")
2429
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
+ }
2430
3113
  const [descOpen, setDescOpen] = useState(packSnap.descOpen !== false)
2431
3114
  const [descTick, setDescTick] = useState(0)
2432
3115
  const [downloading, setDownloading] = useState(false)
@@ -2439,6 +3122,7 @@ window.__ModuleLoader__.load({
2439
3122
  saveMarketUi("pack", { view, summary, items, total, page, hasMore, query, category, sort, detail, dataReady: true })
2440
3123
  }, [view, summary, items, total, page, hasMore, query, category, sort, detail])
2441
3124
 
3125
+
2442
3126
  // 打开详情时补齐插件介绍:包里写了就用包里的,没写就问插件市场的目录
2443
3127
  useEffect(() => {
2444
3128
  if (view !== "detail" || !detail) return undefined
@@ -2541,13 +3225,18 @@ window.__ModuleLoader__.load({
2541
3225
  }
2542
3226
  }
2543
3227
 
2544
- const download = async (pack) => {
3228
+ const download = async (pack, saveOnly) => {
2545
3229
  setDownloading(true); setError(""); setMsg("")
2546
3230
  try {
2547
- const data = await api("/market/download", { id: pack.id })
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
+ }
2548
3237
  if (!data || data.ok !== true) { setError((data && data.error) || "下载失败"); return }
2549
3238
  requestInstall({ token: data.token, fileName: data.fileName, packName: pack.name })
2550
- setMsg("已下载并读取:" + pack.name + ",正在转到安装页")
3239
+ setMsg("已下载并读取:" + pack.name + (data && data.savedName ? "(也存了一份:" + data.savedName + ")" : "") + ",正在转到安装页")
2551
3240
  if (typeof props.onGoInstall === "function") props.onGoInstall()
2552
3241
  } catch (e) {
2553
3242
  setError((e && e.message) || String(e))
@@ -2556,6 +3245,24 @@ window.__ModuleLoader__.load({
2556
3245
  }
2557
3246
  }
2558
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
+
2559
3266
  // 分类英文名(目录里只存中文 label,英文界面在这里映射)
2560
3267
  const catLabel = (name) => name
2561
3268
  const CATEGORY_TINT = { 工作办公: "#4C7DF0", 性能优化: "#2bb673", 界面美化: "#a855f7", 实用功能: "#0ea5e9", 开发调试: "#f59e0b", 娱乐休闲: "#ec4899", 学习资料: "#14b8a6", 水槽: "#7c3aed", 其它: "#64748b" }
@@ -2603,7 +3310,7 @@ window.__ModuleLoader__.load({
2603
3310
  onClick: () => { setDetail(pack); setView("detail"); setError(""); setMsg("") },
2604
3311
  style: { display: "flex", gap: "10px", padding: "10px 12px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", cursor: "pointer", alignItems: "flex-start" },
2605
3312
  },
2606
- h("div", {
3313
+ coverImg(pack, 42) || h("div", {
2607
3314
  style: {
2608
3315
  width: "42px", height: "42px", flexShrink: 0, borderRadius: "8px",
2609
3316
  background: tint, color: "#fff", fontSize: "13px", fontWeight: 600,
@@ -2615,12 +3322,15 @@ window.__ModuleLoader__.load({
2615
3322
  h("span", { style: { fontWeight: 600, fontSize: "13.5px" } }, pack.name),
2616
3323
  h(Tag, null, catLabel(pack.category || "其它")),
2617
3324
  tierTag(pack),
2618
- h(Tag, null, "v" + pack.version),
2619
- pack.installed && pack.installed.all ? h("span", { style: { ...hint, color: "#2bb673" } }, "已装") : null,
2620
- pack.installed && pack.installed.some && !pack.installed.all ? h("span", { style: hint }, "部分已装") : null),
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
+ ),
2621
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,
2622
3331
  h("div", { style: { ...row, gap: "14px" } }, meta.map((line, index) => h("span", { key: "meta-" + pack.id + "-" + index, style: hint }, line)))))
2623
3332
  }
3333
+ const rows = previewPack ? [previewPack].concat(items.filter((item) => item.id !== previewPack.id)) : items
2624
3334
  const resetFilters = () => { setQuery(""); setCategory("all"); setSort("new"); setPage(1); setSearchTick((n) => n + 1) }
2625
3335
 
2626
3336
  const head = h("div", { style: { ...row, justifyContent: "space-between" } },
@@ -2629,15 +3339,20 @@ window.__ModuleLoader__.load({
2629
3339
  present ? h(Tag, null, total + " 个") : null,
2630
3340
  present ? h("span", { style: hint }, "目录来自 " + (summary.repo || "dsh-modpack-catalog") + (summary.builtAt ? " · 构建于 " + String(summary.builtAt).slice(0, 10) : "")) : null),
2631
3341
  h("div", { style: row },
3342
+ h("button", { type: "button", style: chipBtn, onClick: () => { setView("upload"); setDetail(null) } }, "上传我的整合包"),
2632
3343
  h("button", { type: "button", style: chipBtn, onClick: () => { setView("rules"); setDetail(null) } }, "上传方式与规则"),
2633
3344
  h("button", { type: "button", style: chipBtn, disabled: syncing, onClick: syncNow }, syncing ? "更新中…" : "更新目录")))
2634
3345
 
3346
+ if (view === "upload") {
3347
+ return h(UploadPanel, { onBack: () => setView("list"), onPreview: openPreview })
3348
+ }
3349
+
2635
3350
  if (view === "rules") {
2636
3351
  return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
2637
3352
  h("div", { style: row },
2638
3353
  h("button", { type: "button", style: chipBtn, onClick: () => setView("list") }, "← 返回市场"),
2639
3354
  h("span", { style: { ...strong, fontSize: "14px" } }, "上传方式与规则")),
2640
- h("div", { style: { ...hint, lineHeight: "20px" } }, "第一阶段只收轻量包;审核与出问题下架都靠 PR 与 issue,和插件市场一样。"),
3355
+ h("div", { style: { ...hint, lineHeight: "20px" } }, "收轻量包(无修改)与混合包(有自定义);审核与出问题下架都靠 PR 与 issue,和插件市场一样。"),
2641
3356
  h("ol", { style: { margin: 0, paddingLeft: "18px", display: "flex", flexDirection: "column", gap: "8px" } },
2642
3357
  MARKET_RULES.map((line, index) => h("li", { key: "rule-" + index, style: { fontSize: "12.5px", lineHeight: "19px" } }, line))),
2643
3358
  h("div", { style: { border: "1px dashed var(--dsw-alias-border-l2)", borderRadius: "8px", padding: "10px", display: "flex", flexDirection: "column", gap: "4px" } },
@@ -2657,7 +3372,10 @@ window.__ModuleLoader__.load({
2657
3372
  h("span", { style: { ...strong, fontSize: "15px" } }, pack.name),
2658
3373
  h(Tag, null, catLabel(pack.category || "其它")),
2659
3374
  tierTag(pack),
2660
- h("span", { style: hint }, "v" + pack.version + " · 作者 " + (pack.author || "?") + " · " + sizeText(pack.size) + " · " + plugins.length + " 个插件")),
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,
2661
3379
  h("div", { style: { ...hint, lineHeight: "20px" } },
2662
3380
  pack.downloads === null || pack.downloads === undefined
2663
3381
  ? "下载量:暂无统计(安装文件放在 Git 仓库里,没有逐文件计数;放进 GitHub Release 资源才拿得到真实下载数)"
@@ -2667,11 +3385,23 @@ window.__ModuleLoader__.load({
2667
3385
  h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "8px" } },
2668
3386
  h("span", { style: strong }, "这个整合包是做什么的"),
2669
3387
  h("div", { style: { fontSize: "12.5px", lineHeight: "20px" } }, descOf(pack)),
2670
- pack.installed && pack.installed.all
2671
- ? h("div", { style: { ...hint, color: "#2bb673" } }, "这台机器上已经装齐了它包含的插件,可以只下载留存或再装一遍。")
2672
- : pack.installed && pack.installed.some
2673
- ? h("div", { style: hint }, "本机已装 " + pack.installed.count + " / " + plugins.length + " 个,安装时会先跳过已装的那些。")
2674
- : null),
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),
2675
3405
  h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", padding: "12px", display: "flex", flexDirection: "column", gap: "6px" } },
2676
3406
  h("div", { style: { ...row, justifyContent: "space-between" } },
2677
3407
  h("span", { style: strong }, "包含的插件(这些插件会干什么)"),
@@ -2697,7 +3427,8 @@ window.__ModuleLoader__.load({
2697
3427
  error ? h("div", { style: { ...hint, color: "#ff6b6b" } }, error) : null,
2698
3428
  msg ? h("div", { style: hint }, msg) : null,
2699
3429
  h("div", { style: row },
2700
- h("button", { type: "button", style: btnPrimary, disabled: downloading, onClick: () => download(pack) }, downloading ? "下载中…" : "下载并安装"),
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 ? "下载中…" : "下载并安装"),
2701
3432
  h("span", { style: hint }, "下载后在内存里校验 sha256、跑一遍安全检测,再转到安装页读取;半成品不会留在磁盘上。")))
2702
3433
  }
2703
3434
 
@@ -2750,8 +3481,15 @@ window.__ModuleLoader__.load({
2750
3481
  ? h("span", { style: { ...hint, lineHeight: "19px" } }, "网络正常但接口报 404/405 的话,是宿主还跑着旧代码:把 DSH 完全退出再打开,这一栏就会生效。")
2751
3482
  : null)
2752
3483
 
2753
- const listBox = items.length > 0
2754
- ? h("div", { style: { border: "1px solid var(--dsw-alias-border-l2)", borderRadius: "10px", overflow: "hidden" } }, items.map(renderRow))
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))
2755
3493
  : null
2756
3494
 
2757
3495
  return h("div", { style: { display: "flex", flexDirection: "column", gap: "10px" } },
@@ -2761,13 +3499,17 @@ window.__ModuleLoader__.load({
2761
3499
  error ? h("div", { style: { ...hint, color: "#ff6b6b", lineHeight: "19px" } }, String(error)) : null,
2762
3500
  msg ? h("div", { style: hint }, msg) : null,
2763
3501
  listBox,
2764
- !loading && items.length === 0 ? emptyCard : null,
3502
+ !loading && rows.length === 0 ? emptyCard : null,
2765
3503
  hasMore ? h("button", { type: "button", style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : "加载更多") : null)
2766
3504
  }
2767
3505
 
2768
3506
  // ===== [区块] 外壳:页签、刷新、彩蛋、进度窗挂载:Home =====
2769
3507
  function Home(props) {
2770
- const [tab, setTab] = useState("pack")
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])
2771
3513
  const jobs = useJobs()
2772
3514
  const status = props.status
2773
3515
  const surface = (props && props.surface) || "sidebar"