dsh-plugin-explorer 0.1.1 → 0.2.0
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 +48 -15
- package/client.js +397 -21
- package/index.js +64 -9
- package/lib/gate/LICENSE +21 -0
- package/lib/gate/osv.js +116 -0
- package/lib/gate/rules.js +628 -0
- package/lib/gate/scan.js +609 -0
- package/lib/gate/targz.js +146 -0
- package/lib/gate-scan.js +144 -0
- package/lib/installed.js +86 -0
- package/lib/npm.js +109 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -3
- package/scripts/verify.mjs +64 -6
package/client.js
CHANGED
|
@@ -9,8 +9,10 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
const NS = 'pluginFinder'
|
|
10
10
|
/** Results shown per page. */
|
|
11
11
|
const PAGE_SIZE = 30
|
|
12
|
-
/** Exact Fetch
|
|
12
|
+
/** Exact Fetch routes the Host half serves. */
|
|
13
13
|
const CATALOG_PATH = 'api/plugin-finder/catalog.json'
|
|
14
|
+
const SCAN_PATH = 'api/plugin-finder/scan.json'
|
|
15
|
+
const INSTALLED_PATH = 'api/plugin-finder/installed.json'
|
|
14
16
|
|
|
15
17
|
const zh = {
|
|
16
18
|
title: '搜索',
|
|
@@ -26,9 +28,41 @@ window.__ModuleLoader__.load({
|
|
|
26
28
|
empty: '没有匹配的插件',
|
|
27
29
|
install: '安装',
|
|
28
30
|
more: '加载更多',
|
|
29
|
-
note: '目录来自第三方社区索引(CC0),DSH
|
|
31
|
+
note: '目录来自第三方社区索引(CC0),DSH 只校验格式、不验证内容;安装前请核对确认框中的来源。安装前会先做静态安全检查。',
|
|
30
32
|
downloads: '{count} 次下载',
|
|
31
33
|
stars: '{count} 个 GitHub star',
|
|
34
|
+
all: '全部',
|
|
35
|
+
sort: '排序',
|
|
36
|
+
sortHot: '最热',
|
|
37
|
+
sortNew: '最新',
|
|
38
|
+
sortName: '名称',
|
|
39
|
+
installed: '已安装 v{version}',
|
|
40
|
+
update: '更新到 v{version}',
|
|
41
|
+
updateBadge: '有新版',
|
|
42
|
+
scanTitle: '安装前安全检查',
|
|
43
|
+
scanSubtitle: '{name}@{version}',
|
|
44
|
+
scanning: '正在下载并扫描 npm 包…',
|
|
45
|
+
scanFailed: '安全检查失败',
|
|
46
|
+
scanFailedHint: '可以跳过检查直接安装,但请先自行核对来源。',
|
|
47
|
+
skipScan: '跳过检查直接安装',
|
|
48
|
+
verdictPass: '通过',
|
|
49
|
+
verdictWarn: '警告',
|
|
50
|
+
verdictBlock: '高风险',
|
|
51
|
+
verdictLow: '低',
|
|
52
|
+
summaryLine: '高 {high} · 中 {medium} · 低 {low}',
|
|
53
|
+
filesScanned: '扫描 {count} 个文件',
|
|
54
|
+
networkHosts: '网络目标:{hosts}',
|
|
55
|
+
networkNone: '未发现网络目标',
|
|
56
|
+
hitsTitle: '命中规则({count})',
|
|
57
|
+
noHits: '未命中任何规则',
|
|
58
|
+
notesLine: '另有 {count} 条扫描提示',
|
|
59
|
+
confirmInstall: '确认安装',
|
|
60
|
+
installAnyway: '仍然安装',
|
|
61
|
+
riskInstall: '我已知风险,仍要安装',
|
|
62
|
+
cancel: '取消',
|
|
63
|
+
scanDisclaimer: '静态规则扫描(源自 dsh-plugin-gate,MIT)只读、不执行代码;结果是启发式判断,不是安全保证。',
|
|
64
|
+
scanCached: '缓存结果',
|
|
65
|
+
installedFailed: '读取已安装插件失败,仍可安装',
|
|
32
66
|
}
|
|
33
67
|
|
|
34
68
|
const en = {
|
|
@@ -45,9 +79,41 @@ window.__ModuleLoader__.load({
|
|
|
45
79
|
empty: 'No matching plugins',
|
|
46
80
|
install: 'Install',
|
|
47
81
|
more: 'Show more',
|
|
48
|
-
note: 'The catalog is a third-party community index (CC0). DSH checks its format, not its content; verify the source
|
|
82
|
+
note: 'The catalog is a third-party community index (CC0). DSH checks its format, not its content; verify the source before installing. A static safety scan runs first.',
|
|
49
83
|
downloads: '{count} downloads',
|
|
50
84
|
stars: '{count} GitHub stars',
|
|
85
|
+
all: 'All',
|
|
86
|
+
sort: 'Sort',
|
|
87
|
+
sortHot: 'Popular',
|
|
88
|
+
sortNew: 'Newest',
|
|
89
|
+
sortName: 'Name',
|
|
90
|
+
installed: 'Installed v{version}',
|
|
91
|
+
update: 'Update to v{version}',
|
|
92
|
+
updateBadge: 'Update',
|
|
93
|
+
scanTitle: 'Pre-install safety scan',
|
|
94
|
+
scanSubtitle: '{name}@{version}',
|
|
95
|
+
scanning: 'Downloading and scanning the npm package…',
|
|
96
|
+
scanFailed: 'Safety scan failed',
|
|
97
|
+
scanFailedHint: 'You can install without the scan, but verify the source yourself first.',
|
|
98
|
+
skipScan: 'Install without scan',
|
|
99
|
+
verdictPass: 'Pass',
|
|
100
|
+
verdictWarn: 'Warning',
|
|
101
|
+
verdictBlock: 'High risk',
|
|
102
|
+
verdictLow: 'Low',
|
|
103
|
+
summaryLine: 'high {high} · medium {medium} · low {low}',
|
|
104
|
+
filesScanned: 'Scanned {count} files',
|
|
105
|
+
networkHosts: 'Network targets: {hosts}',
|
|
106
|
+
networkNone: 'No network targets found',
|
|
107
|
+
hitsTitle: 'Rule hits ({count})',
|
|
108
|
+
noHits: 'No rules matched',
|
|
109
|
+
notesLine: '{count} additional scan notes',
|
|
110
|
+
confirmInstall: 'Install',
|
|
111
|
+
installAnyway: 'Install anyway',
|
|
112
|
+
riskInstall: 'I understand the risk, install',
|
|
113
|
+
cancel: 'Cancel',
|
|
114
|
+
scanDisclaimer: 'Static rule scan (from dsh-plugin-gate, MIT) only reads; it does not execute code. Heuristic results, not a guarantee.',
|
|
115
|
+
scanCached: 'cached result',
|
|
116
|
+
installedFailed: 'Could not read installed plugins; installing still works',
|
|
51
117
|
}
|
|
52
118
|
|
|
53
119
|
const CATEGORIES = {
|
|
@@ -77,7 +143,7 @@ window.__ModuleLoader__.load({
|
|
|
77
143
|
}
|
|
78
144
|
|
|
79
145
|
const CSS = `
|
|
80
|
-
.pf-root { display: flex; flex-direction: column; gap:
|
|
146
|
+
.pf-root { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
|
|
81
147
|
.pf-toolbar { display: flex; align-items: center; gap: 8px; }
|
|
82
148
|
.pf-search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
|
|
83
149
|
.pf-search-icon { position: absolute; left: 11px; color: var(--dsw-alias-label-secondary); pointer-events: none; }
|
|
@@ -102,6 +168,20 @@ window.__ModuleLoader__.load({
|
|
|
102
168
|
}
|
|
103
169
|
.pf-refresh:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
104
170
|
.pf-refresh:disabled { opacity: 0.6; cursor: default; }
|
|
171
|
+
.pf-filters { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
172
|
+
.pf-chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; padding-bottom: 2px; scrollbar-width: thin; }
|
|
173
|
+
.pf-chip {
|
|
174
|
+
flex: none; border: 1px solid var(--dsw-alias-border-l1); background: transparent;
|
|
175
|
+
color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 4px 10px;
|
|
176
|
+
font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
|
|
177
|
+
}
|
|
178
|
+
.pf-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
179
|
+
.pf-chip[data-active="true"] { background: var(--dsw-alias-brand-primary); border-color: transparent; color: #ffffff; }
|
|
180
|
+
.pf-sort {
|
|
181
|
+
flex: none; height: 30px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l1);
|
|
182
|
+
background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary);
|
|
183
|
+
font: inherit; font-size: 12px; padding: 0 6px; cursor: pointer;
|
|
184
|
+
}
|
|
105
185
|
.pf-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
106
186
|
.pf-warn { color: var(--dsw-alias-state-warn-primary); }
|
|
107
187
|
.pf-state {
|
|
@@ -130,13 +210,18 @@ window.__ModuleLoader__.load({
|
|
|
130
210
|
margin: 6px 0 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary);
|
|
131
211
|
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
|
|
132
212
|
}
|
|
133
|
-
.pf-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap:
|
|
213
|
+
.pf-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding-left: 4px; }
|
|
134
214
|
.pf-stat { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
|
|
135
215
|
.pf-install {
|
|
136
216
|
border: 0; border-radius: 8px; padding: 6px 14px; background: var(--dsw-alias-brand-primary);
|
|
137
217
|
color: #ffffff; font: inherit; font-size: 12px; cursor: pointer;
|
|
138
218
|
}
|
|
139
219
|
.pf-install:hover { filter: brightness(1.08); }
|
|
220
|
+
.pf-badge {
|
|
221
|
+
font-size: 11px; color: var(--dsw-alias-label-secondary);
|
|
222
|
+
border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 2px 7px; white-space: nowrap;
|
|
223
|
+
}
|
|
224
|
+
.pf-badge-new { color: var(--dsw-alias-state-warn-primary); border-color: currentColor; }
|
|
140
225
|
.pf-more {
|
|
141
226
|
align-self: center; margin-top: 2px; padding: 7px 16px; border-radius: 9px;
|
|
142
227
|
border: 1px solid var(--dsw-alias-border-l1); background: transparent;
|
|
@@ -144,6 +229,55 @@ window.__ModuleLoader__.load({
|
|
|
144
229
|
}
|
|
145
230
|
.pf-more:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
146
231
|
.pf-note { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); }
|
|
232
|
+
.pf-overlay {
|
|
233
|
+
position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
|
|
234
|
+
padding: 16px; background: rgba(0, 0, 0, 0.45);
|
|
235
|
+
}
|
|
236
|
+
.pf-dialog {
|
|
237
|
+
width: min(720px, 100%); max-height: min(80vh, 760px); overflow: auto;
|
|
238
|
+
background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1);
|
|
239
|
+
border-radius: 14px; padding: 20px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
|
|
240
|
+
display: flex; flex-direction: column; gap: 12px;
|
|
241
|
+
}
|
|
242
|
+
.pf-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
|
243
|
+
.pf-dialog-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--dsw-alias-label-primary); }
|
|
244
|
+
.pf-dialog-sub { margin-top: 4px; font-size: 12px; color: var(--dsw-alias-label-secondary); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
|
|
245
|
+
.pf-close {
|
|
246
|
+
flex: none; width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent;
|
|
247
|
+
color: var(--dsw-alias-label-secondary); font-size: 18px; line-height: 1; cursor: pointer;
|
|
248
|
+
}
|
|
249
|
+
.pf-close:hover { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); }
|
|
250
|
+
.pf-verdict { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
251
|
+
.pf-verdict-badge { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; border: 1px solid currentColor; }
|
|
252
|
+
.pf-verdict-pass { color: light-dark(#1a7f37, #3fb950); }
|
|
253
|
+
.pf-verdict-warn { color: var(--dsw-alias-state-warn-primary); }
|
|
254
|
+
.pf-verdict-block { color: light-dark(#cf222e, #f85149); }
|
|
255
|
+
.pf-scan-meta { font-size: 12px; color: var(--dsw-alias-label-secondary); display: flex; flex-wrap: wrap; gap: 4px 14px; }
|
|
256
|
+
.pf-hits { display: flex; flex-direction: column; gap: 6px; }
|
|
257
|
+
.pf-hits-title { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); margin-top: 4px; }
|
|
258
|
+
.pf-hit {
|
|
259
|
+
font-size: 11px; line-height: 16px; padding: 8px 10px; border-radius: 8px;
|
|
260
|
+
background: var(--dsw-alias-bg-layer-2); border-left: 3px solid var(--dsw-alias-border-l1);
|
|
261
|
+
}
|
|
262
|
+
.pf-hit[data-sev="high"] { border-left-color: light-dark(#cf222e, #f85149); }
|
|
263
|
+
.pf-hit[data-sev="medium"] { border-left-color: var(--dsw-alias-state-warn-primary); }
|
|
264
|
+
.pf-hit[data-sev="low"] { border-left-color: var(--dsw-alias-border-l2); }
|
|
265
|
+
.pf-hit-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
|
|
266
|
+
.pf-hit-rule { font-weight: 600; color: var(--dsw-alias-label-primary); }
|
|
267
|
+
.pf-hit-file { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; color: var(--dsw-alias-label-secondary); word-break: break-all; }
|
|
268
|
+
.pf-hit-evidence { margin-top: 4px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; color: var(--dsw-alias-label-secondary); word-break: break-all; }
|
|
269
|
+
.pf-hit-hint { margin-top: 4px; color: var(--dsw-alias-label-secondary); }
|
|
270
|
+
.pf-recs { margin: 0; padding-left: 18px; font-size: 11px; line-height: 17px; color: var(--dsw-alias-label-secondary); }
|
|
271
|
+
.pf-disclaimer { font-size: 10px; line-height: 15px; color: var(--dsw-alias-label-secondary); }
|
|
272
|
+
.pf-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
|
|
273
|
+
.pf-button {
|
|
274
|
+
border: 1px solid var(--dsw-alias-border-l1); background: transparent; color: var(--dsw-alias-label-primary);
|
|
275
|
+
border-radius: 8px; padding: 7px 14px; font: inherit; font-size: 12px; cursor: pointer;
|
|
276
|
+
}
|
|
277
|
+
.pf-button:hover { border-color: var(--dsw-alias-border-l2); }
|
|
278
|
+
.pf-button-primary { border: 0; background: var(--dsw-alias-brand-primary); color: #ffffff; }
|
|
279
|
+
.pf-button-primary:hover { filter: brightness(1.08); }
|
|
280
|
+
.pf-button-danger { border: 0; background: light-dark(#cf222e, #f85149); color: #ffffff; }
|
|
147
281
|
.pf-root :focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
148
282
|
@media (max-width: 640px) {
|
|
149
283
|
.pf-side { flex-direction: row; align-items: center; }
|
|
@@ -151,29 +285,55 @@ window.__ModuleLoader__.load({
|
|
|
151
285
|
}
|
|
152
286
|
`
|
|
153
287
|
|
|
154
|
-
function
|
|
155
|
-
|
|
288
|
+
function urlFor(path, params) {
|
|
289
|
+
const url = new URL(path, document.baseURI)
|
|
290
|
+
if (params !== undefined) {
|
|
291
|
+
for (const [key, value] of Object.entries(params)) url.searchParams.set(key, value)
|
|
292
|
+
}
|
|
293
|
+
return url
|
|
156
294
|
}
|
|
157
295
|
|
|
158
|
-
async function
|
|
159
|
-
const response = await fetch(
|
|
296
|
+
async function readJson(url) {
|
|
297
|
+
const response = await fetch(url, { credentials: 'same-origin', cache: 'no-store' })
|
|
160
298
|
if (!response.ok) {
|
|
161
299
|
let detail = ''
|
|
162
300
|
try {
|
|
163
301
|
const body = await response.json()
|
|
164
|
-
if (body && typeof body.error === 'string') detail = body.error
|
|
302
|
+
if (body !== null && typeof body === 'object' && typeof body.error === 'string') detail = body.error
|
|
165
303
|
} catch {
|
|
166
304
|
detail = ''
|
|
167
305
|
}
|
|
168
306
|
throw new Error(detail === '' ? `HTTP ${response.status}` : detail)
|
|
169
307
|
}
|
|
170
|
-
|
|
308
|
+
return response.json()
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async function readCatalog(refresh) {
|
|
312
|
+
const data = await readJson(urlFor(CATALOG_PATH, refresh ? { refresh: '1' } : undefined))
|
|
171
313
|
if (data === null || typeof data !== 'object' || !Array.isArray(data.plugins)) {
|
|
172
314
|
throw new Error('invalid catalog document')
|
|
173
315
|
}
|
|
174
316
|
return data
|
|
175
317
|
}
|
|
176
318
|
|
|
319
|
+
async function readInstalled() {
|
|
320
|
+
const data = await readJson(urlFor(INSTALLED_PATH))
|
|
321
|
+
if (data === null || typeof data !== 'object' || !Array.isArray(data.plugins)) {
|
|
322
|
+
throw new Error('invalid installed document')
|
|
323
|
+
}
|
|
324
|
+
return data
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function readScan(name, version) {
|
|
328
|
+
const params = { name }
|
|
329
|
+
if (typeof version === 'string' && version !== '') params.version = version
|
|
330
|
+
const data = await readJson(urlFor(SCAN_PATH, params))
|
|
331
|
+
if (data === null || typeof data !== 'object' || typeof data.verdict !== 'string') {
|
|
332
|
+
throw new Error('invalid scan document')
|
|
333
|
+
}
|
|
334
|
+
return data
|
|
335
|
+
}
|
|
336
|
+
|
|
177
337
|
/** Lowercased description for the active document language. */
|
|
178
338
|
function currentLanguage() {
|
|
179
339
|
const declared = document.documentElement && document.documentElement.lang
|
|
@@ -216,6 +376,7 @@ window.__ModuleLoader__.load({
|
|
|
216
376
|
haystack: [nameLower, ownerLower, categoryLower, description?.zh, description?.en].filter(Boolean).join('\n').toLowerCase(),
|
|
217
377
|
downloads: Number.isFinite(item.downloads) ? item.downloads : 0,
|
|
218
378
|
stars: Number.isFinite(item.stars) ? item.stars : 0,
|
|
379
|
+
added: typeof item.added === 'string' ? item.added : '',
|
|
219
380
|
})
|
|
220
381
|
}
|
|
221
382
|
return entries
|
|
@@ -268,6 +429,29 @@ window.__ModuleLoader__.load({
|
|
|
268
429
|
return matched.map(match => match.entry)
|
|
269
430
|
}
|
|
270
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Apply a category filter and a sort order to the prepared catalog.
|
|
434
|
+
* @param {Array<object>} entries - prepared entries.
|
|
435
|
+
* @param {{category?: string, sort?: string}} [options] - filter and order.
|
|
436
|
+
* @returns {Array<object>} filtered entries.
|
|
437
|
+
*/
|
|
438
|
+
function applyFilters(entries, options = {}) {
|
|
439
|
+
const { category, sort } = options
|
|
440
|
+
let out = entries
|
|
441
|
+
if (category !== undefined && category !== '' && category !== 'all') {
|
|
442
|
+
out = out.filter(entry => entry.category === category)
|
|
443
|
+
}
|
|
444
|
+
if (sort === 'name') return [...out].sort((left, right) => left.name.localeCompare(right.name))
|
|
445
|
+
if (sort === 'newest') {
|
|
446
|
+
return [...out].sort((left, right) => (
|
|
447
|
+
String(right.added).localeCompare(String(left.added))
|
|
448
|
+
|| right.downloads - left.downloads
|
|
449
|
+
|| left.name.localeCompare(right.name)
|
|
450
|
+
))
|
|
451
|
+
}
|
|
452
|
+
return [...out].sort((left, right) => right.downloads - left.downloads || left.name.localeCompare(right.name))
|
|
453
|
+
}
|
|
454
|
+
|
|
271
455
|
const compact = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 })
|
|
272
456
|
|
|
273
457
|
function SearchIcon() {
|
|
@@ -277,8 +461,21 @@ window.__ModuleLoader__.load({
|
|
|
277
461
|
}, h('circle', { cx: 7, cy: 7, r: 4.5 }), h('path', { d: 'M10.5 10.5 14 14', strokeLinecap: 'round' }))
|
|
278
462
|
}
|
|
279
463
|
|
|
464
|
+
function severityLabel(severity, t) {
|
|
465
|
+
if (severity === 'high') return t('verdictBlock')
|
|
466
|
+
if (severity === 'medium') return t('verdictWarn')
|
|
467
|
+
if (severity === 'low') return t('verdictLow')
|
|
468
|
+
return severity
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Find one entry in the installed-plugin document. */
|
|
472
|
+
function installedOf(installed, name) {
|
|
473
|
+
const list = installed !== null && typeof installed === 'object' && Array.isArray(installed.plugins) ? installed.plugins : []
|
|
474
|
+
return list.find(plugin => plugin !== null && typeof plugin === 'object' && plugin.name === name)
|
|
475
|
+
}
|
|
476
|
+
|
|
280
477
|
function FinderRow(props) {
|
|
281
|
-
const { entry, install, language, t } = props
|
|
478
|
+
const { entry, install, onScan, installed, language, t } = props
|
|
282
479
|
const [broken, setBroken] = useState(false)
|
|
283
480
|
const description = entry.description?.[language] ?? entry.description?.en ?? entry.description?.zh
|
|
284
481
|
const meta = [entry.owner, categoryLabel(entry.category, language)].filter(Boolean).join(' · ')
|
|
@@ -287,6 +484,14 @@ window.__ModuleLoader__.load({
|
|
|
287
484
|
: entry.stars > 0
|
|
288
485
|
? { text: `${compact.format(entry.stars)} ★`, title: t('stars', { count: entry.stars.toLocaleString() }) }
|
|
289
486
|
: undefined
|
|
487
|
+
const record = installedOf(installed, entry.name)
|
|
488
|
+
const current = record !== undefined && typeof record.version === 'string' ? record.version : undefined
|
|
489
|
+
const latest = record !== undefined && typeof record.latest === 'string' ? record.latest : undefined
|
|
490
|
+
const hasUpdate = record !== undefined && record.hasUpdate === true && latest !== undefined
|
|
491
|
+
const startScan = (version) => {
|
|
492
|
+
if (typeof onScan === 'function') onScan({ entry, version, mode: hasUpdate ? 'update' : 'install' })
|
|
493
|
+
else if (typeof install === 'function') install({ spec: entry.name + '@' + version, title: entry.name, version })
|
|
494
|
+
}
|
|
290
495
|
return h('div', { className: 'pf-row', 'data-plugin': entry.name },
|
|
291
496
|
h('div', { className: 'pf-avatar' },
|
|
292
497
|
entry.icon !== undefined && !broken
|
|
@@ -303,10 +508,95 @@ window.__ModuleLoader__.load({
|
|
|
303
508
|
description === undefined || description === '' ? null : h('p', { className: 'pf-desc', title: description }, description)),
|
|
304
509
|
h('div', { className: 'pf-side' },
|
|
305
510
|
metric === undefined ? null : h('span', { className: 'pf-stat', title: metric.title }, metric.text),
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
511
|
+
current === undefined
|
|
512
|
+
? null
|
|
513
|
+
: h('span', {
|
|
514
|
+
className: 'pf-badge' + (hasUpdate ? ' pf-badge-new' : ''),
|
|
515
|
+
title: hasUpdate ? t('installed', { version: current }) + ' → ' + latest : undefined,
|
|
516
|
+
}, hasUpdate ? t('installed', { version: current }) + ' → v' + latest : t('installed', { version: current })),
|
|
517
|
+
current === undefined
|
|
518
|
+
? h('button', {
|
|
519
|
+
type: 'button', className: 'pf-install',
|
|
520
|
+
onClick: () => { startScan(entry.version) },
|
|
521
|
+
}, t('install'))
|
|
522
|
+
: hasUpdate
|
|
523
|
+
? h('button', {
|
|
524
|
+
type: 'button', className: 'pf-install',
|
|
525
|
+
onClick: () => { startScan(latest) },
|
|
526
|
+
}, t('update', { version: latest }))
|
|
527
|
+
: null))
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function ScanDialog(props) {
|
|
531
|
+
const { scan, t, onCancel, onConfirm } = props
|
|
532
|
+
if (scan === null || scan === undefined) return null
|
|
533
|
+
const { entry, version, status, result, error } = scan
|
|
534
|
+
const verdict = result?.verdict
|
|
535
|
+
const verdictClass = verdict === 'PASS' ? 'pf-verdict-pass' : verdict === 'WARN' ? 'pf-verdict-warn' : 'pf-verdict-block'
|
|
536
|
+
const verdictText = verdict === 'PASS' ? t('verdictPass') : verdict === 'WARN' ? t('verdictWarn') : t('verdictBlock')
|
|
537
|
+
const confirmLabel = verdict === 'PASS' ? t('confirmInstall') : verdict === 'WARN' ? t('installAnyway') : t('riskInstall')
|
|
538
|
+
const summary = result?.summary ?? { high: 0, medium: 0, low: 0 }
|
|
539
|
+
const hosts = Array.isArray(result?.network?.hosts) ? result.network.hosts : []
|
|
540
|
+
const hits = Array.isArray(result?.hits) ? result.hits : []
|
|
541
|
+
const recommendations = Array.isArray(result?.recommendations) ? result.recommendations : []
|
|
542
|
+
return h('div', {
|
|
543
|
+
className: 'pf-overlay',
|
|
544
|
+
onMouseDown: event => { if (event.target === event.currentTarget) onCancel() },
|
|
545
|
+
},
|
|
546
|
+
h('div', {
|
|
547
|
+
className: 'pf-dialog', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('scanTitle'),
|
|
548
|
+
},
|
|
549
|
+
h('div', { className: 'pf-dialog-head' },
|
|
550
|
+
h('div', null,
|
|
551
|
+
h('h3', { className: 'pf-dialog-title' }, t('scanTitle')),
|
|
552
|
+
h('div', { className: 'pf-dialog-sub' }, entry.name + (version ? '@' + version : ''))),
|
|
553
|
+
h('button', { type: 'button', className: 'pf-close', 'aria-label': t('cancel'), onClick: onCancel }, '×')),
|
|
554
|
+
status === 'scanning'
|
|
555
|
+
? h('div', { className: 'pf-state', role: 'status' }, t('scanning'))
|
|
556
|
+
: status === 'failed'
|
|
557
|
+
? h('div', null,
|
|
558
|
+
h('div', { className: 'pf-verdict pf-verdict-block', style: { marginBottom: 6 } }, t('scanFailed')),
|
|
559
|
+
h('div', { className: 'pf-note', style: { marginBottom: 10 } }, t('scanFailedHint')),
|
|
560
|
+
h('div', { className: 'pf-note' }, error ?? ''))
|
|
561
|
+
: h('div', null,
|
|
562
|
+
h('div', { className: 'pf-verdict' },
|
|
563
|
+
h('span', { className: 'pf-verdict-badge ' + verdictClass }, verdictText),
|
|
564
|
+
h('span', { className: 'pf-scan-meta' },
|
|
565
|
+
h('span', null, t('summaryLine', summary)),
|
|
566
|
+
h('span', null, t('filesScanned', { count: result.filesScanned ?? 0 })),
|
|
567
|
+
result.cached === true ? h('span', null, t('scanCached')) : null)),
|
|
568
|
+
h('div', { className: 'pf-scan-meta', style: { marginTop: 8 } },
|
|
569
|
+
h('span', null, hosts.length === 0 ? t('networkNone') : t('networkHosts', { hosts: hosts.join(', ') }))),
|
|
570
|
+
hits.length === 0
|
|
571
|
+
? h('div', { className: 'pf-notes', style: { marginTop: 8 } }, t('noHits'))
|
|
572
|
+
: h('div', null,
|
|
573
|
+
h('div', { className: 'pf-hits-title' }, t('hitsTitle', { count: hits.length })),
|
|
574
|
+
h('div', { className: 'pf-hits' },
|
|
575
|
+
hits.slice(0, 40).map((hit, index) => h('div', {
|
|
576
|
+
key: index, className: 'pf-hit', 'data-sev': hit.severity,
|
|
577
|
+
},
|
|
578
|
+
h('div', { className: 'pf-hit-head' },
|
|
579
|
+
h('span', { className: 'pf-hit-rule' }, severityLabel(hit.severity, t) + ' · ' + hit.rule),
|
|
580
|
+
h('span', { className: 'pf-hit-file' }, hit.file + ':' + hit.line)),
|
|
581
|
+
h('div', { className: 'pf-hit-evidence' }, hit.evidence ?? ''),
|
|
582
|
+
hit.hint === undefined ? null : h('div', { className: 'pf-hit-hint' }, hit.hint))))),
|
|
583
|
+
(result.notes ?? 0) > 0 ? h('div', { className: 'pf-note', style: { marginTop: 6 } }, t('notesLine', { count: result.notes })) : null,
|
|
584
|
+
recommendations.length === 0 ? null : h('ul', { className: 'pf-recs', style: { marginTop: 8 } },
|
|
585
|
+
recommendations.slice(0, 4).map((text, index) => h('li', { key: index }, text))),
|
|
586
|
+
h('div', { className: 'pf-disclaimer', style: { marginTop: 10 } }, t('scanDisclaimer'))),
|
|
587
|
+
h('div', { className: 'pf-dialog-actions' },
|
|
588
|
+
h('button', { type: 'button', className: 'pf-button', onClick: onCancel }, t('cancel')),
|
|
589
|
+
status === 'scanning'
|
|
590
|
+
? null
|
|
591
|
+
: status === 'failed'
|
|
592
|
+
? h('button', {
|
|
593
|
+
type: 'button', className: 'pf-button pf-button-danger',
|
|
594
|
+
onClick: () => onConfirm({ skipScan: true }),
|
|
595
|
+
}, t('skipScan'))
|
|
596
|
+
: h('button', {
|
|
597
|
+
type: 'button', className: 'pf-button ' + (verdict === 'BLOCK' ? 'pf-button-danger' : 'pf-button-primary'),
|
|
598
|
+
onClick: () => onConfirm({ skipScan: false }),
|
|
599
|
+
}, confirmLabel))))
|
|
310
600
|
}
|
|
311
601
|
|
|
312
602
|
function FinderTab(props) {
|
|
@@ -319,6 +609,11 @@ window.__ModuleLoader__.load({
|
|
|
319
609
|
const [text, setText] = useState('')
|
|
320
610
|
const [query, setQuery] = useState('')
|
|
321
611
|
const [limit, setLimit] = useState(PAGE_SIZE)
|
|
612
|
+
const [category, setCategory] = useState('all')
|
|
613
|
+
const [sort, setSort] = useState('hot')
|
|
614
|
+
const [installed, setInstalled] = useState(null)
|
|
615
|
+
const [installedError, setInstalledError] = useState(false)
|
|
616
|
+
const [scan, setScan] = useState(null)
|
|
322
617
|
|
|
323
618
|
async function load(refresh) {
|
|
324
619
|
if (refresh) {
|
|
@@ -339,7 +634,43 @@ window.__ModuleLoader__.load({
|
|
|
339
634
|
}
|
|
340
635
|
}
|
|
341
636
|
|
|
637
|
+
async function loadInstalled() {
|
|
638
|
+
try {
|
|
639
|
+
const data = await readInstalled()
|
|
640
|
+
setInstalled(data)
|
|
641
|
+
setInstalledError(false)
|
|
642
|
+
} catch {
|
|
643
|
+
setInstalledError(true)
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function scanEntry({ entry, version }) {
|
|
648
|
+
setScan({ entry, version, status: 'scanning', result: null, error: null })
|
|
649
|
+
void readScan(entry.name, version)
|
|
650
|
+
.then(result => {
|
|
651
|
+
setScan(current => current === null || current.entry.name !== entry.name
|
|
652
|
+
? current
|
|
653
|
+
: { entry, version, status: 'ready', result, error: null })
|
|
654
|
+
})
|
|
655
|
+
.catch(error => {
|
|
656
|
+
setScan(current => current === null || current.entry.name !== entry.name
|
|
657
|
+
? current
|
|
658
|
+
: { ...current, status: 'failed', error: error instanceof Error ? error.message : String(error) })
|
|
659
|
+
})
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function confirmScan() {
|
|
663
|
+
if (scan === null) return
|
|
664
|
+
const { entry, version } = scan
|
|
665
|
+
setScan(null)
|
|
666
|
+
if (typeof install === 'function') {
|
|
667
|
+
install({ spec: entry.name + '@' + version, title: entry.name, version })
|
|
668
|
+
setTimeout(() => { void loadInstalled() }, 3000)
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
342
672
|
useEffect(() => { void load(false) }, [])
|
|
673
|
+
useEffect(() => { void loadInstalled() }, [])
|
|
343
674
|
useEffect(() => {
|
|
344
675
|
const timer = setTimeout(() => { setQuery(text) }, 150)
|
|
345
676
|
return () => { clearTimeout(timer) }
|
|
@@ -347,8 +678,29 @@ window.__ModuleLoader__.load({
|
|
|
347
678
|
|
|
348
679
|
const entries = useMemo(() => prepare(catalog?.plugins ?? []), [catalog])
|
|
349
680
|
const tokens = useMemo(() => tokenize(query), [query])
|
|
350
|
-
const
|
|
351
|
-
|
|
681
|
+
const categories = useMemo(() => {
|
|
682
|
+
const counts = new Map()
|
|
683
|
+
for (const entry of entries) {
|
|
684
|
+
if (entry.category === undefined) continue
|
|
685
|
+
counts.set(entry.category, (counts.get(entry.category) ?? 0) + 1)
|
|
686
|
+
}
|
|
687
|
+
const ranked = [...counts.entries()].sort((left, right) => right[1] - left[1])
|
|
688
|
+
.slice(0, 14)
|
|
689
|
+
.map(([id, count]) => ({ id, count }))
|
|
690
|
+
if (category !== 'all' && !ranked.some(item => item.id === category)) {
|
|
691
|
+
ranked.push({ id: category, count: counts.get(category) ?? 0 })
|
|
692
|
+
}
|
|
693
|
+
return ranked
|
|
694
|
+
}, [entries, category])
|
|
695
|
+
const sortKey = sort === 'hot' ? 'downloads' : sort === 'new' ? 'newest' : 'name'
|
|
696
|
+
const results = useMemo(() => {
|
|
697
|
+
const base = tokens.length === 0
|
|
698
|
+
? applyFilters(entries, { category, sort: sortKey })
|
|
699
|
+
: searchEntries(entries, tokens)
|
|
700
|
+
if (category === 'all' || tokens.length === 0) return base
|
|
701
|
+
return base.filter(entry => entry.category === category)
|
|
702
|
+
}, [entries, tokens, category, sortKey])
|
|
703
|
+
useEffect(() => { setLimit(PAGE_SIZE) }, [query, entries, category, sort])
|
|
352
704
|
|
|
353
705
|
const shown = results.slice(0, limit)
|
|
354
706
|
const language = currentLanguage()
|
|
@@ -371,8 +723,27 @@ window.__ModuleLoader__.load({
|
|
|
371
723
|
type: 'button', className: 'pf-refresh', disabled: refreshing || status === 'loading',
|
|
372
724
|
onClick: () => { void load(true) },
|
|
373
725
|
}, refreshing ? t('refreshing') : t('refresh'))),
|
|
726
|
+
h('div', { className: 'pf-filters' },
|
|
727
|
+
h('div', { className: 'pf-chips', role: 'tablist', 'aria-label': t('sort') },
|
|
728
|
+
h('button', {
|
|
729
|
+
type: 'button', className: 'pf-chip', 'data-active': category === 'all' ? 'true' : 'false',
|
|
730
|
+
onClick: () => { setCategory('all') },
|
|
731
|
+
}, t('all')),
|
|
732
|
+
categories.map(item => h('button', {
|
|
733
|
+
key: item.id, type: 'button', className: 'pf-chip',
|
|
734
|
+
'data-active': category === item.id ? 'true' : 'false',
|
|
735
|
+
onClick: () => { setCategory(category === item.id ? 'all' : item.id) },
|
|
736
|
+
}, categoryLabel(item.id, language) + ' ' + item.count))),
|
|
737
|
+
h('select', {
|
|
738
|
+
className: 'pf-sort', value: sort, 'aria-label': t('sort'),
|
|
739
|
+
onChange: event => { setSort(event.target.value) },
|
|
740
|
+
},
|
|
741
|
+
h('option', { value: 'hot' }, t('sortHot')),
|
|
742
|
+
h('option', { value: 'new' }, t('sortNew')),
|
|
743
|
+
h('option', { value: 'name' }, t('sortName')))),
|
|
374
744
|
h('div', { className: 'pf-summary' },
|
|
375
745
|
h('span', null, status === 'ready' ? t('count', { count: results.length }) : ''),
|
|
746
|
+
installedError ? h('span', { className: 'pf-warn' }, t('installedFailed')) : null,
|
|
376
747
|
refreshError ? h('span', { className: 'pf-warn' }, t('refreshFailed')) : null),
|
|
377
748
|
status === 'loading'
|
|
378
749
|
? h('div', { className: 'pf-state', role: 'status' }, t('loading'))
|
|
@@ -384,18 +755,23 @@ window.__ModuleLoader__.load({
|
|
|
384
755
|
? h('div', { className: 'pf-state' }, t('empty'))
|
|
385
756
|
: h('div', { className: 'pf-list' },
|
|
386
757
|
shown.map(entry => h(FinderRow, {
|
|
387
|
-
key: entry.name, entry, install, language, t,
|
|
758
|
+
key: entry.name, entry, install, onScan: scanEntry, installed, language, t,
|
|
388
759
|
}))),
|
|
389
760
|
results.length > shown.length
|
|
390
761
|
? h('button', { type: 'button', className: 'pf-more', onClick: () => { setLimit(limit + PAGE_SIZE) } },
|
|
391
762
|
`${t('more')} (${results.length - shown.length})`)
|
|
392
763
|
: null,
|
|
393
|
-
h('div', { className: 'pf-note' }, t('note'))
|
|
764
|
+
h('div', { className: 'pf-note' }, t('note')),
|
|
765
|
+
h(ScanDialog, {
|
|
766
|
+
scan, t,
|
|
767
|
+
onCancel: () => { setScan(null) },
|
|
768
|
+
onConfirm: confirmScan,
|
|
769
|
+
}))
|
|
394
770
|
}
|
|
395
771
|
|
|
396
772
|
return {
|
|
397
773
|
/** Internal exports used by the package's Node-side checks. */
|
|
398
|
-
__test: { prepare, tokenize, searchEntries, FinderTab, FinderRow },
|
|
774
|
+
__test: { prepare, tokenize, searchEntries, applyFilters, FinderTab, FinderRow, ScanDialog },
|
|
399
775
|
inject: ['slots', 'locale'],
|
|
400
776
|
apply(ctx) {
|
|
401
777
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'plugin-finder: dictionaries')
|