dsh-cookie-cleaner 0.7.1 → 0.7.2
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/CHANGELOG.md +10 -0
- package/LICENSE +21 -21
- package/README.md +432 -432
- package/cordis.patch.yml +5 -5
- package/dsh.plugin.json +1 -1
- package/lib/client.js +213 -1
- package/lib/client.js.map +1 -1
- package/package.json +1 -1
- package/scripts/gen-locales.mjs +82 -82
- package/scripts/hosts.mjs +57 -57
- package/scripts/sync-hosts.mjs +80 -80
- package/src/client/card.tsx +5 -0
- package/src/client/index.ts +129 -129
- package/src/client/star-row-copy.ts +256 -0
- package/src/i18n.js +140 -140
- package/src/jar-live.js +365 -365
- package/src/locales-advise-owner.js +39 -39
- package/src/locales-dict.js +220 -220
- package/src/locales-dict2.js +214 -214
- package/src/locales-patch.js +207 -207
- package/src/patch-model.js +271 -271
- package/src/report.js +243 -243
- package/src/settings-waist.js +37 -37
package/src/report.js
CHANGED
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-cookie-cleaner — 播报文案层(把处置说全,避免二次求助 AI)。
|
|
3
|
-
*
|
|
4
|
-
* core.js 只做机械动作,这里负责「现在是什么状况 + 下一步敲哪条命令」。
|
|
5
|
-
* 全部文案经 i18n 字典出(9 语),路径/条数/命令保持原样不译;
|
|
6
|
-
* 命令文案给出两种形态:npm bin 别名不可用时用 `node <包>/src/cli.js` 直跑。
|
|
7
|
-
*/
|
|
8
|
-
import path from 'node:path'
|
|
9
|
-
import process from 'node:process'
|
|
10
|
-
import { fileURLToPath } from 'node:url'
|
|
11
|
-
|
|
12
|
-
export * from './core.js'
|
|
13
|
-
import { activeLang, exitInstruction, setLang } from './core.js'
|
|
14
|
-
import { detectLang, translator } from './i18n.js'
|
|
15
|
-
import { patchText } from './locales-patch.js'
|
|
16
|
-
|
|
17
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
-
|
|
19
|
-
/** 未经 npm 全局 link 时也能直接跑的调用形态。 */
|
|
20
|
-
export function directRunCommand() {
|
|
21
|
-
return `node "${path.join(HERE, 'cli.js')}"`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** 按宿主/环境挑语言并激活;返回最终语言码。 */
|
|
25
|
-
export function useDetectedLang(explicit = '') {
|
|
26
|
-
const lang = explicit ? String(explicit).trim() : detectLang()
|
|
27
|
-
return setLang(lang)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* cookie 实时读数的一句(面板/命令面/CLI 共用)。
|
|
32
|
-
* 没折算结果就返回 undefined —— 绝不能拿“没读到”编一个 0%。
|
|
33
|
-
* 借句柄快照走 `cookieLiveSnapshot`:数字是真的,但不是实时,说成实时就是谎报。
|
|
34
|
-
* @param {{authCookies?:number,totalCookies?:number,header?:object,snapshot?:boolean}} [stat]
|
|
35
|
-
* @param {string} [lang]
|
|
36
|
-
*/
|
|
37
|
-
export function cookieLiveText(stat, lang) {
|
|
38
|
-
if (stat === undefined || stat.header === undefined) return undefined
|
|
39
|
-
return patchText('text', stat.snapshot === true ? 'cookieLiveSnapshot' : 'cookieLive', lang ?? activeLang(), {
|
|
40
|
-
count: String(stat.authCookies ?? 0),
|
|
41
|
-
total: String(stat.totalCookies ?? 0),
|
|
42
|
-
bytes: String(stat.header.bytes),
|
|
43
|
-
max: String(stat.header.maxHeaderBytes),
|
|
44
|
-
pct: String(stat.header.pct),
|
|
45
|
-
remaining: String(stat.header.remaining),
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 读不到的分档文案。三者不能共用一句:把“路径没找到/权限不够”说成“被 Chromium 占”是误引导。
|
|
51
|
-
* @param {string} [reason] statCookies 的 reason
|
|
52
|
-
* @param {string} [lang]
|
|
53
|
-
*/
|
|
54
|
-
export function cookieUnreadableText(reason, lang) {
|
|
55
|
-
const key = reason === 'missing' ? 'cookieMissing' : reason === 'permission' ? 'cookiePermission' : 'cookieBusy'
|
|
56
|
-
return patchText('text', key, lang ?? activeLang())
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 组装 `/cookie-cleaner` 的输出。
|
|
61
|
-
* @param {object} stat statCookies 结果(可能是 busy/permission/skipped 降级形态)
|
|
62
|
-
* @param {{expiredOnly?:boolean, userDataRoot?:string, mode?:'status'|'clean', platform?:string, lang?:string}} [cfg]
|
|
63
|
-
*/
|
|
64
|
-
export function cookieCleanerCommandText(stat, cfg = {}) {
|
|
65
|
-
if (cfg.lang) setLang(cfg.lang)
|
|
66
|
-
const lang = cfg.lang ?? activeLang()
|
|
67
|
-
const t = translator(lang)
|
|
68
|
-
const platform = cfg.platform ?? process.platform
|
|
69
|
-
const exit = exitInstruction(platform, lang)
|
|
70
|
-
const lines = []
|
|
71
|
-
const mode = cfg.mode === 'clean' ? 'clean' : 'status'
|
|
72
|
-
|
|
73
|
-
if (stat.verdict === 'skipped') {
|
|
74
|
-
lines.push(t('skipped'))
|
|
75
|
-
lines.push(t('skippedCandidates') + '\n ' + (stat.candidates ?? []).join('\n '))
|
|
76
|
-
lines.push(t('skippedHint'))
|
|
77
|
-
return lines.join('\n')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (stat.reason === 'permission') {
|
|
81
|
-
lines.push(t('permission', { path: stat.path }))
|
|
82
|
-
lines.push(t('permissionHint'))
|
|
83
|
-
lines.push(` ${directRunCommand()} --db="${stat.path ?? '<cookie db path>'}" --clean --dry-run`)
|
|
84
|
-
return lines.join('\n')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (stat.reason === 'busy') {
|
|
88
|
-
lines.push(t('busy', { path: stat.path }))
|
|
89
|
-
lines.push(t('busyWhy'))
|
|
90
|
-
lines.push(t('nextClean', { exit }))
|
|
91
|
-
lines.push(` ${directRunCommand()} --clean`)
|
|
92
|
-
return lines.join('\n')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (stat.verdict === 'error') {
|
|
96
|
-
lines.push(`${t('cleanFailed')}${stat.message ?? 'unknown'}`)
|
|
97
|
-
return lines.join('\n')
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
lines.push(t('dbLine', { path: stat.path, bytes: stat.bytes, total: stat.totalCookies }))
|
|
101
|
-
// 占用折算与面板/命令面共用同一个 `cookieLive`(同一张 9 语表),两边不得各自拼一套句式。
|
|
102
|
-
const liveLine = cookieLiveText(stat, lang)
|
|
103
|
-
if (stat.verdict === 'ok') {
|
|
104
|
-
lines.push(t('ok'))
|
|
105
|
-
if (liveLine !== undefined) lines.push(liveLine)
|
|
106
|
-
return lines.join('\n')
|
|
107
|
-
}
|
|
108
|
-
lines.push(t('found', { count: stat.authCookies, expired: stat.authExpired, live: stat.authLive }))
|
|
109
|
-
lines.push(t('span', { oldest: stat.oldestExpiry, newest: stat.newestExpiry }))
|
|
110
|
-
lines.push(t('hostLine') + stat.byHost.map((row) => `${row.hostKey}×${row.count}`).join(', '))
|
|
111
|
-
if (liveLine !== undefined) lines.push(liveLine)
|
|
112
|
-
lines.push(t('note'))
|
|
113
|
-
|
|
114
|
-
const flag = cfg.expiredOnly === true ? ' --expired-only' : ''
|
|
115
|
-
lines.push(mode === 'status' ? t('nextStatus', { exit }) : t('nextClean', { exit }))
|
|
116
|
-
lines.push(` ${directRunCommand()} --clean${flag}`)
|
|
117
|
-
lines.push(t('cleanFooter'))
|
|
118
|
-
return lines.join('\n')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const VERDICT_KEY = Object.freeze({ ok: 'vOk', warn: 'vWarn', fail: 'vFail', skipped: 'vSkipped' })
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 组装 patch 体检结果(命令面与面板共用同一份渲染,保证「按按钮」与「敲命令」不同案)。
|
|
125
|
-
* @param {object} result patch-guard check/plan 的返回
|
|
126
|
-
* @param {{lang?:string, platform?:string, outcome?:object, withPlan?:boolean}} [cfg]
|
|
127
|
-
*/
|
|
128
|
-
export function patchReportText(result, cfg = {}) {
|
|
129
|
-
if (cfg.lang) setLang(cfg.lang)
|
|
130
|
-
const lang = cfg.lang ?? activeLang()
|
|
131
|
-
const L = (key, params) => patchText('text', key, lang, params)
|
|
132
|
-
const C = (code, params) => patchText('code', code, lang, params)
|
|
133
|
-
const lines = []
|
|
134
|
-
|
|
135
|
-
if (result.reason === 'no-config-editor') {
|
|
136
|
-
lines.push(L('title'))
|
|
137
|
-
lines.push(L('noService'))
|
|
138
|
-
return lines.join('\n')
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// 无据档单独渲染:不能把「profile 不存在」混进「有偏差」的叙事里(也不给 nextFix 这种误导下一步)。
|
|
142
|
-
if (result.reason === 'missing-profile') {
|
|
143
|
-
lines.push(`${L('title')} — ${L('vSkipped')}`)
|
|
144
|
-
if (result.documentPath) lines.push(result.documentPath)
|
|
145
|
-
lines.push(L('missingProfile'))
|
|
146
|
-
return lines.join('\n')
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
lines.push(`${L('title')} — ${L(VERDICT_KEY[result.level] ?? 'vSkipped')}`)
|
|
150
|
-
if (result.documentPath) lines.push(result.documentPath)
|
|
151
|
-
if (result.offline === true) lines.push(L('offlineNote'))
|
|
152
|
-
|
|
153
|
-
const rows = result.rows ?? []
|
|
154
|
-
if (result.level === 'ok') {
|
|
155
|
-
// 结构无差异:一句话给肯定结论,不逐行刷「结构健康」(真机口径:用户要的是「注入正常」这个判定)。
|
|
156
|
-
lines.push(`\u2713 ${L('injectOk')}`)
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
for (const row of rows) {
|
|
160
|
-
const label = row.rowId === 'connection' ? 'rowConnection' : 'rowWebserver'
|
|
161
|
-
lines.push(`\u25aa ${L(label)}: ${L(VERDICT_KEY[row.level] ?? 'vSkipped')}`)
|
|
162
|
-
for (const finding of row.findings ?? []) lines.push(` \u00b7 ${C(finding.code, finding.params)}`)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (result.blocks !== undefined && result.blocks.length > 0) {
|
|
167
|
-
for (const block of result.blocks) {
|
|
168
|
-
lines.push('')
|
|
169
|
-
lines.push(L('planFor', { file: result.documentPath ?? 'cordis.patch.yml' }))
|
|
170
|
-
lines.push(block.block)
|
|
171
|
-
// 表达式被抄成字面量不在体检里刷屏,但处方里必须说清:哪些键原本会跟随上游、怎么拿回跟随形态。
|
|
172
|
-
if ((block.exprFrozen ?? []).length > 0) {
|
|
173
|
-
lines.push('')
|
|
174
|
-
lines.push(C('P9', { rowId: block.rowId, keys: block.exprFrozen }))
|
|
175
|
-
lines.push(L('exprFrozenHint'))
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if ((result.rows ?? []).some((row) => row.rowId === 'webserver' && (row.findings ?? []).length > 0)) {
|
|
181
|
-
lines.push('')
|
|
182
|
-
lines.push(L('webserverNote'))
|
|
183
|
-
}
|
|
184
|
-
const conn = (result.rows ?? []).find((row) => row.rowId === 'connection')
|
|
185
|
-
// 真正有效的那一项先说明自已是哪个值:面板隐藏了端口控件后,用户得看得到
|
|
186
|
-
// 「修复」到底写什么。行上没带时退到顶层 targetDays(两侧任一侧有就能说清)。
|
|
187
|
-
const targetDays = result.targetDays ?? conn?.targetDays
|
|
188
|
-
if (Number.isInteger(targetDays) && targetDays >= 1) {
|
|
189
|
-
lines.push('')
|
|
190
|
-
lines.push(patchText('text', 'targetDaysLine', lang ?? activeLang(), { days: String(targetDays) }))
|
|
191
|
-
}
|
|
192
|
-
if (conn?.actionable === true && cfg.outcome === undefined) {
|
|
193
|
-
lines.push('')
|
|
194
|
-
lines.push(L('nextFix'))
|
|
195
|
-
}
|
|
196
|
-
// cookie 读数与面板同构:同一个折算函数出同一句话。
|
|
197
|
-
if (result.cookie !== undefined) {
|
|
198
|
-
const c = result.cookie
|
|
199
|
-
const readable = c.verdict !== 'skipped' && c.reason !== 'busy' && c.reason !== 'permission'
|
|
200
|
-
lines.push('')
|
|
201
|
-
if (!readable) lines.push(cookieUnreadableText(c.reason, lang))
|
|
202
|
-
else {
|
|
203
|
-
const live = cookieLiveText(c, lang)
|
|
204
|
-
lines.push(live ?? `${String(c.authCookies ?? '?')} dsh-auth-* / ${String(c.totalCookies ?? '?')} total`)
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
// 运行期守护状态行(面板与命令面共用):runtimeGuard 字段存在才渲染,旧行为不受影响。
|
|
208
|
-
if (result.runtimeGuard !== undefined) {
|
|
209
|
-
lines.push('')
|
|
210
|
-
if (result.runtimeGuard === true) {
|
|
211
|
-
lines.push(patchText('text', 'guardOn', lang, {
|
|
212
|
-
budget: String(result.maxHeaderBytes ?? 65536),
|
|
213
|
-
keep: String(result.keep ?? 4),
|
|
214
|
-
cap: '96',
|
|
215
|
-
}))
|
|
216
|
-
} else {
|
|
217
|
-
lines.push(patchText('text', 'guardOff', lang))
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (cfg.outcome !== undefined) lines.push('', patchOutcomeText(cfg.outcome, { lang }))
|
|
222
|
-
return lines.join('\n')
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** 修复/回滚结果的固定句式(kind 来自 patch-guard,不在此处二次判定)。 */
|
|
226
|
-
export function patchOutcomeText(outcome, cfg = {}) {
|
|
227
|
-
const lang = cfg.lang ?? activeLang()
|
|
228
|
-
const L = (key, params) => patchText('text', key, lang, params)
|
|
229
|
-
switch (outcome.kind) {
|
|
230
|
-
case 'fixed': return L('fixed', { changed: (outcome.changed ?? []).join(', ') })
|
|
231
|
-
+ (outcome.retried === true ? ` (${L('vWarn')}: P12)` : '')
|
|
232
|
-
case 'noop': return L('noop')
|
|
233
|
-
case 'blocked': return L('blocked', { codes: (outcome.codes ?? []).join(', ') })
|
|
234
|
-
case 'failed': return L('failed', { message: outcome.message ?? 'unknown' })
|
|
235
|
-
case 'unverified': return L('failed', { message: `effective=${String(outcome.effective)}` })
|
|
236
|
-
case 'reverted': return L('reverted', { changed: (outcome.changed ?? []).join(', ') })
|
|
237
|
-
+ ((outcome.rows ?? []).length > 1 ? ` (${(outcome.rows ?? []).join(', ')})` : '')
|
|
238
|
-
+ ((outcome.failed ?? []).length > 0 ? ` (${L('failed', { message: (outcome.failed ?? []).map((f) => f.rowId).join(', ') })})` : '')
|
|
239
|
-
case 'no-snapshot': return L('noSnapshot')
|
|
240
|
-
case 'no-editor': return L('noService')
|
|
241
|
-
default: return L('failed', { message: outcome.kind ?? 'unknown' })
|
|
242
|
-
}
|
|
243
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* dsh-cookie-cleaner — 播报文案层(把处置说全,避免二次求助 AI)。
|
|
3
|
+
*
|
|
4
|
+
* core.js 只做机械动作,这里负责「现在是什么状况 + 下一步敲哪条命令」。
|
|
5
|
+
* 全部文案经 i18n 字典出(9 语),路径/条数/命令保持原样不译;
|
|
6
|
+
* 命令文案给出两种形态:npm bin 别名不可用时用 `node <包>/src/cli.js` 直跑。
|
|
7
|
+
*/
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import process from 'node:process'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
|
|
12
|
+
export * from './core.js'
|
|
13
|
+
import { activeLang, exitInstruction, setLang } from './core.js'
|
|
14
|
+
import { detectLang, translator } from './i18n.js'
|
|
15
|
+
import { patchText } from './locales-patch.js'
|
|
16
|
+
|
|
17
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
|
|
19
|
+
/** 未经 npm 全局 link 时也能直接跑的调用形态。 */
|
|
20
|
+
export function directRunCommand() {
|
|
21
|
+
return `node "${path.join(HERE, 'cli.js')}"`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 按宿主/环境挑语言并激活;返回最终语言码。 */
|
|
25
|
+
export function useDetectedLang(explicit = '') {
|
|
26
|
+
const lang = explicit ? String(explicit).trim() : detectLang()
|
|
27
|
+
return setLang(lang)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* cookie 实时读数的一句(面板/命令面/CLI 共用)。
|
|
32
|
+
* 没折算结果就返回 undefined —— 绝不能拿“没读到”编一个 0%。
|
|
33
|
+
* 借句柄快照走 `cookieLiveSnapshot`:数字是真的,但不是实时,说成实时就是谎报。
|
|
34
|
+
* @param {{authCookies?:number,totalCookies?:number,header?:object,snapshot?:boolean}} [stat]
|
|
35
|
+
* @param {string} [lang]
|
|
36
|
+
*/
|
|
37
|
+
export function cookieLiveText(stat, lang) {
|
|
38
|
+
if (stat === undefined || stat.header === undefined) return undefined
|
|
39
|
+
return patchText('text', stat.snapshot === true ? 'cookieLiveSnapshot' : 'cookieLive', lang ?? activeLang(), {
|
|
40
|
+
count: String(stat.authCookies ?? 0),
|
|
41
|
+
total: String(stat.totalCookies ?? 0),
|
|
42
|
+
bytes: String(stat.header.bytes),
|
|
43
|
+
max: String(stat.header.maxHeaderBytes),
|
|
44
|
+
pct: String(stat.header.pct),
|
|
45
|
+
remaining: String(stat.header.remaining),
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 读不到的分档文案。三者不能共用一句:把“路径没找到/权限不够”说成“被 Chromium 占”是误引导。
|
|
51
|
+
* @param {string} [reason] statCookies 的 reason
|
|
52
|
+
* @param {string} [lang]
|
|
53
|
+
*/
|
|
54
|
+
export function cookieUnreadableText(reason, lang) {
|
|
55
|
+
const key = reason === 'missing' ? 'cookieMissing' : reason === 'permission' ? 'cookiePermission' : 'cookieBusy'
|
|
56
|
+
return patchText('text', key, lang ?? activeLang())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 组装 `/cookie-cleaner` 的输出。
|
|
61
|
+
* @param {object} stat statCookies 结果(可能是 busy/permission/skipped 降级形态)
|
|
62
|
+
* @param {{expiredOnly?:boolean, userDataRoot?:string, mode?:'status'|'clean', platform?:string, lang?:string}} [cfg]
|
|
63
|
+
*/
|
|
64
|
+
export function cookieCleanerCommandText(stat, cfg = {}) {
|
|
65
|
+
if (cfg.lang) setLang(cfg.lang)
|
|
66
|
+
const lang = cfg.lang ?? activeLang()
|
|
67
|
+
const t = translator(lang)
|
|
68
|
+
const platform = cfg.platform ?? process.platform
|
|
69
|
+
const exit = exitInstruction(platform, lang)
|
|
70
|
+
const lines = []
|
|
71
|
+
const mode = cfg.mode === 'clean' ? 'clean' : 'status'
|
|
72
|
+
|
|
73
|
+
if (stat.verdict === 'skipped') {
|
|
74
|
+
lines.push(t('skipped'))
|
|
75
|
+
lines.push(t('skippedCandidates') + '\n ' + (stat.candidates ?? []).join('\n '))
|
|
76
|
+
lines.push(t('skippedHint'))
|
|
77
|
+
return lines.join('\n')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (stat.reason === 'permission') {
|
|
81
|
+
lines.push(t('permission', { path: stat.path }))
|
|
82
|
+
lines.push(t('permissionHint'))
|
|
83
|
+
lines.push(` ${directRunCommand()} --db="${stat.path ?? '<cookie db path>'}" --clean --dry-run`)
|
|
84
|
+
return lines.join('\n')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (stat.reason === 'busy') {
|
|
88
|
+
lines.push(t('busy', { path: stat.path }))
|
|
89
|
+
lines.push(t('busyWhy'))
|
|
90
|
+
lines.push(t('nextClean', { exit }))
|
|
91
|
+
lines.push(` ${directRunCommand()} --clean`)
|
|
92
|
+
return lines.join('\n')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (stat.verdict === 'error') {
|
|
96
|
+
lines.push(`${t('cleanFailed')}${stat.message ?? 'unknown'}`)
|
|
97
|
+
return lines.join('\n')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
lines.push(t('dbLine', { path: stat.path, bytes: stat.bytes, total: stat.totalCookies }))
|
|
101
|
+
// 占用折算与面板/命令面共用同一个 `cookieLive`(同一张 9 语表),两边不得各自拼一套句式。
|
|
102
|
+
const liveLine = cookieLiveText(stat, lang)
|
|
103
|
+
if (stat.verdict === 'ok') {
|
|
104
|
+
lines.push(t('ok'))
|
|
105
|
+
if (liveLine !== undefined) lines.push(liveLine)
|
|
106
|
+
return lines.join('\n')
|
|
107
|
+
}
|
|
108
|
+
lines.push(t('found', { count: stat.authCookies, expired: stat.authExpired, live: stat.authLive }))
|
|
109
|
+
lines.push(t('span', { oldest: stat.oldestExpiry, newest: stat.newestExpiry }))
|
|
110
|
+
lines.push(t('hostLine') + stat.byHost.map((row) => `${row.hostKey}×${row.count}`).join(', '))
|
|
111
|
+
if (liveLine !== undefined) lines.push(liveLine)
|
|
112
|
+
lines.push(t('note'))
|
|
113
|
+
|
|
114
|
+
const flag = cfg.expiredOnly === true ? ' --expired-only' : ''
|
|
115
|
+
lines.push(mode === 'status' ? t('nextStatus', { exit }) : t('nextClean', { exit }))
|
|
116
|
+
lines.push(` ${directRunCommand()} --clean${flag}`)
|
|
117
|
+
lines.push(t('cleanFooter'))
|
|
118
|
+
return lines.join('\n')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const VERDICT_KEY = Object.freeze({ ok: 'vOk', warn: 'vWarn', fail: 'vFail', skipped: 'vSkipped' })
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 组装 patch 体检结果(命令面与面板共用同一份渲染,保证「按按钮」与「敲命令」不同案)。
|
|
125
|
+
* @param {object} result patch-guard check/plan 的返回
|
|
126
|
+
* @param {{lang?:string, platform?:string, outcome?:object, withPlan?:boolean}} [cfg]
|
|
127
|
+
*/
|
|
128
|
+
export function patchReportText(result, cfg = {}) {
|
|
129
|
+
if (cfg.lang) setLang(cfg.lang)
|
|
130
|
+
const lang = cfg.lang ?? activeLang()
|
|
131
|
+
const L = (key, params) => patchText('text', key, lang, params)
|
|
132
|
+
const C = (code, params) => patchText('code', code, lang, params)
|
|
133
|
+
const lines = []
|
|
134
|
+
|
|
135
|
+
if (result.reason === 'no-config-editor') {
|
|
136
|
+
lines.push(L('title'))
|
|
137
|
+
lines.push(L('noService'))
|
|
138
|
+
return lines.join('\n')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 无据档单独渲染:不能把「profile 不存在」混进「有偏差」的叙事里(也不给 nextFix 这种误导下一步)。
|
|
142
|
+
if (result.reason === 'missing-profile') {
|
|
143
|
+
lines.push(`${L('title')} — ${L('vSkipped')}`)
|
|
144
|
+
if (result.documentPath) lines.push(result.documentPath)
|
|
145
|
+
lines.push(L('missingProfile'))
|
|
146
|
+
return lines.join('\n')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
lines.push(`${L('title')} — ${L(VERDICT_KEY[result.level] ?? 'vSkipped')}`)
|
|
150
|
+
if (result.documentPath) lines.push(result.documentPath)
|
|
151
|
+
if (result.offline === true) lines.push(L('offlineNote'))
|
|
152
|
+
|
|
153
|
+
const rows = result.rows ?? []
|
|
154
|
+
if (result.level === 'ok') {
|
|
155
|
+
// 结构无差异:一句话给肯定结论,不逐行刷「结构健康」(真机口径:用户要的是「注入正常」这个判定)。
|
|
156
|
+
lines.push(`\u2713 ${L('injectOk')}`)
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
for (const row of rows) {
|
|
160
|
+
const label = row.rowId === 'connection' ? 'rowConnection' : 'rowWebserver'
|
|
161
|
+
lines.push(`\u25aa ${L(label)}: ${L(VERDICT_KEY[row.level] ?? 'vSkipped')}`)
|
|
162
|
+
for (const finding of row.findings ?? []) lines.push(` \u00b7 ${C(finding.code, finding.params)}`)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (result.blocks !== undefined && result.blocks.length > 0) {
|
|
167
|
+
for (const block of result.blocks) {
|
|
168
|
+
lines.push('')
|
|
169
|
+
lines.push(L('planFor', { file: result.documentPath ?? 'cordis.patch.yml' }))
|
|
170
|
+
lines.push(block.block)
|
|
171
|
+
// 表达式被抄成字面量不在体检里刷屏,但处方里必须说清:哪些键原本会跟随上游、怎么拿回跟随形态。
|
|
172
|
+
if ((block.exprFrozen ?? []).length > 0) {
|
|
173
|
+
lines.push('')
|
|
174
|
+
lines.push(C('P9', { rowId: block.rowId, keys: block.exprFrozen }))
|
|
175
|
+
lines.push(L('exprFrozenHint'))
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if ((result.rows ?? []).some((row) => row.rowId === 'webserver' && (row.findings ?? []).length > 0)) {
|
|
181
|
+
lines.push('')
|
|
182
|
+
lines.push(L('webserverNote'))
|
|
183
|
+
}
|
|
184
|
+
const conn = (result.rows ?? []).find((row) => row.rowId === 'connection')
|
|
185
|
+
// 真正有效的那一项先说明自已是哪个值:面板隐藏了端口控件后,用户得看得到
|
|
186
|
+
// 「修复」到底写什么。行上没带时退到顶层 targetDays(两侧任一侧有就能说清)。
|
|
187
|
+
const targetDays = result.targetDays ?? conn?.targetDays
|
|
188
|
+
if (Number.isInteger(targetDays) && targetDays >= 1) {
|
|
189
|
+
lines.push('')
|
|
190
|
+
lines.push(patchText('text', 'targetDaysLine', lang ?? activeLang(), { days: String(targetDays) }))
|
|
191
|
+
}
|
|
192
|
+
if (conn?.actionable === true && cfg.outcome === undefined) {
|
|
193
|
+
lines.push('')
|
|
194
|
+
lines.push(L('nextFix'))
|
|
195
|
+
}
|
|
196
|
+
// cookie 读数与面板同构:同一个折算函数出同一句话。
|
|
197
|
+
if (result.cookie !== undefined) {
|
|
198
|
+
const c = result.cookie
|
|
199
|
+
const readable = c.verdict !== 'skipped' && c.reason !== 'busy' && c.reason !== 'permission'
|
|
200
|
+
lines.push('')
|
|
201
|
+
if (!readable) lines.push(cookieUnreadableText(c.reason, lang))
|
|
202
|
+
else {
|
|
203
|
+
const live = cookieLiveText(c, lang)
|
|
204
|
+
lines.push(live ?? `${String(c.authCookies ?? '?')} dsh-auth-* / ${String(c.totalCookies ?? '?')} total`)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// 运行期守护状态行(面板与命令面共用):runtimeGuard 字段存在才渲染,旧行为不受影响。
|
|
208
|
+
if (result.runtimeGuard !== undefined) {
|
|
209
|
+
lines.push('')
|
|
210
|
+
if (result.runtimeGuard === true) {
|
|
211
|
+
lines.push(patchText('text', 'guardOn', lang, {
|
|
212
|
+
budget: String(result.maxHeaderBytes ?? 65536),
|
|
213
|
+
keep: String(result.keep ?? 4),
|
|
214
|
+
cap: '96',
|
|
215
|
+
}))
|
|
216
|
+
} else {
|
|
217
|
+
lines.push(patchText('text', 'guardOff', lang))
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (cfg.outcome !== undefined) lines.push('', patchOutcomeText(cfg.outcome, { lang }))
|
|
222
|
+
return lines.join('\n')
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** 修复/回滚结果的固定句式(kind 来自 patch-guard,不在此处二次判定)。 */
|
|
226
|
+
export function patchOutcomeText(outcome, cfg = {}) {
|
|
227
|
+
const lang = cfg.lang ?? activeLang()
|
|
228
|
+
const L = (key, params) => patchText('text', key, lang, params)
|
|
229
|
+
switch (outcome.kind) {
|
|
230
|
+
case 'fixed': return L('fixed', { changed: (outcome.changed ?? []).join(', ') })
|
|
231
|
+
+ (outcome.retried === true ? ` (${L('vWarn')}: P12)` : '')
|
|
232
|
+
case 'noop': return L('noop')
|
|
233
|
+
case 'blocked': return L('blocked', { codes: (outcome.codes ?? []).join(', ') })
|
|
234
|
+
case 'failed': return L('failed', { message: outcome.message ?? 'unknown' })
|
|
235
|
+
case 'unverified': return L('failed', { message: `effective=${String(outcome.effective)}` })
|
|
236
|
+
case 'reverted': return L('reverted', { changed: (outcome.changed ?? []).join(', ') })
|
|
237
|
+
+ ((outcome.rows ?? []).length > 1 ? ` (${(outcome.rows ?? []).join(', ')})` : '')
|
|
238
|
+
+ ((outcome.failed ?? []).length > 0 ? ` (${L('failed', { message: (outcome.failed ?? []).map((f) => f.rowId).join(', ') })})` : '')
|
|
239
|
+
case 'no-snapshot': return L('noSnapshot')
|
|
240
|
+
case 'no-editor': return L('noService')
|
|
241
|
+
default: return L('failed', { message: outcome.kind ?? 'unknown' })
|
|
242
|
+
}
|
|
243
|
+
}
|
package/src/settings-waist.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-cookie-cleaner — 三代宿主设置 waist(特性检测分派,禁止读版本号)。
|
|
3
|
-
*
|
|
4
|
-
* 检测点互斥、只用 settings 服务自身的方法:
|
|
5
|
-
* - 0.1.2-rc.1 / 0.1.5-rc.x:实例带 `installSection`(注册 ns + 原生表单挂账 +
|
|
6
|
-
* `setSource` 换绑配置源;base 必须传 resolveConfig 解包后的普通值,活引用直传
|
|
7
|
-
* 会 ValidationError 且 cordis 静默吞掉 inject 回调异常);
|
|
8
|
-
* - 0.1.0-rc.x / 0.1.1-rc.x:只有 `register/update/mutate/describe`(壳没有设置页,
|
|
9
|
-
* 注册 ns 即拿到持久化与桥读写,非缺陷);
|
|
10
|
-
* - 0.1.7-rc.1+ / 0.2.x:两个注册 API 都已移除,volatile Config 由 loader 托管
|
|
11
|
-
* 存储,本插件没有 client 卡,设置面即宿主自动表单。
|
|
12
|
-
* 任何线缺方法都只降级(走 patch 配置 + 默认值),绝不 fatal。
|
|
13
|
-
*/
|
|
14
|
-
export function installSettingsWaist(ctx, { ns, Config, base, onSource }) {
|
|
15
|
-
ctx.inject(['settings'], (sctx) => {
|
|
16
|
-
const svc = sctx.settings
|
|
17
|
-
if (typeof svc.installSection === 'function') {
|
|
18
|
-
try {
|
|
19
|
-
svc.installSection(ctx, ns, Config, base(), {
|
|
20
|
-
setSource: (source) => onSource(source),
|
|
21
|
-
onChange: () => {},
|
|
22
|
-
})
|
|
23
|
-
console.warn(`${ns}: settings via installSection (0.1.2/0.1.5 line)`)
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.warn(`${ns}: installSection FAILED:`, e?.stack ?? e)
|
|
26
|
-
}
|
|
27
|
-
} else if (typeof svc.register === 'function') {
|
|
28
|
-
try {
|
|
29
|
-
svc.register(ns, Config, { base: base() })
|
|
30
|
-
console.warn(`${ns}: settings via register (0.1.0/0.1.1 line)`)
|
|
31
|
-
} catch (e) {
|
|
32
|
-
console.warn(`${ns}: register FAILED:`, e?.stack ?? e)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// 其余代际:无需动作。
|
|
36
|
-
})
|
|
37
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* dsh-cookie-cleaner — 三代宿主设置 waist(特性检测分派,禁止读版本号)。
|
|
3
|
+
*
|
|
4
|
+
* 检测点互斥、只用 settings 服务自身的方法:
|
|
5
|
+
* - 0.1.2-rc.1 / 0.1.5-rc.x:实例带 `installSection`(注册 ns + 原生表单挂账 +
|
|
6
|
+
* `setSource` 换绑配置源;base 必须传 resolveConfig 解包后的普通值,活引用直传
|
|
7
|
+
* 会 ValidationError 且 cordis 静默吞掉 inject 回调异常);
|
|
8
|
+
* - 0.1.0-rc.x / 0.1.1-rc.x:只有 `register/update/mutate/describe`(壳没有设置页,
|
|
9
|
+
* 注册 ns 即拿到持久化与桥读写,非缺陷);
|
|
10
|
+
* - 0.1.7-rc.1+ / 0.2.x:两个注册 API 都已移除,volatile Config 由 loader 托管
|
|
11
|
+
* 存储,本插件没有 client 卡,设置面即宿主自动表单。
|
|
12
|
+
* 任何线缺方法都只降级(走 patch 配置 + 默认值),绝不 fatal。
|
|
13
|
+
*/
|
|
14
|
+
export function installSettingsWaist(ctx, { ns, Config, base, onSource }) {
|
|
15
|
+
ctx.inject(['settings'], (sctx) => {
|
|
16
|
+
const svc = sctx.settings
|
|
17
|
+
if (typeof svc.installSection === 'function') {
|
|
18
|
+
try {
|
|
19
|
+
svc.installSection(ctx, ns, Config, base(), {
|
|
20
|
+
setSource: (source) => onSource(source),
|
|
21
|
+
onChange: () => {},
|
|
22
|
+
})
|
|
23
|
+
console.warn(`${ns}: settings via installSection (0.1.2/0.1.5 line)`)
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.warn(`${ns}: installSection FAILED:`, e?.stack ?? e)
|
|
26
|
+
}
|
|
27
|
+
} else if (typeof svc.register === 'function') {
|
|
28
|
+
try {
|
|
29
|
+
svc.register(ns, Config, { base: base() })
|
|
30
|
+
console.warn(`${ns}: settings via register (0.1.0/0.1.1 line)`)
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.warn(`${ns}: register FAILED:`, e?.stack ?? e)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// 其余代际:无需动作。
|
|
36
|
+
})
|
|
37
|
+
}
|