dsh-modpack-kit 0.1.1 → 0.1.3
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 +42 -9
- package/assets/icon-180.png +0 -0
- package/assets/install-stub.cmd +15 -0
- package/assets/install-stub.mjs +259 -0
- package/assets/install-stub.sh +9 -0
- package/client.js +469 -34
- package/docs/DETAIL.md +15 -0
- package/index.js +268 -14
- package/lib/install.mjs +7 -2
- package/lib/manifest.mjs +18 -10
- package/lib/pack.mjs +90 -12
- package/lib/scan.mjs +47 -0
- package/lib/store.mjs +3 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -3
package/docs/DETAIL.md
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
- **没装市场**:打包、装包、强制检测、完整性/兼容/许可证校验、配置回填、装好先不启用、三处入口**全部照常**(这些槽位由 DSH 核心声明,不依赖市场插件)。少的只有市场 Discover 界面,以及**尚未建过目录索引时**的分类胶囊、搜索、市场版对比与「切换市场版」。建一次索引(5~30 秒)即恢复。
|
|
19
19
|
- **没索引又没网**:首屏仍只列已装插件;已装行的分类退回内置兜底规则,与 23 类的 id 不完全对得上,按 theme / memory 之类筛会漏几条;轻量包装不了(需按清单版本联网取包),完整版照装。
|
|
20
20
|
- **分类 + 搜索 + 分页**:分类就是市场的 23 个分区。首屏只列本机已装的插件,不联网;输入关键词或点分类才去目录里搜,服务端分页(默认每页 20 条,可改),底部「加载更多」。排序照抄市场:已装优先 → 相关度(整字段 > 包含 > 其它词,包名权重最高)→ 目录原序;本机独有、目录里没有的插件也能搜到。
|
|
21
|
+
- **风险确认**:检出高危时不再直接拒绝,而是把任务停在 `paused` 等你确认「我知道在干什么」;确认状态写进清单 `security.acknowledged`,报告照常列出命中。市场收录与否只影响 `security.trustedOnly` 与提示措辞。
|
|
22
|
+
- **快捷选择**:打包页搜索框右侧有「全部加入」(本机已装全部插件,按「基础配置」)与「清除选择」。
|
|
21
23
|
- **切换市场版**:本机已装插件若在目录里有同名条目,行末有小字「(切换市场版)」——改用上游原版代码 + 默认配置打包;再点「(切回本机版)」回到本机快照。同名可能是撞名,所以只作为选项,默认仍打本机那份。
|
|
22
24
|
- **显示位置**:设置页底部三个独立开关(设置页内 / 侧边栏 / 插件页内),改了立刻挂上或撤下,不用重启;只剩一处时那个开关会变灰、点不动,接口层也会拒绝三处全关,免得再没有入口关回来。
|
|
23
25
|
- **装完是否启用**:安装页与设置里都有「安装后直接启用」,默认关。关的时候文件与依赖照装,但装完会把 `dsh.profile.bundles` 精确撤回原样——重启也不加载,想用再手动登记或重装时勾上。
|
|
@@ -45,6 +47,9 @@ dsh-modpack.json 清单:格式、插件、选项、安全摘要、安装
|
|
|
45
47
|
README.txt 不依赖本插件的手工安装说明
|
|
46
48
|
security/report.txt 检测报告(只有类型、位置、掩码)
|
|
47
49
|
integrity.json sha256 清单
|
|
50
|
+
install/install.mjs 独立安装器(不装本插件也能装这个包)
|
|
51
|
+
install/install.cmd Windows 双击入口
|
|
52
|
+
install/install.sh shell 入口
|
|
48
53
|
plugins/<name>/** 完整版才有
|
|
49
54
|
configs/<name>.json 抓到的配置条目
|
|
50
55
|
data/<name>/** 插件数据快照(仅小体积文本)
|
|
@@ -52,6 +57,16 @@ data/<name>/** 插件数据快照(仅小体积文本)
|
|
|
52
57
|
|
|
53
58
|
文件名:`<包名>-<日期>-<full|lite>.dshpack`。
|
|
54
59
|
|
|
60
|
+
## 风险列表与打包进度
|
|
61
|
+
|
|
62
|
+
- 命中按来源分栏:每个插件一组、`configs/` 一组、`data/` 一组,整合包自身(清单、README、安装器)单独一组;整体可折叠,每组也可折叠,组头带高/中/低计数,高危组排最前。
|
|
63
|
+
- 打包走后台任务(`POST /pack` 带 `async: true` → `GET /jobs` 轮询):悬浮进度窗显示概述 + 百分比 + 进度条,展开可看每个任务;`POST /jobs/cancel` 终止,包在内存里组装,取消不会写到磁盘。
|
|
64
|
+
- 检出高风险时任务一律停在 `paused`:`GET /jobs` 带 `risk`(高/中/低、`trustedOnly`、按插件分组的命中摘要 `risk.groups[].samples`)与 `canAck`,打包页会在选项下方按插件分别列出这些命中项。「我知道在干什么」= `POST /jobs/ack`:复用停在那一刻的中间结果(`job.checkpoint`:已收集的文件、配置快照、检测结果),从检测点继续,**不重新收集、也不重复检测**,清单记 `security.acknowledged`;确认成功的同时 `job.risk` 清空,界面上的红字警告随之消失(记录只留状态与进度)。「删除该进程」= `POST /jobs/dismiss`(只删记录,跑着的任务不给删)。
|
|
65
|
+
- 收尾的任务在进度窗里给「下载安装包」:点击会切到打包页、把该任务的 `data` 放回结果区并滚到下载部分;结果存在客户端模块级缓存里(`packStore`),切页签、卸载再挂载都不丢,程序退出或插件被关掉才清。进度窗的「清空进程」(`POST /jobs/clear`)清掉所有收尾记录——完成的、失败的、取消的,以及像「超过打包上限」这类中途报错卡住的失败进程都带走;`running` 与 `paused`(还在跑或等你决定)保留。界面侧如果发现宿主还是旧代码(`/jobs/clear` 404),会退回逐个 `POST /jobs/dismiss`;清空后打包页上残留的报错与失败结果也一并收掉。
|
|
66
|
+
- 悬浮进度窗可拖:按住标题拖动,位置存在浏览器 `localStorage`(键 `dsh-modpack-kit:dock-pos`),不经过服务端配置;没有任务时自动收起,只留一枚「进度」按钮用于唤出,任务开跑会自动冒出。
|
|
67
|
+
- 体积上限默认 `maxPackBytes = 512MB`;单个下载另有 `maxDownloadBytes = 256MB`。
|
|
68
|
+
- 允许同时打多个包(每个任务独立 token、独立进度)。
|
|
69
|
+
|
|
55
70
|
## 已知限制
|
|
56
71
|
|
|
57
72
|
- 只打包已发布的 npm 包或本机已装目录,不处理 git 仓库直装。
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { buildPack, PackRefused } from './lib/pack.mjs'
|
|
|
14
14
|
import { inspectPackBuffer, installPack, readPackFromUrl, InstallRefused } from './lib/install.mjs'
|
|
15
15
|
import { checkCompatibility } from './lib/compat.mjs'
|
|
16
16
|
import { classifyPlugin } from './lib/classify.mjs'
|
|
17
|
+
import { groupFindings } from './lib/scan.mjs'
|
|
17
18
|
import { catalogSummary, searchCatalog, syncCatalog, categoryMapFor, lookupPlugins } from './lib/market-catalog.mjs'
|
|
18
19
|
import { parseYaml } from './lib/yamlish.mjs'
|
|
19
20
|
import { readPatch } from './lib/profile.mjs'
|
|
@@ -309,15 +310,80 @@ export default {
|
|
|
309
310
|
}
|
|
310
311
|
})
|
|
311
312
|
|
|
312
|
-
// ——
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
// —— 打包(支持后台任务:左下角悬浮窗要进度,且允许同时打多个包) ——
|
|
314
|
+
const jobs = new Map()
|
|
315
|
+
let jobSeq = 0
|
|
316
|
+
const JOBS_KEEP = 10 * 60 * 1000
|
|
317
|
+
const pruneJobs = () => {
|
|
318
|
+
const cut = Date.now() - JOBS_KEEP
|
|
319
|
+
for (const [id, job] of jobs) {
|
|
320
|
+
if (job.status === 'running') continue
|
|
321
|
+
const stamp = Date.parse(job.finishedAt || job.startedAt) || 0
|
|
322
|
+
if (stamp && stamp < cut) jobs.delete(id)
|
|
323
|
+
}
|
|
324
|
+
for (const id of [...jobs.keys()]) {
|
|
325
|
+
if (jobs.size <= 20) break
|
|
326
|
+
const job = jobs.get(id)
|
|
327
|
+
if (job.status === 'running') continue
|
|
328
|
+
jobs.delete(id)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const createJob = (kind, label) => {
|
|
332
|
+
const job = {
|
|
333
|
+
id: 'job_' + (++jobSeq).toString(36) + '_' + Date.now().toString(36),
|
|
334
|
+
kind,
|
|
335
|
+
label,
|
|
336
|
+
status: 'running',
|
|
337
|
+
pct: 0,
|
|
338
|
+
note: '准备中',
|
|
339
|
+
startedAt: new Date().toISOString(),
|
|
340
|
+
finishedAt: '',
|
|
341
|
+
error: '',
|
|
342
|
+
data: null,
|
|
343
|
+
// 风险停下来的任务:保留原始请求,等你选「立即停止」还是「我知道在干什么」
|
|
344
|
+
risk: null,
|
|
345
|
+
body: null,
|
|
346
|
+
}
|
|
347
|
+
jobs.set(job.id, job)
|
|
348
|
+
pruneJobs()
|
|
349
|
+
return job
|
|
350
|
+
}
|
|
351
|
+
const publicJob = (job) => ({
|
|
352
|
+
id: job.id,
|
|
353
|
+
kind: job.kind,
|
|
354
|
+
label: job.label,
|
|
355
|
+
status: job.status,
|
|
356
|
+
pct: job.pct,
|
|
357
|
+
note: job.note,
|
|
358
|
+
startedAt: job.startedAt,
|
|
359
|
+
finishedAt: job.finishedAt,
|
|
360
|
+
error: job.error,
|
|
361
|
+
data: job.data,
|
|
362
|
+
risk: job.risk,
|
|
363
|
+
// 只有「可确认继续」的风险任务才给「我知道在干什么」;停下来的任务都能删
|
|
364
|
+
canAck: Boolean(job.risk && job.risk.needsAck && job.status === 'paused'),
|
|
365
|
+
canDismiss: job.status !== 'running',
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
class JobCancelled extends Error {}
|
|
369
|
+
const performPack = async (body, job, resume = null) => {
|
|
316
370
|
const selection = Array.isArray(body.selection) ? body.selection : []
|
|
317
|
-
if (selection.length === 0) { json(res, 400, { ok: false, error: '没有选择任何插件' }); return }
|
|
318
371
|
const options = body.options && typeof body.options === 'object' ? body.options : {}
|
|
319
372
|
const dir = profileDir()
|
|
320
373
|
const installed = installedOrEmpty()
|
|
374
|
+
const dshVersionNow = (() => { try { return dshVersion(dir) } catch { return '' } })()
|
|
375
|
+
// 市场目录里能查到的插件:风险项默认放行,但需调用方 acknowledge
|
|
376
|
+
let trusted = []
|
|
377
|
+
try {
|
|
378
|
+
const look = lookupPlugins(config, selection.map((item) => String(item.name || '')).filter(Boolean))
|
|
379
|
+
trusted = Object.keys(look || {})
|
|
380
|
+
} catch { trusted = [] }
|
|
381
|
+
const onProgress = (event) => {
|
|
382
|
+
if (!job) return
|
|
383
|
+
if (job.cancelled) throw new JobCancelled('已取消')
|
|
384
|
+
job.pct = event.pct
|
|
385
|
+
job.note = event.note || job.note
|
|
386
|
+
}
|
|
321
387
|
try {
|
|
322
388
|
const result = await buildPack({
|
|
323
389
|
selection: selection.map((item) => ({
|
|
@@ -333,20 +399,23 @@ export default {
|
|
|
333
399
|
includeLocalEdits: options.includeLocalEdits === true,
|
|
334
400
|
confirmLicense: options.confirmLicense === true,
|
|
335
401
|
force: options.force === true,
|
|
402
|
+
acknowledge: options.acknowledge === true,
|
|
403
|
+
trusted,
|
|
336
404
|
keepLocal: options.keepLocal !== false,
|
|
337
|
-
// 扫描是强制的,客户端传什么都不认
|
|
338
405
|
scanBeforePack: true,
|
|
406
|
+
onProgress,
|
|
339
407
|
name: String(options.name || 'DSH 整合包'),
|
|
340
408
|
description: String(options.description || ''),
|
|
341
409
|
author: String(options.author || ''),
|
|
342
410
|
license: String(options.license || ''),
|
|
343
411
|
homepage: String(options.homepage || ''),
|
|
344
412
|
extensions: options.extensions && typeof options.extensions === 'object' ? options.extensions : {},
|
|
413
|
+
resume: resume && typeof resume === 'object' ? resume : null,
|
|
345
414
|
},
|
|
346
415
|
context: {
|
|
347
416
|
config,
|
|
348
417
|
profileDir: dir,
|
|
349
|
-
dshVersion:
|
|
418
|
+
dshVersion: dshVersionNow,
|
|
350
419
|
installed,
|
|
351
420
|
pluginVersion: VERSION,
|
|
352
421
|
extraScanRules: Array.isArray(config.extraScanRules) ? config.extraScanRules : [],
|
|
@@ -356,24 +425,208 @@ export default {
|
|
|
356
425
|
})
|
|
357
426
|
const token = rememberPending(result.fileName, { buffer: result.buffer, manifest: result.manifest, report: result.report, scan: result.scan })
|
|
358
427
|
appendHistory({ at: new Date().toISOString(), kind: 'pack', name: result.manifest.name, format: result.manifest.format, plugins: result.manifest.plugins.map((p) => p.name + '@' + p.version), size: result.size, high: result.scan.counts.high }, config.historyLimit)
|
|
359
|
-
|
|
428
|
+
return {
|
|
360
429
|
ok: true,
|
|
361
430
|
token,
|
|
362
431
|
fileName: result.fileName,
|
|
363
432
|
size: result.size,
|
|
364
433
|
manifest: result.manifest,
|
|
365
434
|
scan: result.scan,
|
|
435
|
+
scanGroups: result.scanGroups,
|
|
366
436
|
report: result.report,
|
|
367
437
|
notes: result.notes,
|
|
368
|
-
compat: checkCompatibility(result.manifest.plugins, { installed, dshVersion:
|
|
369
|
-
}
|
|
438
|
+
compat: checkCompatibility(result.manifest.plugins, { installed, dshVersion: dshVersionNow, nodeVersion: process.versions.node, config }),
|
|
439
|
+
}
|
|
370
440
|
} catch (error) {
|
|
441
|
+
if (error instanceof JobCancelled) {
|
|
442
|
+
// 取消发生在内存里:没有写入任何文件,直接丢弃缓冲
|
|
443
|
+
return { ok: false, cancelled: true, error: '已取消(未生成文件,本地没有残留)' }
|
|
444
|
+
}
|
|
371
445
|
if (error instanceof PackRefused) {
|
|
372
|
-
|
|
446
|
+
const scanGroups = (() => { try { return error.scan ? groupFindings(error.scan.findings, (selection || []).map((item) => ({ name: String(item.name || '') }))) : [] } catch { return [] } })()
|
|
447
|
+
return {
|
|
448
|
+
ok: false,
|
|
449
|
+
refused: true,
|
|
450
|
+
needsAck: error.needsAck === true,
|
|
451
|
+
trustedOnly: error.trustedOnly === true,
|
|
452
|
+
error: error.message,
|
|
453
|
+
scan: error.scan,
|
|
454
|
+
scanGroups,
|
|
455
|
+
checkpoint: error.checkpoint || null,
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return { ok: false, error: String((error && error.message) || error) }
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// 任务收尾:只有「能确认继续」的风险才停下等你点一下;其余情况照旧判失败
|
|
463
|
+
const finishPackJob = (job, payload) => {
|
|
464
|
+
if (payload && payload.ok !== true && payload.refused === true) {
|
|
465
|
+
const counts = (payload.scan && payload.scan.counts) || {}
|
|
466
|
+
job.risk = {
|
|
467
|
+
high: counts.high || 0,
|
|
468
|
+
medium: counts.medium || 0,
|
|
469
|
+
low: counts.low || 0,
|
|
470
|
+
needsAck: payload.needsAck === true,
|
|
471
|
+
trustedOnly: payload.trustedOnly === true,
|
|
472
|
+
message: payload.error || '检测到风险',
|
|
473
|
+
// 只留分组摘要,不给界面塞整份 findings
|
|
474
|
+
groups: Array.isArray(payload.scanGroups)
|
|
475
|
+
? payload.scanGroups.map((g) => ({
|
|
476
|
+
plugin: g.plugin || '',
|
|
477
|
+
label: g.label,
|
|
478
|
+
origin: g.origin,
|
|
479
|
+
counts: g.counts,
|
|
480
|
+
samples: Array.isArray(g.findings)
|
|
481
|
+
? g.findings.slice(0, 4).map((f) => ({ label: f.label, severity: f.severity, file: f.file, line: f.line }))
|
|
482
|
+
: [],
|
|
483
|
+
}))
|
|
484
|
+
: [],
|
|
485
|
+
}
|
|
486
|
+
job.finishedAt = new Date().toISOString()
|
|
487
|
+
if (payload.needsAck === true) {
|
|
488
|
+
job.status = 'paused'
|
|
489
|
+
job.note = '检测到风险,等你决定'
|
|
490
|
+
job.pct = Math.min(job.pct || 0, 66)
|
|
491
|
+
job.checkpoint = payload.checkpoint || null
|
|
492
|
+
} else {
|
|
493
|
+
// 市场目录里查不到:没有「我知道在干什么」这条路,直接判失败
|
|
494
|
+
job.status = 'failed'
|
|
495
|
+
job.error = payload.error || '检测到风险'
|
|
496
|
+
job.note = '检测到风险,已拒绝出包'
|
|
497
|
+
job.data = payload
|
|
498
|
+
}
|
|
499
|
+
return
|
|
500
|
+
}
|
|
501
|
+
job.status = payload && payload.ok ? 'done' : payload && payload.cancelled === true ? 'cancelled' : 'failed'
|
|
502
|
+
job.data = payload
|
|
503
|
+
job.pct = payload && payload.ok ? 100 : job.pct
|
|
504
|
+
job.note = payload && payload.ok ? '完成' : ((payload && payload.error) || '已停止')
|
|
505
|
+
// 失败/取消也把原因放进 error,进度窗那一行能直接看到为什么卡住
|
|
506
|
+
if (!(payload && payload.ok)) job.error = (payload && payload.error) || job.note
|
|
507
|
+
job.finishedAt = new Date().toISOString()
|
|
508
|
+
}
|
|
509
|
+
const startPackJob = (body, label) => {
|
|
510
|
+
const job = createJob('pack', label || ('打包「' + String((body.options && body.options.name) || 'DSH 整合包') + '」'))
|
|
511
|
+
// 留一份原始请求:风险停下来之后,界面上点「我知道在干什么」要能照原样再跑一次
|
|
512
|
+
try {
|
|
513
|
+
job.body = JSON.parse(JSON.stringify({
|
|
514
|
+
selection: Array.isArray(body.selection) ? body.selection : [],
|
|
515
|
+
options: body.options && typeof body.options === 'object' ? body.options : {},
|
|
516
|
+
}))
|
|
517
|
+
} catch { job.body = null }
|
|
518
|
+
performPack(body, job)
|
|
519
|
+
.then((payload) => finishPackJob(job, payload))
|
|
520
|
+
.catch((error) => {
|
|
521
|
+
job.status = 'failed'
|
|
522
|
+
job.error = String((error && error.message) || error)
|
|
523
|
+
job.note = '失败'
|
|
524
|
+
job.finishedAt = new Date().toISOString()
|
|
525
|
+
})
|
|
526
|
+
return job
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
route('/dsh-modpack-kit/api/pack', async (req, res) => {
|
|
530
|
+
if (!needPost(req, res)) return
|
|
531
|
+
const body = asJson(await readBody(req), {})
|
|
532
|
+
const selection = Array.isArray(body.selection) ? body.selection : []
|
|
533
|
+
if (selection.length === 0) { json(res, 400, { ok: false, error: '没有选择任何插件' }); return }
|
|
534
|
+
if (body.async === true || body.background === true) {
|
|
535
|
+
const job = startPackJob(body)
|
|
536
|
+
json(res, 200, { ok: true, async: true, job: publicJob(job) })
|
|
537
|
+
return
|
|
538
|
+
}
|
|
539
|
+
const payload = await performPack(body, null)
|
|
540
|
+
json(res, 200, payload)
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
// 风险停下来之后:只有「我知道在干什么」,点它就在同一个任务里接着跑完
|
|
544
|
+
route('/dsh-modpack-kit/api/jobs/ack', async (req, res) => {
|
|
545
|
+
if (!needPost(req, res)) return
|
|
546
|
+
const body = asJson(await readBody(req), {})
|
|
547
|
+
const job = jobs.get(String(body.id || ''))
|
|
548
|
+
if (!job) { json(res, 404, { ok: false, error: '没有这个任务(可能已完成并过期)' }); return }
|
|
549
|
+
if (!job.risk) { json(res, 400, { ok: false, error: '这个任务没有风险项,不需要确认' }); return }
|
|
550
|
+
if (job.risk.needsAck !== true) { json(res, 400, { ok: false, error: '这些风险不在插件市场目录里,没法确认继续' }); return }
|
|
551
|
+
if (job.status === 'running') { json(res, 409, { ok: false, error: '任务还在跑,等它到风险点再说' }); return }
|
|
552
|
+
if (job.status !== 'paused') { json(res, 400, { ok: false, error: '这个任务已经收尾了,不能再确认' }); return }
|
|
553
|
+
// 同一个任务接着跑:复用停下来的那份检测结果,进度从检测点继续,不重新检测
|
|
554
|
+
const checkpoint = job.checkpoint || null
|
|
555
|
+
job.checkpoint = null
|
|
556
|
+
job.status = 'running'
|
|
557
|
+
job.cancelled = false
|
|
558
|
+
job.acked = true
|
|
559
|
+
// 确认过了就不该再吓人:红字(risk)撤掉,只留 status 与进度
|
|
560
|
+
job.risk = null
|
|
561
|
+
job.error = ''
|
|
562
|
+
job.note = checkpoint ? '已确认风险,从检测点继续' : '已确认风险,继续完成'
|
|
563
|
+
job.pct = Math.min(job.pct || 0, 66)
|
|
564
|
+
job.finishedAt = ''
|
|
565
|
+
const source = job.body || { selection: [] }
|
|
566
|
+
const replay = { selection: source.selection || [], options: { ...(source.options || {}), acknowledge: true } }
|
|
567
|
+
performPack(replay, job, checkpoint)
|
|
568
|
+
.then((payload) => finishPackJob(job, payload))
|
|
569
|
+
.catch((error) => {
|
|
570
|
+
job.status = 'failed'
|
|
571
|
+
job.error = String((error && error.message) || error)
|
|
572
|
+
job.note = '失败'
|
|
573
|
+
job.finishedAt = new Date().toISOString()
|
|
574
|
+
})
|
|
575
|
+
json(res, 200, { ok: true, job: publicJob(job) })
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
route('/dsh-modpack-kit/api/jobs/dismiss', async (req, res) => {
|
|
579
|
+
if (!needPost(req, res)) return
|
|
580
|
+
const body = asJson(await readBody(req), {})
|
|
581
|
+
const id = String(body.id || '')
|
|
582
|
+
const job = jobs.get(id)
|
|
583
|
+
if (!job) { json(res, 404, { ok: false, error: '没有这个任务(可能已经删了)' }); return }
|
|
584
|
+
if (job.status === 'running') { json(res, 400, { ok: false, error: '还在跑,先终止再删' }); return }
|
|
585
|
+
jobs.delete(id)
|
|
586
|
+
json(res, 200, { ok: true, removed: id })
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
// 清空进程:删掉所有收尾记录(完成的、失败的、取消的、超上限卡住的都算),
|
|
590
|
+
// 只有还在跑的与停在风险点等决定的留着。
|
|
591
|
+
route('/dsh-modpack-kit/api/jobs/clear', async (req, res) => {
|
|
592
|
+
if (!needPost(req, res)) return
|
|
593
|
+
const keep = new Set(['running', 'paused'])
|
|
594
|
+
const removed = []
|
|
595
|
+
for (const [id, job] of [...jobs.entries()]) {
|
|
596
|
+
if (keep.has(job.status)) continue
|
|
597
|
+
jobs.delete(id)
|
|
598
|
+
removed.push(id)
|
|
599
|
+
}
|
|
600
|
+
json(res, 200, { ok: true, removed, jobs: [...jobs.values()].map(publicJob) })
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
route('/dsh-modpack-kit/api/jobs/cancel', async (req, res) => {
|
|
604
|
+
if (!needPost(req, res)) return
|
|
605
|
+
const body = asJson(await readBody(req), {})
|
|
606
|
+
const job = jobs.get(String(body.id || ''))
|
|
607
|
+
if (!job) { json(res, 404, { ok: false, error: '没有这个任务(可能已完成并过期)' }); return }
|
|
608
|
+
if (job.status !== 'running') {
|
|
609
|
+
// 停在风险点的任务:立即停止就是把它标成已停止,不留文件
|
|
610
|
+
if (job.status === 'paused') {
|
|
611
|
+
job.checkpoint = null
|
|
612
|
+
job.status = 'cancelled'
|
|
613
|
+
job.note = '已停止(未生成文件,本地没有残留)'
|
|
614
|
+
job.finishedAt = job.finishedAt || new Date().toISOString()
|
|
615
|
+
json(res, 200, { ok: true, job: publicJob(job) })
|
|
373
616
|
return
|
|
374
617
|
}
|
|
375
|
-
json(res, 200, { ok:
|
|
618
|
+
json(res, 200, { ok: true, already: true, job: publicJob(job) })
|
|
619
|
+
return
|
|
376
620
|
}
|
|
621
|
+
job.cancelled = true
|
|
622
|
+
job.note = '正在停止…'
|
|
623
|
+
json(res, 200, { ok: true, job: publicJob(job) })
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
route('/dsh-modpack-kit/api/jobs', (req, res) => {
|
|
627
|
+
if (req.method !== 'GET') { json(res, 405, { ok: false, error: '只支持 GET' }); return }
|
|
628
|
+
pruneJobs()
|
|
629
|
+
json(res, 200, { ok: true, jobs: [...jobs.values()].map(publicJob) })
|
|
377
630
|
})
|
|
378
631
|
|
|
379
632
|
// —— 下载 / 落盘 ——
|
|
@@ -451,6 +704,7 @@ export default {
|
|
|
451
704
|
manifest: inspected.manifest,
|
|
452
705
|
integrity: inspected.integrity,
|
|
453
706
|
scan: inspected.scan,
|
|
707
|
+
scanGroups: groupFindings(inspected.scan.findings, inspected.manifest.plugins),
|
|
454
708
|
report: inspected.report,
|
|
455
709
|
blockingReasons: inspected.blockingReasons,
|
|
456
710
|
notes: inspected.notes,
|
|
@@ -478,7 +732,7 @@ export default {
|
|
|
478
732
|
const inspected = await inspectInput(body)
|
|
479
733
|
if (inspected.blockingReasons.length > 0 && !options.force) {
|
|
480
734
|
const refused = new InstallRefused(inspected.blockingReasons.join(';'), inspected.scan)
|
|
481
|
-
json(res, 200, { ok: false, refused: true, error: refused.message, integrity: inspected.integrity, scan: inspected.scan, report: inspected.report })
|
|
735
|
+
json(res, 200, { ok: false, refused: true, error: refused.message, integrity: inspected.integrity, scan: inspected.scan, scanGroups: groupFindings(inspected.scan.findings, inspected.manifest.plugins), report: inspected.report })
|
|
482
736
|
return
|
|
483
737
|
}
|
|
484
738
|
const result = await installPack({
|
|
@@ -504,7 +758,7 @@ export default {
|
|
|
504
758
|
},
|
|
505
759
|
})
|
|
506
760
|
appendHistory({ at: new Date().toISOString(), kind: 'install', name: inspected.manifest.name, format: inspected.manifest.format, ok: result.ok, pack: inspected.manifest.name, actions: result.actions.length }, config.historyLimit)
|
|
507
|
-
json(res, 200, { ok: result.ok, ...result, manifest: inspected.manifest, scan: inspected.scan, report: inspected.report, integrity: inspected.integrity })
|
|
761
|
+
json(res, 200, { ok: result.ok, ...result, manifest: inspected.manifest, scan: inspected.scan, scanGroups: groupFindings(inspected.scan.findings, inspected.manifest.plugins), report: inspected.report, integrity: inspected.integrity })
|
|
508
762
|
} catch (error) {
|
|
509
763
|
json(res, 200, { ok: false, error: String((error && error.message) || error) })
|
|
510
764
|
}
|
package/lib/install.mjs
CHANGED
|
@@ -105,9 +105,14 @@ export function inspectPackBuffer(buffer, options = {}) {
|
|
|
105
105
|
if (integrity.present && !integrity.ok) {
|
|
106
106
|
blockingReasons.push('完整性校验失败(' + (integrity.mismatches.length + integrity.missing.length) + ' 个文件对不上)')
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
// 打包方已确认(市场收录插件的确认放行)时,不再用高风险拦人;报告照常列明细。
|
|
109
|
+
const acknowledged = Boolean(manifest.security && (manifest.security.acknowledged === true || manifest.security.trustedOnly === true))
|
|
110
|
+
if (scan.counts.high > 0 && !options.force && !acknowledged) {
|
|
109
111
|
blockingReasons.push('安全检测发现 ' + scan.counts.high + ' 个高风险项')
|
|
110
112
|
}
|
|
113
|
+
if (scan.counts.high > 0 && acknowledged) {
|
|
114
|
+
notes.push('打包方已确认 ' + scan.counts.high + ' 个高风险项(市场收录插件),明细见扫描报告')
|
|
115
|
+
}
|
|
111
116
|
|
|
112
117
|
return { manifest, entries, integrity, scan, report, blockingReasons, notes }
|
|
113
118
|
}
|
|
@@ -237,7 +242,7 @@ export async function installPack(input) {
|
|
|
237
242
|
maxTotalBytes: 64 * 1024 * 1024,
|
|
238
243
|
})
|
|
239
244
|
const deep = scanEntries(brought.files, { extraRules: Array.isArray(config.extraScanRules) ? config.extraScanRules : [] })
|
|
240
|
-
if (deep.counts.high > 0 && !options.force) {
|
|
245
|
+
if (deep.counts.high > 0 && !options.force && !acknowledged) {
|
|
241
246
|
actions.push({ plugin: plugin.name, action: 'install', ok: false, message: '从市场取回的代码里有 ' + deep.counts.high + ' 个高风险项,已拦下' })
|
|
242
247
|
continue
|
|
243
248
|
}
|
package/lib/manifest.mjs
CHANGED
|
@@ -104,6 +104,8 @@ export function normalizeManifest(raw) {
|
|
|
104
104
|
medium: num(raw.security?.medium),
|
|
105
105
|
low: num(raw.security?.low),
|
|
106
106
|
approvedRisk: bool(raw.security?.approvedRisk),
|
|
107
|
+
acknowledged: bool(raw.security?.acknowledged),
|
|
108
|
+
trustedOnly: bool(raw.security?.trustedOnly),
|
|
107
109
|
note: str(raw.security?.note, 500),
|
|
108
110
|
},
|
|
109
111
|
install: {
|
|
@@ -154,25 +156,31 @@ export function buildReadme(manifest, extra = {}) {
|
|
|
154
156
|
lines.push('')
|
|
155
157
|
lines.push('怎么装')
|
|
156
158
|
if (manifest.format === 'lite') {
|
|
157
|
-
lines.push('
|
|
158
|
-
lines.push('
|
|
159
|
-
lines.push('
|
|
159
|
+
lines.push(' 方式 A(有 dsh-modpack 插件):侧栏「整合包 → 安装」选择本文件,会联网按版本取包并校验完整性。')
|
|
160
|
+
lines.push(' 方式 B(裸 DSH 也能装):解压后运行 install/ 里的安装器,它会按清单里的名字与版本从 registry 取包:')
|
|
161
|
+
lines.push(' Windows: install\\install.cmd 其它: sh install/install.sh')
|
|
162
|
+
lines.push(' 指定 profile 或 DSH 位置:加 --profile <名字> --dsh "<DSH 可执行文件或 cli.js>"')
|
|
160
163
|
} else {
|
|
161
164
|
lines.push(' 方式 A(推荐,有 dsh-modpack 插件):侧栏「整合包 → 安装」选择本文件,会校验完整性、')
|
|
162
165
|
lines.push(' 重新扫描安全项、检查兼容性,并把打包时保存的配置同步回来。')
|
|
163
|
-
lines.push(' 方式 B
|
|
164
|
-
lines.push(' 1.
|
|
165
|
-
lines.push(' 2.
|
|
166
|
-
lines.push('
|
|
167
|
-
lines.push('
|
|
168
|
-
lines.push('
|
|
169
|
-
lines.push('
|
|
166
|
+
lines.push(' 方式 B(没有任何插件、裸 DSH 也能装,推荐给没装本插件的人):')
|
|
167
|
+
lines.push(' 1. 解压整个 zip;')
|
|
168
|
+
lines.push(' 2. 运行包内安装器(需要 Node 20+):')
|
|
169
|
+
lines.push(' Windows: install\\install.cmd 其它: sh install/install.sh')
|
|
170
|
+
lines.push(' 可加参数:--profile <名字>(默认 desktop)--dry-run(只看要做什么)')
|
|
171
|
+
lines.push(' --no-bundles(装了但先不启用)--dsh "<DSH 可执行文件或 cli.js>"')
|
|
172
|
+
lines.push(' 3. 安装器会逐插件执行官方 dsh plugin add、把 configs/ 里的配置合并进 cordis.patch.yml;')
|
|
173
|
+
lines.push(' 4. 重启 DSH。')
|
|
174
|
+
lines.push(' 方式 C(手工,没有 Node 时):解压后对 plugins/ 下每个目录执行')
|
|
175
|
+
lines.push(' dsh plugin --profile <你的profile> add "file:<绝对路径>/plugins/<插件名>"')
|
|
176
|
+
lines.push(' 再把插件名加进 ~/.dsh/profiles/<你的profile>/package.json 的 dsh.profile.bundles。')
|
|
170
177
|
}
|
|
171
178
|
lines.push('')
|
|
172
179
|
lines.push('目录结构')
|
|
173
180
|
lines.push(' dsh-modpack.json 清单(机器可读,schema ' + SCHEMA + ')')
|
|
174
181
|
lines.push(' integrity.json 每个文件的 sha256')
|
|
175
182
|
lines.push(' security/ 安全检测报告(已打码)')
|
|
183
|
+
lines.push(' install/ 独立安装器(不依赖本插件,裸 DSH 可用)')
|
|
176
184
|
lines.push(' configs/ 打包时的非默认配置(每个插件一个 json)')
|
|
177
185
|
if (manifest.format === 'full') lines.push(' plugins/ 插件本体,一个目录一个插件')
|
|
178
186
|
lines.push(' data/ 插件数据快照(如果打包时选了保留)')
|