dsh-clash-subscription 0.6.0 → 0.6.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/client.js +31 -19
- package/index.js +32 -45
- package/lib/health.js +82 -0
- package/lib/routes.js +38 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -107,6 +107,9 @@ const en = {
|
|
|
107
107
|
statusDirect: 'Outbound policy not installed (direct)',
|
|
108
108
|
measuredAt: 'Last measurement: {time}',
|
|
109
109
|
never: 'never',
|
|
110
|
+
usableOk: 'usable',
|
|
111
|
+
usableBlocked: 'blocked',
|
|
112
|
+
usableUnknown: 'untested',
|
|
110
113
|
readOnly: 'This panel is read-only here; open it from Settings to edit.',
|
|
111
114
|
}
|
|
112
115
|
|
|
@@ -180,6 +183,9 @@ const zh = {
|
|
|
180
183
|
blockedTag: '已屏蔽',
|
|
181
184
|
blockedCount: '已屏蔽 {count} 个节点',
|
|
182
185
|
blockedInvalid: '正则无效,未生效:',
|
|
186
|
+
usableOk: '可用',
|
|
187
|
+
usableBlocked: '受限',
|
|
188
|
+
usableUnknown: '未测',
|
|
183
189
|
blockedEmpty: '还没有节点清单——先启动一次,这里就会出现可勾选的节点。',
|
|
184
190
|
blockedSearch: '筛选节点…',
|
|
185
191
|
blockedSelected: '已屏蔽 {count} / 共 {total}',
|
|
@@ -339,6 +345,10 @@ const CSS = `
|
|
|
339
345
|
.clxp-node + .clxp-node { border-top: 1px solid var(--dsh-border-muted, #eaeef2); }
|
|
340
346
|
.clxp-node-act { padding: 1px 6px; font-size: 12px; line-height: 1.4; border-radius: 4px; }
|
|
341
347
|
.clxp-node.current { background: var(--dsh-surface-subtle, #f6f8fa); font-weight: 600; }
|
|
348
|
+
.clxp-usable { flex: 0 0 auto; font-size: 11px; padding: 0 5px; border-radius: 3px; line-height: 1.6; }
|
|
349
|
+
.clxp-usable.ok { color: #1a7f37; background: rgba(26, 127, 55, 0.1); }
|
|
350
|
+
.clxp-usable.blocked { color: #cf222e; background: rgba(207, 34, 46, 0.1); }
|
|
351
|
+
.clxp-usable.unknown { color: var(--dsh-text-tertiary, #8b949e); background: var(--dsh-surface-subtle, #f6f8fa); }
|
|
342
352
|
.clxp-node-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
343
353
|
.clxp-delay { font-variant-numeric: tabular-nums; color: var(--dsh-text-secondary, #57606a); font-size: 12px; }
|
|
344
354
|
.clxp-delay.good { color: #1a7f37; }
|
|
@@ -495,6 +505,11 @@ function BlocklistPicker(props) {
|
|
|
495
505
|
function Panel(props) {
|
|
496
506
|
const { t, draft, live, delays, busy, message, probe, saving, dirty, open, editable } = props
|
|
497
507
|
const nodes = Array.isArray(live?.nodes) ? live.nodes : []
|
|
508
|
+
// One row per node from the server: latency and usability measured together, so the list
|
|
509
|
+
// shows "120 ms · usable" instead of needing a second list to answer the same question.
|
|
510
|
+
const rowsByName = new Map(
|
|
511
|
+
(Array.isArray(live?.nodeRows?.rows) ? live.nodeRows.rows : []).map((row) => [row.name, row]),
|
|
512
|
+
)
|
|
498
513
|
const subscriptions = Array.isArray(live?.subscriptions) && live.subscriptions.length > 0
|
|
499
514
|
? live.subscriptions
|
|
500
515
|
: // Before the first status poll resolves, fall back to the draft's own lines so the
|
|
@@ -698,34 +713,30 @@ function Panel(props) {
|
|
|
698
713
|
h('span', { key: 's', className: 'clxp-delay bad' }, t('blockedTag')),
|
|
699
714
|
])))
|
|
700
715
|
: null,
|
|
701
|
-
live?.capability !== undefined && Array.isArray(live.capability.nodes) && live.capability.nodes.length > 0
|
|
702
|
-
? h('p', { key: 'cp', className: 'clxp-note' }, fill(t('usableCount'), {
|
|
703
|
-
usable: live.capability.nodes.filter((row) => row.usable).length,
|
|
704
|
-
total: live.capability.nodes.length,
|
|
705
|
-
}) + ' · ' + t('requiredProbes') + ': ' + (live.capability.required ?? []).join(', '))
|
|
706
|
-
: null,
|
|
707
|
-
live?.capability !== undefined && Array.isArray(live.capability.nodes)
|
|
708
|
-
? h('div', { key: 'cpl', className: 'clxp-subs' },
|
|
709
|
-
live.capability.nodes
|
|
710
|
-
.filter((row) => !row.usable)
|
|
711
|
-
.slice(0, 6)
|
|
712
|
-
.map((row) => h('div', { key: row.name, className: 'clxp-sub' }, [
|
|
713
|
-
h('span', { key: 'n', className: 'clxp-node-name' }, row.name),
|
|
714
|
-
h('span', { key: 'f', className: 'clxp-delay bad' }, (row.failed ?? []).join(', ') || '-'),
|
|
715
|
-
])))
|
|
716
|
-
: null,
|
|
717
716
|
|
|
718
717
|
nodes.length === 0
|
|
719
718
|
? h('p', { key: 'em', className: 'clxp-note' }, t('noNodes'))
|
|
720
719
|
: h('div', { key: 'ls', className: 'clxp-nodes', role: 'listbox', 'aria-label': t('routing') },
|
|
721
|
-
nodes.map((name) =>
|
|
720
|
+
nodes.map((name) => {
|
|
721
|
+
// Latency and usability come from one measurement, so they are rendered from one
|
|
722
|
+
// row. Splitting them into two lists let the panel show "fast" beside "blocked"
|
|
723
|
+
// with nothing connecting the two.
|
|
724
|
+
const nodeRow = rowsByName.get(name)
|
|
725
|
+
const usable = nodeRow?.usable ?? 'unknown'
|
|
726
|
+
const shownDelay = nodeRow?.delay === undefined ? delays[name] : nodeRow.delay
|
|
727
|
+
return h('div', {
|
|
722
728
|
key: name,
|
|
723
729
|
className: `clxp-node${name === live?.node ? ' current' : ''}`,
|
|
724
730
|
role: 'option',
|
|
725
731
|
'aria-selected': name === live?.node,
|
|
726
732
|
}, [
|
|
727
733
|
h('span', { key: 'n', className: 'clxp-node-name', title: name }, name),
|
|
728
|
-
h('span', { key: 'd', className: delayClass(
|
|
734
|
+
h('span', { key: 'd', className: delayClass(shownDelay) }, delayText(shownDelay)),
|
|
735
|
+
h('span', {
|
|
736
|
+
key: 'u',
|
|
737
|
+
className: `clxp-usable ${usable}`,
|
|
738
|
+
title: (nodeRow?.failed ?? []).join(', '),
|
|
739
|
+
}, usable === 'ok' ? t('usableOk') : usable === 'blocked' ? t('usableBlocked') : t('usableUnknown')),
|
|
729
740
|
h('button', {
|
|
730
741
|
key: 't',
|
|
731
742
|
type: 'button',
|
|
@@ -742,7 +753,8 @@ function Panel(props) {
|
|
|
742
753
|
disabled: busy !== '' || !running || name === live?.node,
|
|
743
754
|
onClick: () => void props.onAction('select', { node: name }),
|
|
744
755
|
}, name === live?.node ? '✓' : t('select')),
|
|
745
|
-
])
|
|
756
|
+
])
|
|
757
|
+
})),
|
|
746
758
|
h('div', { key: 'ac', className: 'clxp-actions' }, [
|
|
747
759
|
h('button', { key: 'te', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test') }, busy === 'test' ? t('testing') : t('testNow')),
|
|
748
760
|
h('button', { key: 'ta', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test', { all: true }) }, busy === 'test' ? t('testing') : t('testAll')),
|
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { fetchGeoDatabases, hasGeoDatabase } from './lib/geo.js'
|
|
|
23
23
|
import { DEFAULT_PROBES, judgeNode, rankNodes, resolveProbes } from './lib/select.js'
|
|
24
24
|
import { buildExcludeFilter, isBlocked, partitionNodes, validateBlocklist } from './lib/blocklist.js'
|
|
25
25
|
import { readInventory, rememberNodes } from './lib/inventory.js'
|
|
26
|
+
import { buildNodeRows, summariseRows } from './lib/health.js'
|
|
26
27
|
import { installName, loadHttpProxyModule, locateInstallRoot, resolveFromInstall } from './lib/install.js'
|
|
27
28
|
import { Routing } from './lib/routing.js'
|
|
28
29
|
import {
|
|
@@ -318,15 +319,32 @@ export class Runtime {
|
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
const measured = new Map(this.measured)
|
|
322
|
+
const plan = resolveProbes(this.config.probes, this.config.requiredProbes)
|
|
323
|
+
const capability = new Map((this.lastMatrix ?? []).map((row) => [row.name, row]))
|
|
321
324
|
const batchSize = 5
|
|
322
325
|
for (let at = 0; at < candidates.length; at += batchSize) {
|
|
323
326
|
const batch = candidates.slice(at, at + batchSize)
|
|
327
|
+
// Latency and usability are measured in the same pass: a row that reports "120 ms" without
|
|
328
|
+
// saying whether the node can reach the required services answers half the question, and
|
|
329
|
+
// measuring them separately let the two disagree.
|
|
324
330
|
const answers = await Promise.all(
|
|
325
|
-
batch.map(async (name) =>
|
|
331
|
+
batch.map(async (name) => {
|
|
332
|
+
const delay = await this.core.delay(name, 5000)
|
|
333
|
+
const results = delay === null ? undefined : await this.core.capabilities(name, plan.probes, {
|
|
334
|
+
timeoutMs: this.config.probeTimeoutMs ?? 8000,
|
|
335
|
+
samples: this.config.probeSamples ?? 2,
|
|
336
|
+
})
|
|
337
|
+
return { name, delay, results }
|
|
338
|
+
}),
|
|
326
339
|
)
|
|
327
|
-
for (const answer of answers)
|
|
340
|
+
for (const answer of answers) {
|
|
341
|
+
measured.set(answer.name, answer.delay)
|
|
342
|
+
if (answer.results !== undefined) capability.set(answer.name, { name: answer.name, results: answer.results })
|
|
343
|
+
else capability.set(answer.name, { name: answer.name, results: {} })
|
|
344
|
+
}
|
|
328
345
|
}
|
|
329
346
|
this.measured = measured
|
|
347
|
+
this.lastMatrix = [...capability.values()]
|
|
330
348
|
this.measuredAt = Date.now()
|
|
331
349
|
return Object.fromEntries(measured)
|
|
332
350
|
}
|
|
@@ -1272,6 +1290,18 @@ export class Runtime {
|
|
|
1272
1290
|
idleSince: this.idleSince === undefined ? null : new Date(this.idleSince).toISOString(),
|
|
1273
1291
|
},
|
|
1274
1292
|
/** Per-node probe results from the last selection, and which services gate it. */
|
|
1293
|
+
/**
|
|
1294
|
+
* One row per live node with its latency and usability together. The panel draws this and
|
|
1295
|
+
* nothing else for the node list, so latency and capability cannot drift apart on screen.
|
|
1296
|
+
*/
|
|
1297
|
+
nodeRows: (() => {
|
|
1298
|
+
const live = group.all.filter((name) => name !== 'DIRECT')
|
|
1299
|
+
const rows = buildNodeRows(live, Object.fromEntries(this.measured), {
|
|
1300
|
+
required: resolveProbes(this.config.probes, this.config.requiredProbes).required,
|
|
1301
|
+
nodes: this.lastMatrix,
|
|
1302
|
+
})
|
|
1303
|
+
return { rows, summary: summariseRows(rows) }
|
|
1304
|
+
})(),
|
|
1275
1305
|
capability: {
|
|
1276
1306
|
required: resolveProbes(this.config.probes, this.config.requiredProbes).required,
|
|
1277
1307
|
probes: resolveProbes(this.config.probes, this.config.requiredProbes).probes.map((probe) => ({ id: probe.id, label: probe.label })),
|
|
@@ -1513,49 +1543,6 @@ function subscriptionTool(runtime) {
|
|
|
1513
1543
|
const report = await runtime.start()
|
|
1514
1544
|
return { ...report, summary: `已启动:${report.endpoint},节点「${report.group.now ?? '未选择'}」,共 ${Math.max(0, report.group.all.length - 1)} 个可选节点。` }
|
|
1515
1545
|
}
|
|
1516
|
-
if (action === 'blockSelection') {
|
|
1517
|
-
// The picker sends exact node names, so each becomes an anchored literal entry. Raw
|
|
1518
|
-
// regex text stays available in the blocklist field for whole-region removal; keeping
|
|
1519
|
-
// them apart means a checkbox can never accidentally behave as a pattern.
|
|
1520
|
-
const names = Array.isArray(body.names)
|
|
1521
|
-
? body.names.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim())
|
|
1522
|
-
: []
|
|
1523
|
-
const keepRegex = String(body.keepRegex ?? '').trim()
|
|
1524
|
-
const literals = names.join('\n')
|
|
1525
|
-
const list = [keepRegex, literals].filter((part) => part !== '').join('\n')
|
|
1526
|
-
const problems = validateBlocklist(list)
|
|
1527
|
-
if (problems.length > 0) {
|
|
1528
|
-
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
1529
|
-
return
|
|
1530
|
-
}
|
|
1531
|
-
const saved = await runtime.saveConfig({ blocklist: list })
|
|
1532
|
-
sendJson(response, 200, {
|
|
1533
|
-
ok: true,
|
|
1534
|
-
blocked: names.length,
|
|
1535
|
-
filter: buildExcludeFilter(list),
|
|
1536
|
-
config: saved.config,
|
|
1537
|
-
warnings: saved.warnings,
|
|
1538
|
-
})
|
|
1539
|
-
return
|
|
1540
|
-
}
|
|
1541
|
-
if (action === 'blocklist') {
|
|
1542
|
-
const raw = String(body.list ?? '')
|
|
1543
|
-
const problems = validateBlocklist(raw)
|
|
1544
|
-
// An invalid regex makes the core reject the whole provider, which empties the node table
|
|
1545
|
-
// — a far worse symptom than a rejected save. Catch it here instead.
|
|
1546
|
-
if (problems.length > 0) {
|
|
1547
|
-
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
1548
|
-
return
|
|
1549
|
-
}
|
|
1550
|
-
const saved = await runtime.saveConfig({ blocklist: raw })
|
|
1551
|
-
sendJson(response, 200, {
|
|
1552
|
-
ok: true,
|
|
1553
|
-
filter: buildExcludeFilter(raw),
|
|
1554
|
-
config: saved.config,
|
|
1555
|
-
warnings: saved.warnings,
|
|
1556
|
-
})
|
|
1557
|
-
return
|
|
1558
|
-
}
|
|
1559
1546
|
if (action === 'reselect') {
|
|
1560
1547
|
const result = await runtime.autoReselect({ force: true })
|
|
1561
1548
|
return {
|
package/lib/health.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-node health as one row the panel can render: delay plus usability.
|
|
3
|
+
*
|
|
4
|
+
* The panel used to show latency in the node list and usability in a separate capability
|
|
5
|
+
* block, which meant two lists of the same nodes and a reader had to join them by name. A
|
|
6
|
+
* single row carrying both is the whole point: "120 ms, usable" or "260 ms, OpenAI blocked"
|
|
7
|
+
* answers the question someone actually has when picking an exit.
|
|
8
|
+
*
|
|
9
|
+
* Usability is a three-state, not a boolean:
|
|
10
|
+
*
|
|
11
|
+
* - `unknown` — never probed, or probed before the current required set changed;
|
|
12
|
+
* - `ok` — every required service answered;
|
|
13
|
+
* - `blocked` — at least one did not.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-clash-proxy/health
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Build one row per node, joining the latency map with the capability matrix.
|
|
20
|
+
*
|
|
21
|
+
* @param names - node names the core currently carries.
|
|
22
|
+
* @param delays - node name to delay in ms, or null when it did not answer.
|
|
23
|
+
* @param capability - `{ required, nodes }` from the last selection, or undefined.
|
|
24
|
+
* @returns one row per node, in the order given.
|
|
25
|
+
*/
|
|
26
|
+
export function buildNodeRows(names, delays, capability) {
|
|
27
|
+
const list = Array.isArray(names) ? names : []
|
|
28
|
+
const delayMap = delays !== null && typeof delays === 'object' ? delays : {}
|
|
29
|
+
const required = Array.isArray(capability?.required) ? capability.required : []
|
|
30
|
+
const results = new Map()
|
|
31
|
+
for (const row of Array.isArray(capability?.nodes) ? capability.nodes : []) {
|
|
32
|
+
if (row !== null && typeof row === 'object' && typeof row.name === 'string') results.set(row.name, row)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return list.map((name) => {
|
|
36
|
+
const delay = Object.hasOwn(delayMap, name) ? delayMap[name] : undefined
|
|
37
|
+
const measured = results.get(name)
|
|
38
|
+
let usable = 'unknown'
|
|
39
|
+
let failed = []
|
|
40
|
+
if (measured !== undefined && required.length > 0) {
|
|
41
|
+
failed = required.filter((id) => typeof measured.results?.[id] !== 'number')
|
|
42
|
+
usable = failed.length === 0 ? 'ok' : 'blocked'
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
/** ms, null for "did not answer", undefined for "not measured yet". */
|
|
47
|
+
delay: delay === undefined ? undefined : delay,
|
|
48
|
+
usable,
|
|
49
|
+
failed,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Summarise a row set for the panel header.
|
|
56
|
+
*
|
|
57
|
+
* `usable` counts only nodes positively confirmed for every required service; `unknown` is
|
|
58
|
+
* reported apart from it so a fresh start does not read as "nothing works".
|
|
59
|
+
*
|
|
60
|
+
* @param rows - output of {@link buildNodeRows}.
|
|
61
|
+
* @returns counts by state and the total.
|
|
62
|
+
*/
|
|
63
|
+
export function summariseRows(rows) {
|
|
64
|
+
const list = Array.isArray(rows) ? rows : []
|
|
65
|
+
return {
|
|
66
|
+
total: list.length,
|
|
67
|
+
ok: list.filter((row) => row.usable === 'ok').length,
|
|
68
|
+
blocked: list.filter((row) => row.usable === 'blocked').length,
|
|
69
|
+
unknown: list.filter((row) => row.usable === 'unknown').length,
|
|
70
|
+
measured: list.filter((row) => typeof row.delay === 'number').length,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A short label for one row's usability, for the panel to translate.
|
|
76
|
+
*
|
|
77
|
+
* @param row - one output row.
|
|
78
|
+
* @returns `ok`, `blocked` or `unknown`.
|
|
79
|
+
*/
|
|
80
|
+
export function usabilityLabel(row) {
|
|
81
|
+
return row?.usable === 'ok' || row?.usable === 'blocked' ? row.usable : 'unknown'
|
|
82
|
+
}
|
package/lib/routes.js
CHANGED
|
@@ -111,6 +111,8 @@ const methodOf = (request) => String(request.method ?? 'GET').toUpperCase()
|
|
|
111
111
|
* @param log - logger for route failures.
|
|
112
112
|
* @returns disposers for every registered route.
|
|
113
113
|
*/
|
|
114
|
+
import { buildExcludeFilter, validateBlocklist } from './blocklist.js'
|
|
115
|
+
|
|
114
116
|
export function mountRoutes(webServer, runtime, log) {
|
|
115
117
|
const disposers = []
|
|
116
118
|
|
|
@@ -200,6 +202,42 @@ export function mountRoutes(webServer, runtime, log) {
|
|
|
200
202
|
sendJson(response, 200, { ok: true, ...report, binary: runtime.binary })
|
|
201
203
|
return
|
|
202
204
|
}
|
|
205
|
+
if (action === 'blockSelection') {
|
|
206
|
+
// The picker sends exact node names, so each becomes an anchored literal entry. Raw regex
|
|
207
|
+
// text stays in the blocklist field for whole-region removal; keeping them apart means a
|
|
208
|
+
// checkbox can never accidentally behave as a pattern.
|
|
209
|
+
const names = Array.isArray(body.names)
|
|
210
|
+
? body.names.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim())
|
|
211
|
+
: []
|
|
212
|
+
const keepRegex = String(body.keepRegex ?? '').trim()
|
|
213
|
+
const list = [keepRegex, names.join('\n')].filter((part) => part !== '').join('\n')
|
|
214
|
+
const problems = validateBlocklist(list)
|
|
215
|
+
if (problems.length > 0) {
|
|
216
|
+
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
const saved = await runtime.saveConfig({ blocklist: list })
|
|
220
|
+
sendJson(response, 200, {
|
|
221
|
+
ok: true,
|
|
222
|
+
blocked: names.length,
|
|
223
|
+
filter: buildExcludeFilter(list),
|
|
224
|
+
warnings: saved.warnings,
|
|
225
|
+
})
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
if (action === 'blocklist') {
|
|
229
|
+
const raw = String(body.list ?? '')
|
|
230
|
+
const problems = validateBlocklist(raw)
|
|
231
|
+
// An invalid regex makes the core reject the whole provider, which empties the node table —
|
|
232
|
+
// a far worse symptom than a rejected save. Catch it here instead.
|
|
233
|
+
if (problems.length > 0) {
|
|
234
|
+
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
const saved = await runtime.saveConfig({ blocklist: raw })
|
|
238
|
+
sendJson(response, 200, { ok: true, filter: buildExcludeFilter(raw), warnings: saved.warnings })
|
|
239
|
+
return
|
|
240
|
+
}
|
|
203
241
|
if (action === 'start') {
|
|
204
242
|
const report = await runtime.start()
|
|
205
243
|
sendJson(response, 200, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin, so blocked sites work while domestic traffic stays direct — no other software involved.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|