dsh-dpharness 0.3.5 → 0.4.1
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 +28 -2
- package/lib/client.js +182 -15
- package/lib/index.js +80 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
在 DeepSeek Harness(dsh)里浏览、搜索 [dpharness.com](https://dpharness.com) 的 dsh 插件目录,
|
|
4
4
|
**并可直接一键安装**。
|
|
5
5
|
|
|
6
|
+
## 两个视图
|
|
7
|
+
|
|
8
|
+
面板(浮窗与页签共用同一套组件)顶部可在两个视图间切换:
|
|
9
|
+
|
|
10
|
+
| 视图 | 数据来源 | 回答的问题 |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| **严选推荐** | `GET /api/plugins`(全量目录) | 「我知道要什么,帮我找」——可搜索、可按 Star 排序 |
|
|
13
|
+
| **分类精选** | `GET /api/best`(月度策展,与站点 [/best](https://dpharness.com/best) 同一份数据) | 「我该装哪几个」——按大类 → 小类分组,每小类只留 2~3 个 |
|
|
14
|
+
|
|
15
|
+
分类精选视图刻意保留两项元数据:**小类内名次**与**上榜理由**(如「小类第 1 · 实装验证通过 · 周下载 12.8 万」)。
|
|
16
|
+
去掉它们,这份清单就只是又一个列表;它们的价值恰恰在于「为什么是它」可复核。
|
|
17
|
+
入榜门槛(站点侧规则):通过静态安装检查或 CI 实装验证 + 汉化完成;每月 1 日重算并公开淘汰原因。
|
|
18
|
+
|
|
6
19
|
## 三个入口
|
|
7
20
|
|
|
8
21
|
| 入口 | 位置 | 说明 |
|
|
@@ -52,6 +65,7 @@
|
|
|
52
65
|
| 路由 | 说明 |
|
|
53
66
|
|---|---|
|
|
54
67
|
| `GET /api/dpharness/search?q=&take=&sort=stars` | 目录查询,字段裁剪后返回,按 `q+take+sort` 缓存 5 分钟 |
|
|
68
|
+
| `GET /api/dpharness/best` | 分类精选榜单(站点 `/api/best` 的代理 + 字段裁剪),缓存 5 分钟 |
|
|
55
69
|
| `POST /api/dpharness/event` | 埋点代理 → `dpharness.com/api/track/event` |
|
|
56
70
|
| `POST /api/dpharness/install` | `{ pkg }`,spawn `dsh plugin add`;返回 202 + 任务启动 |
|
|
57
71
|
| `GET /api/dpharness/install` | 安装任务进度与结果 |
|
|
@@ -67,17 +81,29 @@
|
|
|
67
81
|
|
|
68
82
|
## 安装本插件
|
|
69
83
|
|
|
84
|
+
**官方命令(推荐)**:
|
|
85
|
+
|
|
70
86
|
```bash
|
|
71
|
-
dsh plugin --profile web add dsh-dpharness
|
|
87
|
+
dsh plugin --profile web add dsh-dpharness
|
|
72
88
|
```
|
|
73
89
|
|
|
74
90
|
> `--profile web` 是 dsh CLI 的**必需参数**,省略会直接报
|
|
75
91
|
> `required option '--profile <name>' not specified`。
|
|
76
92
|
> 任何来源给出的 `dsh plugin add <owner/repo>` 都不可用。
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
也可从 GitHub 源安装(等价,未依赖 npm 缓存时用):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
dsh plugin --profile web add zhanghao3693/dsh-dpharness
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
开发用(改完立刻看效果,从本地目录装):`bash install.sh`,然后重启 dsh
|
|
79
101
|
(侧边栏「重启」按钮,或 `pkill -9 -f "bin/dsh web"` 让 launchd 拉起)。
|
|
80
102
|
|
|
103
|
+
> ⚠️ **`install.sh` 与官方命令不能混用**:官方安装会把它并入 profile 的 bundle 层,
|
|
104
|
+
> 而 `install.sh` 是往 profile 的 `cordis.patch.yml` 里插一段 `insert` ——
|
|
105
|
+
> 同一个 `id` 被插入两次会让 **dsh 启动硬失败**。切换前先清掉另一边。
|
|
106
|
+
|
|
81
107
|
## 卸载
|
|
82
108
|
|
|
83
109
|
从 `~/.dsh/profiles/web/cordis.patch.yml` 删掉含 `id: dpharness` 的 `insert` 块,然后:
|
package/lib/client.js
CHANGED
|
@@ -35,6 +35,33 @@ window.__ModuleLoader__.load({
|
|
|
35
35
|
".dph_desc{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary);margin:0}",
|
|
36
36
|
".dph_cmdRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
37
37
|
".dph_cmdWrap{display:flex;flex-direction:column;gap:4px}",
|
|
38
|
+
/* 视图切换(严选推荐 / 分类精选):复用既有 `.dph_seg`,
|
|
39
|
+
只加一层包裹让它铺满面板宽度。
|
|
40
|
+
⚠️ 不要重定义 .dph_seg / .dph_segBtn —— 排序与数量控件也在用它们,
|
|
41
|
+
重复定义会**覆盖既有样式**(2026-09-18 自己踩过:加了同名定义且排在后面,
|
|
42
|
+
把既有的两个控件改了观感)。用包裹层提高特异性即可。 */
|
|
43
|
+
".dph_segWrap{display:flex}",
|
|
44
|
+
".dph_segWrap .dph_seg{flex:1}",
|
|
45
|
+
".dph_segWrap .dph_segBtn{flex:1}",
|
|
46
|
+
/* 分类精选:大类(可折叠)→ 小类 → 条目
|
|
47
|
+
⚠️ `flex:none` 不可省(2026-09-18 实测踩到,用户截图暴露):
|
|
48
|
+
`.dph_panelBody` 是 `display:flex; flex-direction:column`,而本元素有
|
|
49
|
+
`overflow:hidden`(为了圆角)。规范规定 flex 子项的**自动最小高度只在
|
|
50
|
+
overflow:visible 时生效** —— 有了 overflow:hidden,最小高度变 0,
|
|
51
|
+
于是 9 个大类被**压扁成细线**、展开的那个也把卡片压没了(文字被裁掉)。
|
|
52
|
+
显式 `flex:none` 让它保持内容高度、由面板主体滚动。
|
|
53
|
+
(「严选推荐」视图没这个问题,因为 .dph_card 没有 overflow:hidden。) */
|
|
54
|
+
".dph_bestCat{flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}",
|
|
55
|
+
".dph_bestCatHead{display:flex;align-items:baseline;justify-content:space-between;gap:8px;padding:8px 12px;cursor:pointer;list-style:none;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}",
|
|
56
|
+
".dph_bestCatHead::-webkit-details-marker{display:none}",
|
|
57
|
+
".dph_bestCatCount{font-size:10px;font-weight:400;color:var(--dsw-alias-label-tertiary)}",
|
|
58
|
+
".dph_bestSub{padding:0 10px 10px}",
|
|
59
|
+
".dph_bestSubHead{display:flex;align-items:baseline;gap:6px;padding:6px 2px 6px;flex-wrap:wrap}",
|
|
60
|
+
".dph_bestSubName{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
|
|
61
|
+
".dph_bestSubSum{font-size:10px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}",
|
|
62
|
+
".dph_bestItem{display:flex;flex-direction:column;gap:4px}",
|
|
63
|
+
".dph_bestRank{font-size:10px;font-weight:700;color:var(--dsw-alias-state-business-primary)}",
|
|
64
|
+
".dph_bestReason{font-size:10px;color:var(--dsw-alias-label-tertiary);padding-left:2px}",
|
|
38
65
|
".dph_cmd{flex:1;min-width:200px;box-sizing:border-box;background:var(--dsw-alias-bg-layer-3);border-radius:6px;padding:6px 10px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-primary);overflow-x:auto;white-space:nowrap}",
|
|
39
66
|
".dph_cmdMissing{font-size:12px;color:var(--dsw-alias-label-tertiary)}",
|
|
40
67
|
".dph_notice{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:14px;font-size:13px;color:var(--dsw-alias-label-secondary)}",
|
|
@@ -111,6 +138,12 @@ window.__ModuleLoader__.load({
|
|
|
111
138
|
"label.untranslated": "未汉化",
|
|
112
139
|
"label.repoSource": "GitHub 源",
|
|
113
140
|
"hint.repoSource": "该插件未发布到 npm,走 GitHub 源安装(与站点详情页同口径)。",
|
|
141
|
+
"best.recommend": "严选推荐",
|
|
142
|
+
"best.picks": "分类精选",
|
|
143
|
+
"best.catCount": "{subs} 个小类 · {n} 个",
|
|
144
|
+
"best.month": "{m} 期 · 每小类 2~3 个",
|
|
145
|
+
"best.loading": "正在取当期榜单…",
|
|
146
|
+
"best.empty": "当期榜单还没有数据(每月 1 日重算)",
|
|
114
147
|
"footer.hint": "网页无法自动安装:复制命令到终端执行,装完重启 dsh 才会生效。命令里的 --profile web 不可省略。",
|
|
115
148
|
"telemetry.on": "匿名统计(不含搜索内容)",
|
|
116
149
|
"install.action": "安装",
|
|
@@ -150,6 +183,12 @@ window.__ModuleLoader__.load({
|
|
|
150
183
|
"label.untranslated": "Not translated",
|
|
151
184
|
"label.repoSource": "GitHub source",
|
|
152
185
|
"hint.repoSource": "Not published to npm — installs from the GitHub source (same rule as the site's detail page).",
|
|
186
|
+
"best.recommend": "Curated",
|
|
187
|
+
"best.picks": "By category",
|
|
188
|
+
"best.catCount": "{subs} groups · {n}",
|
|
189
|
+
"best.month": "{m} · 2-3 per group",
|
|
190
|
+
"best.loading": "Loading this month's picks…",
|
|
191
|
+
"best.empty": "No picks for the current month yet (recomputed on the 1st)",
|
|
153
192
|
"footer.hint": "A web page cannot install plugins: copy the command into a terminal, then restart dsh. The --profile web flag is mandatory.",
|
|
154
193
|
"telemetry.on": "Anonymous stats (no search text)",
|
|
155
194
|
"install.action": "Install",
|
|
@@ -346,15 +385,20 @@ window.__ModuleLoader__.load({
|
|
|
346
385
|
const EDGE = 8;
|
|
347
386
|
const DRAG_THRESHOLD = 5;
|
|
348
387
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
388
|
+
* 默认位置刻意**不贴右下角**,且要避开其它插件已占的那几个位置。
|
|
389
|
+
*
|
|
390
|
+
* 实测(1280×860 与 1280×900 两次量测,2026-09-17/18)右下角竖着排了三个
|
|
391
|
+
* **z-index 同为 2147483000** 的浮动按钮,DOM 靠后的会压住前面的:
|
|
392
|
+
* · `#dsh-check-updates-btn`(「检查更新」) bottom 16..48
|
|
393
|
+
* · `#mem-open`(dsh-mnemon 的「🧠 Memory」)bottom 56..96
|
|
394
|
+
* 故取 bottom:108(在两者之上)—— 108 这个数是量出来的,不是拍的:
|
|
395
|
+
* 曾经用 60,正好落在 mnemon 按钮的 56..96 里,导致胶囊被完全覆盖、
|
|
396
|
+
* **点不动**(playwright 报 `#mem-open … intercepts pointer events`)。
|
|
397
|
+
*
|
|
398
|
+
* 不用提高 z-index 去抢:那会让被压住的那个按钮反过来点不动(同样是别人的功能)。
|
|
399
|
+
* 位置冲突可以用位置解决;用户仍可拖动,位置会记住。
|
|
356
400
|
*/
|
|
357
|
-
const DEFAULT_POS = { right: 16, bottom:
|
|
401
|
+
const DEFAULT_POS = { right: 16, bottom: 108 };
|
|
358
402
|
|
|
359
403
|
function viewportSize() {
|
|
360
404
|
return {
|
|
@@ -524,6 +568,52 @@ window.__ModuleLoader__.load({
|
|
|
524
568
|
};
|
|
525
569
|
}
|
|
526
570
|
|
|
571
|
+
/**
|
|
572
|
+
* 「分类精选」榜单取数(站点 /best 的同源数据)。
|
|
573
|
+
*
|
|
574
|
+
* 按需拉取:只有用户切到该视图才请求,不拖慢默认打开速度。
|
|
575
|
+
* 拿到一次就不再重复请求(榜单每月 1 日才重算),手动刷新才重取。
|
|
576
|
+
*/
|
|
577
|
+
function useBest(t, enabled) {
|
|
578
|
+
const [reload, setReload] = react.useState(0);
|
|
579
|
+
const [state, setState] = react.useState({ loading: false, data: null, error: null });
|
|
580
|
+
const [copiedCmd, setCopiedCmd] = react.useState("");
|
|
581
|
+
const loaded = react.useRef(false);
|
|
582
|
+
|
|
583
|
+
react.useEffect(() => {
|
|
584
|
+
if (!enabled) return undefined;
|
|
585
|
+
if (loaded.current && reload === 0) return undefined;
|
|
586
|
+
loaded.current = true;
|
|
587
|
+
const controller = new AbortController();
|
|
588
|
+
const timer = setTimeout(() => controller.abort(), 20000);
|
|
589
|
+
setState((previous) => ({ loading: true, data: previous.data, error: null }));
|
|
590
|
+
fetch("/api/dpharness/best", { cache: "no-store", signal: controller.signal })
|
|
591
|
+
.then((response) => response.json().then((body) => ({ status: response.status, body })))
|
|
592
|
+
.then((result) => {
|
|
593
|
+
if (controller.signal.aborted) return;
|
|
594
|
+
if (result.status !== 200 || !result.body || result.body.ok !== true) {
|
|
595
|
+
throw new Error((result.body && result.body.error) || ("HTTP " + result.status));
|
|
596
|
+
}
|
|
597
|
+
setState({ loading: false, data: result.body, error: null });
|
|
598
|
+
track("plugin_hub", { action: "best_open", cats: (result.body.categories || []).length, total: result.body.total || 0 });
|
|
599
|
+
})
|
|
600
|
+
.catch((error) => {
|
|
601
|
+
if (controller.signal.aborted) return;
|
|
602
|
+
const message = error && error.name === "AbortError" ? "timeout" : String((error && error.message) || error);
|
|
603
|
+
setState((previous) => ({ loading: false, data: previous.data, error: message }));
|
|
604
|
+
})
|
|
605
|
+
.finally(() => clearTimeout(timer));
|
|
606
|
+
return () => clearTimeout(timer);
|
|
607
|
+
}, [enabled, reload]);
|
|
608
|
+
|
|
609
|
+
const markCopied = react.useCallback((text) => {
|
|
610
|
+
setCopiedCmd(text);
|
|
611
|
+
setTimeout(() => setCopiedCmd((current) => (current === text ? "" : current)), 2000);
|
|
612
|
+
}, []);
|
|
613
|
+
|
|
614
|
+
return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
|
|
615
|
+
}
|
|
616
|
+
|
|
527
617
|
/* ------------------------------------------------------------ components */
|
|
528
618
|
function makeUi(t) {
|
|
529
619
|
function badge(label, kind) {
|
|
@@ -622,6 +712,58 @@ window.__ModuleLoader__.load({
|
|
|
622
712
|
]);
|
|
623
713
|
}
|
|
624
714
|
|
|
715
|
+
/**
|
|
716
|
+
* 「分类精选」视图:大类(可折叠)→ 小类 → 条目。
|
|
717
|
+
*
|
|
718
|
+
* 与「严选推荐」的区别:那边是**可搜索的全量目录**(按你的关键词找),
|
|
719
|
+
* 这边是**月度策展结果**(每小类只留 2~3 个),回答的是"按用途该装哪几个"。
|
|
720
|
+
* 所以渲染上刻意保留两项元数据:
|
|
721
|
+
* · rank —— 小类内名次,用户要知道"这是这个小类里最好的第几个";
|
|
722
|
+
* · reason —— 上榜理由(如"实装验证通过 · 周下载 12.8 万"),
|
|
723
|
+
* 这是"为什么是它"的依据,去掉就只是又一个列表。
|
|
724
|
+
*/
|
|
725
|
+
function renderBest(data, copiedCmd, onCopied) {
|
|
726
|
+
if (!data) return null;
|
|
727
|
+
const cats = Array.isArray(data.categories) ? data.categories : [];
|
|
728
|
+
return cats.map((cat, index) =>
|
|
729
|
+
h("details", { className: "dph_bestCat", key: cat.key || String(index), open: index === 0 }, [
|
|
730
|
+
h("summary", { className: "dph_bestCatHead", key: "head" }, [
|
|
731
|
+
h("span", { key: "name" }, cat.label),
|
|
732
|
+
h(
|
|
733
|
+
"span",
|
|
734
|
+
{ className: "dph_bestCatCount", key: "count" },
|
|
735
|
+
format(t("best.catCount"), { subs: (cat.subs || []).length, n: cat.count || 0 }),
|
|
736
|
+
),
|
|
737
|
+
]),
|
|
738
|
+
...(cat.subs || []).map((sub) =>
|
|
739
|
+
h("div", { className: "dph_bestSub", key: sub.key }, [
|
|
740
|
+
h("div", { className: "dph_bestSubHead", key: "subHead" }, [
|
|
741
|
+
h("span", { className: "dph_bestSubName", key: "n" }, sub.label),
|
|
742
|
+
sub.summary
|
|
743
|
+
? h("span", { className: "dph_bestSubSum", key: "s", title: sub.summary }, sub.summary)
|
|
744
|
+
: null,
|
|
745
|
+
]),
|
|
746
|
+
h(
|
|
747
|
+
"div",
|
|
748
|
+
{ className: "dph_list", key: "list" },
|
|
749
|
+
(sub.items || []).map((item) =>
|
|
750
|
+
h("div", { key: item.fullName, className: "dph_bestItem" }, [
|
|
751
|
+
item.rank
|
|
752
|
+
? h("div", { className: "dph_bestRank", key: "rank" }, "#" + item.rank)
|
|
753
|
+
: null,
|
|
754
|
+
renderCard(item, copiedCmd, onCopied, true),
|
|
755
|
+
item.reason
|
|
756
|
+
? h("div", { className: "dph_bestReason", key: "why" }, item.reason)
|
|
757
|
+
: null,
|
|
758
|
+
]),
|
|
759
|
+
),
|
|
760
|
+
),
|
|
761
|
+
]),
|
|
762
|
+
),
|
|
763
|
+
]),
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
625
767
|
function renderCard(item, copiedCmd, onCopied, compact) {
|
|
626
768
|
const title = item.nameZh || item.name || item.fullName || "";
|
|
627
769
|
const tags = tagsOf(item);
|
|
@@ -786,6 +928,16 @@ window.__ModuleLoader__.load({
|
|
|
786
928
|
const skipClickRef = react.useRef(false);
|
|
787
929
|
const panelRef = react.useRef(null);
|
|
788
930
|
const onDrag = makeDragHandlers(() => posRef.current, setPos, skipClickRef);
|
|
931
|
+
/**
|
|
932
|
+
* 面板内的两个视图:
|
|
933
|
+
* search = 严选推荐(可搜索的全量目录)
|
|
934
|
+
* best = 分类精选(站点 /best 的月度策展结果)
|
|
935
|
+
* 放在同一入口里而不是再开一个入口:用户的意图都是"找该装哪个",
|
|
936
|
+
* 分成两个入口只会让人不知道该点哪个。
|
|
937
|
+
*/
|
|
938
|
+
const [mode, setMode] = react.useState("search");
|
|
939
|
+
const best = useBest(t, state.open && mode === "best");
|
|
940
|
+
const bestData = best.state.data;
|
|
789
941
|
|
|
790
942
|
/**
|
|
791
943
|
* 展开时按**面板实际尺寸**重新夹取位置。
|
|
@@ -864,16 +1016,31 @@ window.__ModuleLoader__.load({
|
|
|
864
1016
|
title: t("action.drag"),
|
|
865
1017
|
onPointerDown: onDrag,
|
|
866
1018
|
}, t("view.title")),
|
|
867
|
-
h("span", { className: "dph_sub", key: "sub" },
|
|
1019
|
+
h("span", { className: "dph_sub", key: "sub" }, mode === "best"
|
|
1020
|
+
? (bestData ? format(t("best.month"), { m: bestData.month || "" }) : "")
|
|
1021
|
+
: (data ? format(t("count.summary"), { n: data.count }) : "")),
|
|
868
1022
|
h("span", { className: "dph_spacer", key: "gap" }),
|
|
869
|
-
h("a", { className: "dph_btn", key: "site", href: SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: "overlay" }) }, t("action.openSite")),
|
|
1023
|
+
h("a", { className: "dph_btn", key: "site", href: mode === "best" ? SITE + "/best" : SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: mode === "best" ? "best" : "overlay" }) }, t("action.openSite")),
|
|
870
1024
|
h("button", { className: "dph_close", key: "close", type: "button", title: t("action.close"), "aria-label": t("action.close"), onClick: () => setHub({ open: false }) }, "×"),
|
|
871
1025
|
]),
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1026
|
+
h("div", { className: "dph_segWrap", key: "seg" }, seg([
|
|
1027
|
+
{ value: "search", label: t("best.recommend") },
|
|
1028
|
+
{ value: "best", label: t("best.picks") },
|
|
1029
|
+
], mode, setMode)),
|
|
1030
|
+
...(mode === "search"
|
|
1031
|
+
? [
|
|
1032
|
+
controls(cat),
|
|
1033
|
+
cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
|
|
1034
|
+
cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
|
|
1035
|
+
!cat.state.loading && !cat.state.error && cat.plugins.length === 0 ? h(Notice, { key: "empty", text: t("state.empty") }) : null,
|
|
1036
|
+
h("div", { className: "dph_panelBody", key: "body" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, true))),
|
|
1037
|
+
]
|
|
1038
|
+
: [
|
|
1039
|
+
best.state.error ? h(Notice, { key: "berror", kind: "bad", text: t("state.failed") + ":" + best.state.error }) : null,
|
|
1040
|
+
best.state.loading && !bestData ? h(Notice, { key: "bloading", text: t("best.loading") }) : null,
|
|
1041
|
+
!best.state.loading && bestData && (bestData.total || 0) === 0 ? h(Notice, { key: "bempty", text: t("best.empty") }) : null,
|
|
1042
|
+
h("div", { className: "dph_panelBody", key: "bbody" }, renderBest(bestData, best.copiedCmd, best.markCopied)),
|
|
1043
|
+
]),
|
|
877
1044
|
h("div", { className: "dph_panelFoot", key: "foot" }, [
|
|
878
1045
|
telemetryToggle(),
|
|
879
1046
|
h("span", { key: "hint", className: "dph_footer" }, t("footer.hint")),
|
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export const name = "dpharness";
|
|
|
34
34
|
/** The dsh web server service used to register HTTP routes. */
|
|
35
35
|
export const inject = ["webServer"];
|
|
36
36
|
|
|
37
|
-
export const VERSION = "0.
|
|
37
|
+
export const VERSION = "0.4.1";
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Profile used for installs.
|
|
@@ -51,6 +51,7 @@ const PROFILE = (() => {
|
|
|
51
51
|
})();
|
|
52
52
|
|
|
53
53
|
const UPSTREAM = "https://dpharness.com/api/plugins";
|
|
54
|
+
const BEST_UPSTREAM = "https://dpharness.com/api/best";
|
|
54
55
|
const SITE = "https://dpharness.com";
|
|
55
56
|
const TRACK = "https://dpharness.com/api/track/event";
|
|
56
57
|
const DEFAULT_TAKE = 30;
|
|
@@ -237,6 +238,8 @@ function jobView() {
|
|
|
237
238
|
|
|
238
239
|
/** key -> { at: epochMs, value: { count, plugins } } */
|
|
239
240
|
const cache = new Map();
|
|
241
|
+
/** /api/best 单键缓存(榜单每月只重算一次,5 分钟缓存足够) */
|
|
242
|
+
let bestCache = { at: 0, value: null };
|
|
240
243
|
let eventWindow = { startedAt: 0, count: 0 };
|
|
241
244
|
|
|
242
245
|
/**
|
|
@@ -441,9 +444,59 @@ async function fetchCatalog(params) {
|
|
|
441
444
|
}
|
|
442
445
|
}
|
|
443
446
|
|
|
444
|
-
|
|
447
|
+
/**
|
|
448
|
+
* 「分类精选」榜单(站点 /api/best,2026-09-18 新增的只读接口)。
|
|
449
|
+
*
|
|
450
|
+
* 与 fetchCatalog 的关系:两者都是站点的策展/目录数据,**条目一律走同一个 slim()**,
|
|
451
|
+
* 否则卡片会出现两套字段口径(本站已经栽过一次:命令口径不一致)。
|
|
452
|
+
* 唯一补充是 `category`:上游 /api/best 只给大类 key 在分组结构里,
|
|
453
|
+
* 条目本身没有 Plugin.category,故把所在大类的 key 注入每条,卡片才能显示正确分类。
|
|
454
|
+
*/
|
|
455
|
+
async function fetchBest() {
|
|
445
456
|
const now = Date.now();
|
|
446
|
-
if (now -
|
|
457
|
+
if (bestCache.value && now - bestCache.at < CACHE_TTL_MS) {
|
|
458
|
+
return { ...bestCache.value, cached: true, fetchedAt: bestCache.at };
|
|
459
|
+
}
|
|
460
|
+
const controller = new AbortController();
|
|
461
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
462
|
+
try {
|
|
463
|
+
const response = await fetch(BEST_UPSTREAM, {
|
|
464
|
+
headers: { accept: "application/json", "user-agent": `dsh-dpharness/${VERSION}` },
|
|
465
|
+
signal: controller.signal,
|
|
466
|
+
});
|
|
467
|
+
if (!response.ok) throw new Error(`upstream HTTP ${response.status}`);
|
|
468
|
+
const body = await response.json();
|
|
469
|
+
const categories = (Array.isArray(body && body.categories) ? body.categories : []).map((cat) => ({
|
|
470
|
+
key: cat.key,
|
|
471
|
+
label: cat.label,
|
|
472
|
+
count: cat.count,
|
|
473
|
+
subs: (Array.isArray(cat.subs) ? cat.subs : []).map((sub) => ({
|
|
474
|
+
key: sub.key,
|
|
475
|
+
label: sub.label,
|
|
476
|
+
summary: sub.summary || "",
|
|
477
|
+
items: (Array.isArray(sub.items) ? sub.items : []).map((item) => ({
|
|
478
|
+
...slim({ ...item, category: cat.key }),
|
|
479
|
+
// 名次与上榜理由是「为什么是它」的依据,不能丢
|
|
480
|
+
rank: typeof item.rank === "number" ? item.rank : null,
|
|
481
|
+
reason: typeof item.reason === "string" ? item.reason : "",
|
|
482
|
+
})),
|
|
483
|
+
})),
|
|
484
|
+
}));
|
|
485
|
+
const value = {
|
|
486
|
+
month: body && typeof body.month === "string" ? body.month : null,
|
|
487
|
+
total: typeof (body && body.total) === "number" ? body.total : 0,
|
|
488
|
+
categories,
|
|
489
|
+
// rank 越靠前的越该被看见,这里按小类聚合但保持接口给的顺序(口径与页面一致)
|
|
490
|
+
};
|
|
491
|
+
bestCache = { at: Date.now(), value };
|
|
492
|
+
return { ...value, cached: false, fetchedAt: Date.now() };
|
|
493
|
+
} finally {
|
|
494
|
+
clearTimeout(timer);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function withinEventBudget() {
|
|
499
|
+
const now = Date.now(); if (now - eventWindow.startedAt > EVENT_WINDOW_MS) {
|
|
447
500
|
eventWindow = { startedAt: now, count: 0 };
|
|
448
501
|
}
|
|
449
502
|
eventWindow.count += 1;
|
|
@@ -504,6 +557,29 @@ function registerRoute(ctx, pathname, handler) {
|
|
|
504
557
|
}
|
|
505
558
|
|
|
506
559
|
export function apply(ctx) {
|
|
560
|
+
// 「分类精选」:站点 /best 专区的同源数据(月度策展,每小类 2~3 个)
|
|
561
|
+
registerRoute(ctx, "/api/dpharness/best", async (req, res) => {
|
|
562
|
+
if (req.method !== "GET") {
|
|
563
|
+
res.writeHead(405, { allow: "GET" });
|
|
564
|
+
res.end();
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
try {
|
|
568
|
+
const result = await fetchBest();
|
|
569
|
+
sendJson(res, 200, {
|
|
570
|
+
ok: true,
|
|
571
|
+
source: `${SITE}/best`,
|
|
572
|
+
cached: result.cached,
|
|
573
|
+
fetchedAt: new Date(result.fetchedAt).toISOString(),
|
|
574
|
+
month: result.month,
|
|
575
|
+
total: result.total,
|
|
576
|
+
categories: result.categories,
|
|
577
|
+
});
|
|
578
|
+
} catch (error) {
|
|
579
|
+
sendJson(res, 502, { ok: false, error: String((error && error.message) || error) });
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
|
|
507
583
|
registerRoute(ctx, "/api/dpharness/search", async (req, res) => {
|
|
508
584
|
if (req.method !== "GET") {
|
|
509
585
|
res.writeHead(405, { allow: "GET" });
|
|
@@ -630,6 +706,7 @@ export function apply(ctx) {
|
|
|
630
706
|
tracker: TRACK,
|
|
631
707
|
routes: [
|
|
632
708
|
"/api/dpharness/search",
|
|
709
|
+
"/api/dpharness/best",
|
|
633
710
|
"/api/dpharness/event",
|
|
634
711
|
"/api/dpharness/install",
|
|
635
712
|
"/api/dpharness/meta",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dpharness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Curated dpharness.com plugin catalog inside the DeepSeek Harness Web GUI: a conversation-view tab, a sidebar entry and a site-wide floating panel, with one-click install via dshmarket or the dsh CLI. Read-only catalog plus an opt-out telemetry relay.",
|
|
5
5
|
"author": "zhanghao3693 <zhanghao3693@qq.com>",
|
|
6
6
|
"repository": {
|