dsh-dpharness 0.7.0 → 0.8.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/lib/changelog.js +20 -0
- package/lib/client.js +210 -9
- package/lib/index.js +197 -1
- package/package.json +1 -1
package/lib/changelog.js
CHANGED
|
@@ -37,6 +37,26 @@ export function npmLatestUrl(pkg) {
|
|
|
37
37
|
* (用户要看的是行为变化,不是我们的 commit 分类)。
|
|
38
38
|
*/
|
|
39
39
|
export const CHANGELOG = [
|
|
40
|
+
{
|
|
41
|
+
version: "0.8.0",
|
|
42
|
+
date: "2026-11-18",
|
|
43
|
+
title: "插件面板新增可合作的展示位",
|
|
44
|
+
items: [
|
|
45
|
+
"严选插件库面板里新增三处展示位:右栏、列表上方与页脚。它们是给合作方展示信息的卡片,与「今日推荐」完全分开,不会混进推荐结论里。",
|
|
46
|
+
"付费合作的内容会明确标注「广告」,与网站上的标注方式一致;站内自荐内容则显示自己的标签。",
|
|
47
|
+
"展示内容由网站统一配置,调整物料不需要更新插件;没有合作内容时这些位置不会出现,也不会留下空白占位。",
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
version: "0.7.1",
|
|
52
|
+
date: "2026-11-18",
|
|
53
|
+
title: "「今日推荐」现在和网站推的是同一个",
|
|
54
|
+
items: [
|
|
55
|
+
"打开面板或「每日推荐」时,看到的那一条与 dpharness.com 官网当天推荐的一致。此前两端各算各的,同一天可能显示不同插件。",
|
|
56
|
+
"如果网站当天的推荐暂时取不到,仍会显示一条本地结果,并在卡片上标明「当前显示本地口径,可能与网站不同」——不会把本地结果冒充成官网同源。",
|
|
57
|
+
"这条推荐每天 00:00(北京时间)更换,当天对所有用户一致。",
|
|
58
|
+
],
|
|
59
|
+
},
|
|
40
60
|
{
|
|
41
61
|
version: "0.7.0",
|
|
42
62
|
date: "2026-10-30",
|
package/lib/client.js
CHANGED
|
@@ -181,6 +181,20 @@ window.__ModuleLoader__.load({
|
|
|
181
181
|
".dph_setCol{display:flex;flex-direction:column;gap:2px;min-width:0}",
|
|
182
182
|
".dph_setLabel{font-size:13px;color:var(--dsw-alias-label-primary)}",
|
|
183
183
|
".dph_setHint{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}",
|
|
184
|
+
/* 今日推荐口径标注(2026-11-18):同源=低调绿,本地回落=中性灰,
|
|
185
|
+
两类都不抢主 CTA 视觉,但能一眼看出这条是否与网站一致。 */
|
|
186
|
+
".dph_dailyMode{font-size:11px;line-height:1.5;margin:4px 0 0;color:var(--dsw-alias-label-tertiary)}",
|
|
187
|
+
".dph_dailyModeSite{color:var(--dsw-alias-success-fg,#16a34a)}",
|
|
188
|
+
/* 招商物料卡(2026-11-18):沿用 dph_railCard 卡片语言,但整体更轻——
|
|
189
|
+
角标固定「广告」、不抢安装主 CTA 的实心 accent。三处共用同一组件。 */
|
|
190
|
+
".dph_adCard{position:relative;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:10px 12px;background:var(--dsw-alias-bg-secondary,transparent)}",
|
|
191
|
+
".dph_adBadge{display:inline-block;font-size:10px;line-height:1;padding:3px 5px;border-radius:4px;background:var(--dsw-alias-bg-tertiary,rgba(127,127,127,.15));color:var(--dsw-alias-label-secondary);vertical-align:middle;margin-right:6px}",
|
|
192
|
+
".dph_adBadgeOwn{color:var(--dsw-alias-accent-fg,#0a7)}",
|
|
193
|
+
".dph_adBrand{font-size:11px;color:var(--dsw-alias-label-secondary)}",
|
|
194
|
+
".dph_adTitle{font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary);margin:4px 0 2px;line-height:1.45}",
|
|
195
|
+
".dph_adDesc{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}",
|
|
196
|
+
".dph_adCta{display:inline-block;margin-top:6px;font-size:11px;color:var(--dsw-alias-accent-fg,#0a7);text-decoration:none}",
|
|
197
|
+
".dph_adCta:hover{text-decoration:underline}",
|
|
184
198
|
".dph_setState{flex:none;font-size:12px;color:var(--dsw-alias-label-secondary)}",
|
|
185
199
|
/* 更新日志:版本折叠列表。复用 details/summary(与分类精选同一手法)——
|
|
186
200
|
原生折叠无需自己管状态,键盘可达性也白送。 */
|
|
@@ -464,6 +478,9 @@ window.__ModuleLoader__.load({
|
|
|
464
478
|
"daily.empty": "今日推荐暂不可用(榜单数据未就绪)",
|
|
465
479
|
"daily.why": "为什么是它",
|
|
466
480
|
"daily.hint": "每天 00:00(北京时间)换一条,当天对所有用户一致。",
|
|
481
|
+
"daily.modeSite": "与 dpharness.com 今日推荐同源",
|
|
482
|
+
"ad.badge": "广告",
|
|
483
|
+
"daily.modeLocal": "本站推荐暂不可用,当前显示本地口径(可能与网站不同)",
|
|
467
484
|
"daily.expand": "展开",
|
|
468
485
|
"daily.collapse": "收起",
|
|
469
486
|
"changelog.title": "更新日志",
|
|
@@ -798,6 +815,9 @@ window.__ModuleLoader__.load({
|
|
|
798
815
|
"daily.empty": "Today's pick is unavailable (catalogue data not ready)",
|
|
799
816
|
"daily.why": "Why this one",
|
|
800
817
|
"daily.hint": "Rotates at 00:00 (UTC+8); identical for everyone that day.",
|
|
818
|
+
"daily.modeSite": "Same as today's pick on dpharness.com",
|
|
819
|
+
"ad.badge": "Ad",
|
|
820
|
+
"daily.modeLocal": "Site pick unavailable; showing local result (may differ from the website)",
|
|
801
821
|
"daily.expand": "Expand",
|
|
802
822
|
"daily.collapse": "Collapse",
|
|
803
823
|
"changelog.title": "Changelog",
|
|
@@ -2612,8 +2632,159 @@ window.__ModuleLoader__.load({
|
|
|
2612
2632
|
return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
|
|
2613
2633
|
}
|
|
2614
2634
|
|
|
2635
|
+
/* 今日推荐同源取数(2026-11-18)。
|
|
2636
|
+
host 路由 /api/dpharness/daily-pick 已把「站点推荐的 fullName → best 完整 item」
|
|
2637
|
+
拼好,客户端只渲染。三个组件(面板/页签/侧栏)都要这条,用模块级缓存共享,
|
|
2638
|
+
避免一展开就发三次同样的请求 —— 与 useBest「拿到一次不再取」同纪律。 */
|
|
2639
|
+
let dailyPickShared = null; // { date, mode, matched, item, cat, sub, reason }
|
|
2640
|
+
let dailyPickInflight = null;
|
|
2641
|
+
|
|
2642
|
+
function useDailyPick(t, enabled, dateKey) {
|
|
2643
|
+
const [, force] = react.useState(0);
|
|
2644
|
+
react.useEffect(() => {
|
|
2645
|
+
if (!enabled || !dateKey) return undefined;
|
|
2646
|
+
// 同一天已有结果就不再取;跨日必重取(推荐是「今天」的语义)
|
|
2647
|
+
if (dailyPickShared && dailyPickShared.date === dateKey) return undefined;
|
|
2648
|
+
if (dailyPickInflight) {
|
|
2649
|
+
let alive = true;
|
|
2650
|
+
dailyPickInflight.then(() => { if (alive) force((n) => n + 1); });
|
|
2651
|
+
return () => { alive = false; };
|
|
2652
|
+
}
|
|
2653
|
+
const controller = new AbortController();
|
|
2654
|
+
const timer = setTimeout(() => controller.abort(), 20000);
|
|
2655
|
+
dailyPickInflight = readHostJson("/api/dpharness/daily-pick", controller.signal)
|
|
2656
|
+
.then((body) => {
|
|
2657
|
+
if (controller.signal.aborted) return null;
|
|
2658
|
+
// 站点接口给的是北京日;本地 dateKey 也是 UTC+8,直接可比
|
|
2659
|
+
dailyPickShared = {
|
|
2660
|
+
date: (body && body.date) || dateKey,
|
|
2661
|
+
mode: body && body.mode === "site" ? "site" : "local",
|
|
2662
|
+
matched: !!(body && body.matched),
|
|
2663
|
+
item: body && body.item ? body.item : null,
|
|
2664
|
+
cat: (body && body.cat) || "",
|
|
2665
|
+
sub: (body && body.sub) || "",
|
|
2666
|
+
reason: (body && body.reason) || "",
|
|
2667
|
+
};
|
|
2668
|
+
track("plugin_hub", {
|
|
2669
|
+
action: "daily_pick_resolved", mode: dailyPickShared.mode,
|
|
2670
|
+
matched: dailyPickShared.matched ? 1 : 0, reason: dailyPickShared.reason,
|
|
2671
|
+
});
|
|
2672
|
+
return dailyPickShared;
|
|
2673
|
+
})
|
|
2674
|
+
.catch(() => {
|
|
2675
|
+
// 取数失败按本地口径处理,绝不卡住「今日推荐」不显示
|
|
2676
|
+
if (!dailyPickShared || dailyPickShared.date !== dateKey) {
|
|
2677
|
+
dailyPickShared = { date: dateKey, mode: "local", matched: false, item: null, cat: "", sub: "", reason: "client_error" };
|
|
2678
|
+
}
|
|
2679
|
+
return dailyPickShared;
|
|
2680
|
+
})
|
|
2681
|
+
.finally(() => { dailyPickInflight = null; force((n) => n + 1); });
|
|
2682
|
+
return () => { clearTimeout(timer); controller.abort(); };
|
|
2683
|
+
}, [enabled, dateKey]);
|
|
2684
|
+
return dailyPickShared && dailyPickShared.date === dateKey ? dailyPickShared : null;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2615
2687
|
/**
|
|
2616
|
-
*
|
|
2688
|
+
* 决定「今日推荐」最终展示哪一条(2026-11-18 同源改造)。
|
|
2689
|
+
*
|
|
2690
|
+
* 优先用 host 路由给的站点同源 item(matched=true);否则回落本地 pickDaily。
|
|
2691
|
+
* 返回 { picked, mode }:picked 形状与本地一致({item,cat,sub}),
|
|
2692
|
+
* mode 用于卡片上标注口径,避免「本地算法结果冒充网站同源」。
|
|
2693
|
+
*/
|
|
2694
|
+
function resolveDailyPick(best, dailyPick, dateKey) {
|
|
2695
|
+
const mode = dailyPick && dailyPick.matched && dailyPick.item ? "site" : "local";
|
|
2696
|
+
if (mode === "site") {
|
|
2697
|
+
return { picked: { item: dailyPick.item, cat: dailyPick.cat, sub: dailyPick.sub }, mode };
|
|
2698
|
+
}
|
|
2699
|
+
return { picked: best.state.data ? pickDaily(best.state.data, dateKey) : null, mode };
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
/* 招商物料取数(2026-11-18,PRD-插件招商广告位)。
|
|
2703
|
+
站点 /api/plugin-ads 一次返回三个位的物料,经 host /api/dpharness/plugin-ads 转发。
|
|
2704
|
+
模块级共享:面板里三处(右栏/主列/页脚)各渲染一张卡,但只发一次请求。
|
|
2705
|
+
上刊免发版:host 缓存 60s、站点 no-store;这里组件挂载后取一次,切视图不重取。 */
|
|
2706
|
+
let pluginAdsShared = null;
|
|
2707
|
+
let pluginAdsInflight = null;
|
|
2708
|
+
|
|
2709
|
+
function usePluginAds(t, enabled) {
|
|
2710
|
+
const [, force] = react.useState(0);
|
|
2711
|
+
react.useEffect(() => {
|
|
2712
|
+
if (!enabled || pluginAdsShared || pluginAdsInflight) return undefined;
|
|
2713
|
+
const controller = new AbortController();
|
|
2714
|
+
const timer = setTimeout(() => controller.abort(), 20000);
|
|
2715
|
+
pluginAdsInflight = readHostJson("/api/dpharness/plugin-ads", controller.signal)
|
|
2716
|
+
.then((body) => {
|
|
2717
|
+
if (controller.signal.aborted) return;
|
|
2718
|
+
pluginAdsShared = Array.isArray(body && body.items) ? body.items : [];
|
|
2719
|
+
force((n) => n + 1);
|
|
2720
|
+
})
|
|
2721
|
+
.catch(() => {
|
|
2722
|
+
pluginAdsShared = []; // 取数失败 = 不渲染广告,绝不阻塞面板
|
|
2723
|
+
force((n) => n + 1);
|
|
2724
|
+
})
|
|
2725
|
+
.finally(() => { pluginAdsInflight = null; clearTimeout(timer); });
|
|
2726
|
+
return () => { clearTimeout(timer); controller.abort(); };
|
|
2727
|
+
}, [enabled]);
|
|
2728
|
+
return pluginAdsShared;
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
/**
|
|
2732
|
+
* 招商物料卡。三处(右栏 / 主列 / 页脚)共用同一组件,避免三套口径。
|
|
2733
|
+
*
|
|
2734
|
+
* 🔴 角标合规(沿用站内 config/sponsor.ts):kind="ad" 强制渲染「广告」,
|
|
2735
|
+
* **不读物料的 tag 字段**(tag 可被配置改写,不能承载广告标识);
|
|
2736
|
+
* 只有 kind="own" 才显示物料自带的 tag。与站内 SponsorSlot 完全同一条纪律。
|
|
2737
|
+
* 🔴 埋点走 plugin_hub 事件(插件唯一能进站点的通道),位与物料 id 用
|
|
2738
|
+
* host buildTrackPayload 白名单里的 via / pkg 段承载(新增字段会被丢弃)。
|
|
2739
|
+
*/
|
|
2740
|
+
function AdCard(props) {
|
|
2741
|
+
// 🔴 必须是组件形式(h(AdCard, props))而非普通函数调用 —— 内部有 hooks。
|
|
2742
|
+
// 站内既有 dailyCard/railDailyCard 是纯函数(无 hooks),不要照抄那个调用方式。
|
|
2743
|
+
const item = props && props.item;
|
|
2744
|
+
const t = props && props.t;
|
|
2745
|
+
const hasItem = !!(item && item.slot);
|
|
2746
|
+
react.useEffect(() => {
|
|
2747
|
+
if (!hasItem) return;
|
|
2748
|
+
// via=位、pkg=物料 id —— 二者都在 buildTrackPayload 的白名单段内
|
|
2749
|
+
track("plugin_hub", {
|
|
2750
|
+
action: "ad_show", via: item.code || item.slot,
|
|
2751
|
+
pkg: String(item.id || "").slice(0, 64),
|
|
2752
|
+
});
|
|
2753
|
+
}, [hasItem, item && item.id]);
|
|
2754
|
+
if (!hasItem) return null;
|
|
2755
|
+
const slotCode = item.code || item.slot;
|
|
2756
|
+
const isAd = item.kind === "ad";
|
|
2757
|
+
const badge = isAd ? t("ad.badge") : (item.tag || t("ad.badge"));
|
|
2758
|
+
const href = String(item.url || "");
|
|
2759
|
+
const external = item.external !== false && /^https?:\/\//i.test(href);
|
|
2760
|
+
const report = (action) => {
|
|
2761
|
+
track("plugin_hub", { action, via: slotCode, pkg: String(item.id || "").slice(0, 64) });
|
|
2762
|
+
};
|
|
2763
|
+
return h("div", { className: "dph_adCard", "data-ad-slot": item.slot, key: "ad-" + item.slot }, [
|
|
2764
|
+
h("div", { className: "dph_bar", key: "head" }, [
|
|
2765
|
+
h("span", {
|
|
2766
|
+
className: "dph_adBadge" + (isAd ? "" : " dph_adBadgeOwn"),
|
|
2767
|
+
key: "badge",
|
|
2768
|
+
}, badge),
|
|
2769
|
+
item.brand ? h("span", { className: "dph_adBrand", key: "brand" }, item.brand) : null,
|
|
2770
|
+
]),
|
|
2771
|
+
h("div", { className: "dph_adTitle", key: "title" }, item.title),
|
|
2772
|
+
item.desc ? h("div", { className: "dph_adDesc", key: "desc" }, item.desc) : null,
|
|
2773
|
+
Array.isArray(item.points) && item.points.length
|
|
2774
|
+
? h("div", { className: "dph_tags", key: "points" }, item.points.slice(0, 3).map((p, i) =>
|
|
2775
|
+
h("span", { className: "dph_tag", key: "p" + i }, p)))
|
|
2776
|
+
: null,
|
|
2777
|
+
h("a", {
|
|
2778
|
+
className: "dph_adCta", key: "cta", href,
|
|
2779
|
+
target: external ? "_blank" : undefined,
|
|
2780
|
+
rel: external ? "noopener noreferrer" : undefined,
|
|
2781
|
+
onClick: () => report("ad_click"),
|
|
2782
|
+
}, item.cta || t("action.openSite")),
|
|
2783
|
+
]);
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
/**
|
|
2787
|
+
* 「套装」取数(站点 /sets 的同源数据,经本机 host 转发)。
|
|
2617
2788
|
*
|
|
2618
2789
|
* 与 useBest 同一条纪律:只在切到该视图时才请求;拿到一次就不再重复,
|
|
2619
2790
|
* 点刷新才重取(缓存交给 host,TTL 5 分钟)。
|
|
@@ -3639,7 +3810,10 @@ window.__ModuleLoader__.load({
|
|
|
3639
3810
|
* 本组件只负责上面那行「今日 + 日期 + 所属小类」的抬头与上榜理由。
|
|
3640
3811
|
*/
|
|
3641
3812
|
function dailyCard(best, copiedCmd, onCopied, opts) {
|
|
3642
|
-
|
|
3813
|
+
// 2026-11-18 同源:优先站点接口 item,回落本地算法;opts.dailyPick 由调用方注入
|
|
3814
|
+
const resolved = resolveDailyPick(best, opts.dailyPick, opts.dateKey);
|
|
3815
|
+
const picked = resolved.picked;
|
|
3816
|
+
const pickMode = resolved.mode;
|
|
3643
3817
|
/* 窄面板里默认**收成一行**(调用方给 opts.collapsed + opts.toggle):
|
|
3644
3818
|
实测浮动面板 max-height 只有 min(72vh, 620px),而完整的今日推荐卡约 350px
|
|
3645
3819
|
且 flex:none 不收缩 —— 结果区被压到只剩一小条,用户的说法是
|
|
@@ -3671,6 +3845,12 @@ window.__ModuleLoader__.load({
|
|
|
3671
3845
|
picked.item.reason
|
|
3672
3846
|
? h("p", { className: "dph_dailyWhy", key: "why" }, t("daily.why") + ":" + picked.item.reason)
|
|
3673
3847
|
: null,
|
|
3848
|
+
/* 口径标注(2026-11-18):同源/本地如实说,不让本地结果冒充网站推荐 */
|
|
3849
|
+
h("div", {
|
|
3850
|
+
className: "dph_dailyMode" + (pickMode === "site" ? " dph_dailyModeSite" : ""),
|
|
3851
|
+
key: "mode",
|
|
3852
|
+
"data-pick-mode": pickMode,
|
|
3853
|
+
}, t(pickMode === "site" ? "daily.modeSite" : "daily.modeLocal")),
|
|
3674
3854
|
h("div", { className: "dph_setHint", key: "hint" }, t("daily.hint")),
|
|
3675
3855
|
]);
|
|
3676
3856
|
}
|
|
@@ -4914,8 +5094,10 @@ window.__ModuleLoader__.load({
|
|
|
4914
5094
|
* 避免选取逻辑出现第二份实现。取数失败时同样要说清"暂不可用",
|
|
4915
5095
|
* 不能静止消失 —— 它是侧栏里唯一"今天该装哪个"的答案。
|
|
4916
5096
|
*/
|
|
4917
|
-
function railDailyCard(best, copiedCmd, onCopied, dateKey) {
|
|
4918
|
-
const
|
|
5097
|
+
function railDailyCard(best, copiedCmd, onCopied, dateKey, dailyPick) {
|
|
5098
|
+
const resolved = resolveDailyPick(best, dailyPick, dateKey);
|
|
5099
|
+
const picked = resolved.picked;
|
|
5100
|
+
const pickMode = resolved.mode;
|
|
4919
5101
|
if (!picked) {
|
|
4920
5102
|
return h("div", { className: "dph_railCard dph_railCardAccent", key: "daily" }, [
|
|
4921
5103
|
h("div", { className: "dph_bar", key: "head" }, [
|
|
@@ -4961,6 +5143,10 @@ window.__ModuleLoader__.load({
|
|
|
4961
5143
|
])
|
|
4962
5144
|
: null,
|
|
4963
5145
|
item.reason ? h("p", { className: "dph_railWhy", key: "why" }, t("daily.why") + ":" + item.reason) : null,
|
|
5146
|
+
h("div", {
|
|
5147
|
+
className: "dph_dailyMode" + (pickMode === "site" ? " dph_dailyModeSite" : ""),
|
|
5148
|
+
key: "mode", "data-pick-mode": pickMode,
|
|
5149
|
+
}, t(pickMode === "site" ? "daily.modeSite" : "daily.modeLocal")),
|
|
4964
5150
|
]);
|
|
4965
5151
|
}
|
|
4966
5152
|
|
|
@@ -4993,6 +5179,11 @@ window.__ModuleLoader__.load({
|
|
|
4993
5179
|
daily 开着时必须取,关掉后即回到「只有切到榜单/每日视图才请求」。
|
|
4994
5180
|
不给侧栏新增任何请求 —— 全站只有这一个数据源。 */
|
|
4995
5181
|
const best = useBest(t, mode === "best" || mode === "daily" || state.daily);
|
|
5182
|
+
// 今日推荐同源(2026-11-18):与 best 同开关,三组件共享模块级缓存只发一次
|
|
5183
|
+
const dailyPick = useDailyPick(t, mode === "best" || mode === "daily" || state.daily, dateKey);
|
|
5184
|
+
// 招商物料(2026-11-18):三个位一次请求,模块级共享
|
|
5185
|
+
const ads = usePluginAds(t, mode === "best" || mode === "daily" || state.daily);
|
|
5186
|
+
const adOf = (slot) => ads && ads.find((a) => a.slot === slot);
|
|
4996
5187
|
const sets = useSets(t, mode === "sets");
|
|
4997
5188
|
const board = useBoard(t, boardKind, mode === "board");
|
|
4998
5189
|
const data = cat.state.data;
|
|
@@ -5059,7 +5250,7 @@ window.__ModuleLoader__.load({
|
|
|
5059
5250
|
]
|
|
5060
5251
|
: isDaily
|
|
5061
5252
|
? [
|
|
5062
|
-
h("div", { className: "dph_list", key: "dlist" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey })),
|
|
5253
|
+
h("div", { className: "dph_list", key: "dlist" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey, dailyPick: dailyPick })),
|
|
5063
5254
|
]
|
|
5064
5255
|
: isBoard
|
|
5065
5256
|
? [
|
|
@@ -5178,15 +5369,19 @@ window.__ModuleLoader__.load({
|
|
|
5178
5369
|
/* 社群 + 订阅:与待重启横幅同一层(常驻、不随列表滚走)。展开二维码后
|
|
5179
5370
|
会把列表往下推约 120px —— 可接受,因为它是点击后的主动结果。 */
|
|
5180
5371
|
h(JoinCard, { key: "join" }),
|
|
5372
|
+
h(AdCard, { item: adOf("plugin-inline"), t: t, scope: "tab", key: "ad-inline" }),
|
|
5181
5373
|
...body,
|
|
5374
|
+
h(AdCard, { item: adOf("plugin-footer"), t: t, scope: "tab", key: "ad-footer" }),
|
|
5182
5375
|
h("div", { className: "dph_footer", key: "hint" }, t("footer.hint")),
|
|
5183
5376
|
h("div", { className: "dph_footer", key: "tel" }, h("div", { className: "dph_footToggles" }, [telemetryToggle(), floatToggle()])),
|
|
5184
5377
|
]),
|
|
5185
5378
|
h("div", { className: "dph_rail", key: "rail" }, [
|
|
5186
5379
|
showRailDaily
|
|
5187
|
-
? h("div", { className: "dph_dailySlot", key: "dslot" }, railDailyCard(best, cat.copiedCmd, cat.markCopied, dateKey))
|
|
5380
|
+
? h("div", { className: "dph_dailySlot", key: "dslot" }, railDailyCard(best, cat.copiedCmd, cat.markCopied, dateKey, dailyPick))
|
|
5188
5381
|
: null,
|
|
5189
|
-
h("div", { className: "dph_railSlot", key: "rslot" }, [highlightCard, installCard
|
|
5382
|
+
h("div", { className: "dph_railSlot", key: "rslot" }, [highlightCard, installCard,
|
|
5383
|
+
h(AdCard, { item: adOf("plugin-rail"), t: t, scope: "tab", key: "ad-rail" }),
|
|
5384
|
+
].filter(Boolean)),
|
|
5190
5385
|
]),
|
|
5191
5386
|
]);
|
|
5192
5387
|
}
|
|
@@ -5291,6 +5486,11 @@ window.__ModuleLoader__.load({
|
|
|
5291
5486
|
关掉每日推荐开关后,回到「只有切到榜单/每日视图才请求」。
|
|
5292
5487
|
仍然挂在 state.open 上:收成胶囊时不发这个请求。 */
|
|
5293
5488
|
const best = useBest(t, state.open && (mode === "best" || mode === "daily" || state.daily));
|
|
5489
|
+
// 今日推荐同源(2026-11-18):面板收成胶囊时(!state.open)不发请求
|
|
5490
|
+
const dailyPick = useDailyPick(t, state.open && (mode === "best" || mode === "daily" || state.daily), dateKey);
|
|
5491
|
+
// 招商物料(2026-11-18):面板是 400px 窄形态,只放页脚位 P3(与页签共用缓存,不额外请求)
|
|
5492
|
+
const ads = usePluginAds(t, state.open && (mode === "best" || mode === "daily" || state.daily));
|
|
5493
|
+
const adFooter = ads && ads.find((a) => a.slot === "plugin-footer");
|
|
5294
5494
|
const bestData = best.state.data;
|
|
5295
5495
|
const sets = useSets(t, state.open && mode === "sets");
|
|
5296
5496
|
const setsData = sets.state.data;
|
|
@@ -5463,11 +5663,11 @@ window.__ModuleLoader__.load({
|
|
|
5463
5663
|
]
|
|
5464
5664
|
: mode === "daily"
|
|
5465
5665
|
? [
|
|
5466
|
-
h("div", { className: "dph_panelBody", key: "dbody" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey })),
|
|
5666
|
+
h("div", { className: "dph_panelBody", key: "dbody" }, dailyCard(best, best.copiedCmd, best.markCopied, { dateKey: dateKey, dailyPick: dailyPick })),
|
|
5467
5667
|
]
|
|
5468
5668
|
: mode === "search"
|
|
5469
5669
|
? [
|
|
5470
|
-
state.daily ? dailyCard(best, cat.copiedCmd, cat.markCopied, { dateKey: dateKey, collapsed: !dailyOpen, toggle: () => setDailyOpen((v) => !v) }) : null,
|
|
5670
|
+
state.daily ? dailyCard(best, cat.copiedCmd, cat.markCopied, { dateKey: dateKey, dailyPick: dailyPick, collapsed: !dailyOpen, toggle: () => setDailyOpen((v) => !v) }) : null,
|
|
5471
5671
|
controls(cat),
|
|
5472
5672
|
cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
|
|
5473
5673
|
cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
|
|
@@ -5486,6 +5686,7 @@ window.__ModuleLoader__.load({
|
|
|
5486
5686
|
/* 浮窗里也放一份:浮窗是曝光最高的入口,只有页签有等于大半用户看不到。
|
|
5487
5687
|
compact 版省掉说明行,二维码默认收起(面板只有 400px 宽)。 */
|
|
5488
5688
|
h(JoinCard, { key: "join", compact: true }),
|
|
5689
|
+
h(AdCard, { item: adFooter, t: t, scope: "panel", key: "ad-footer" }),
|
|
5489
5690
|
h("div", { className: "dph_footRow", key: "row" }, [
|
|
5490
5691
|
telemetryToggle(),
|
|
5491
5692
|
h("button", {
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,7 @@ export const name = "dpharness";
|
|
|
48
48
|
/** The dsh web server service used to register HTTP routes. */
|
|
49
49
|
export const inject = ["webServer"];
|
|
50
50
|
|
|
51
|
-
export const VERSION = "0.
|
|
51
|
+
export const VERSION = "0.8.0";
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* 本插件在 npm 上的包名 —— 与 dsh 的插件 id(上面的 `name = "dpharness"`)**不是一回事**,
|
|
@@ -269,6 +269,12 @@ export function profileFromArgv(argv = process.argv) {
|
|
|
269
269
|
const UPSTREAM = "https://dpharness.com/api/plugins";
|
|
270
270
|
const BEST_UPSTREAM = "https://dpharness.com/api/best";
|
|
271
271
|
const SETS_UPSTREAM = "https://dpharness.com/api/sets";
|
|
272
|
+
/** 「今日推荐」的上游:站点的唯一选取实现(2026-11-18 接入,见 fetchDailyPick)。 */
|
|
273
|
+
const DAILY_PICK_UPSTREAM = "https://dpharness.com/api/daily-pick";
|
|
274
|
+
/** 招商物料的上游(2026-11-18,PRD-插件招商广告位)。站点 no-store,插件侧只做短缓存。 */
|
|
275
|
+
const PLUGIN_ADS_UPSTREAM = "https://dpharness.com/api/plugin-ads";
|
|
276
|
+
/** 物料缓存 60s:上刊/下刊最多等 1 分钟生效,同时避免每次开面板都打上游。 */
|
|
277
|
+
const PLUGIN_ADS_TTL_MS = 60 * 1000;
|
|
272
278
|
const SITE = "https://dpharness.com";
|
|
273
279
|
const TRACK = "https://dpharness.com/api/track/event";
|
|
274
280
|
/**
|
|
@@ -871,6 +877,10 @@ export function pkgState(pkg, manifest = profileManifest()) {
|
|
|
871
877
|
const cache = new Map();
|
|
872
878
|
/** /api/best 单键缓存(榜单每月只重算一次,5 分钟缓存足够) */
|
|
873
879
|
let bestCache = { at: 0, value: null };
|
|
880
|
+
/** /api/daily-pick 的结果缓存(按自然日缓存,跨日必失效——推荐是「今天」的语义)。 */
|
|
881
|
+
let dailyPickCache = { date: "", value: null };
|
|
882
|
+
/** /api/plugin-ads 的物料缓存(短 TTL,保证上刊免发版且不过度打上游)。 */
|
|
883
|
+
let pluginAdsCache = { at: 0, value: null };
|
|
874
884
|
/** /api/sets 单键缓存(套装同样每月才同步一次,缓存策略与 /best 一致) */
|
|
875
885
|
let setsCache = { at: 0, value: null };
|
|
876
886
|
let eventWindow = { startedAt: 0, count: 0 };
|
|
@@ -1152,6 +1162,70 @@ async function fetchBest() {
|
|
|
1152
1162
|
}
|
|
1153
1163
|
}
|
|
1154
1164
|
|
|
1165
|
+
/**
|
|
1166
|
+
* 「今日推荐」的上游选取(站点 /api/daily-pick,2026-11-18 接入)。
|
|
1167
|
+
*
|
|
1168
|
+
* 为什么要接它:插件端 2026-10-12 定的 pickDaily() 是从 /api/best 展平后按
|
|
1169
|
+
* UTC+8 日期取模的**本地**算法,而站点 11-15 上线了 /api/daily-pick —— 同一天
|
|
1170
|
+
* 两端选出不同插件(11-18 实测:本地 wqty123/dsh-browser vs 站点
|
|
1171
|
+
* shanliuling/dsh-image-gen),「今日推荐」语义当场破产。插件注释里写的
|
|
1172
|
+
* 「日后站点给出接口就替换数据源」就是这一天。
|
|
1173
|
+
*
|
|
1174
|
+
* 本函数只取站点的 { date, fullName },不取完整条目:/api/daily-pick 只给精简
|
|
1175
|
+
* 元数据(fullName/nameZh/desc…),**没有安装命令**;完整 item 由路由层从 best
|
|
1176
|
+
* 缓存里按 fullName 找出后拼回(见 /api/dpharness/daily-pick 路由)。
|
|
1177
|
+
*
|
|
1178
|
+
* 缓存按自然日键:同一天重复请求直接命中,跨日(date 变化)必然重取 —— 不用
|
|
1179
|
+
* CACHE_TTL_MS,因为「今日推荐」的正确性绑定日期而非时间流逝。上游失败返回 null,
|
|
1180
|
+
* 由路由层决定回落本地算法,绝不把失败伪装成「站点没推荐」。
|
|
1181
|
+
*/
|
|
1182
|
+
async function fetchDailyPick() {
|
|
1183
|
+
const controller = new AbortController();
|
|
1184
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
1185
|
+
try {
|
|
1186
|
+
const response = await fetch(DAILY_PICK_UPSTREAM, {
|
|
1187
|
+
headers: { accept: "application/json", "user-agent": `dsh-dpharness/${VERSION}` },
|
|
1188
|
+
signal: controller.signal,
|
|
1189
|
+
});
|
|
1190
|
+
if (!response.ok) throw new Error(`upstream HTTP ${response.status}`);
|
|
1191
|
+
const body = await response.json();
|
|
1192
|
+
const date = body && typeof body.date === "string" ? body.date : "";
|
|
1193
|
+
const fullName = body && body.pick && typeof body.pick.fullName === "string"
|
|
1194
|
+
? body.pick.fullName : "";
|
|
1195
|
+
// pick:null(站点当天候选池为空)是合法形态,不是错误 —— 照实返回让路由层回落
|
|
1196
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw new Error("upstream date missing");
|
|
1197
|
+
dailyPickCache = { date, value: { date, fullName } };
|
|
1198
|
+
return { ...dailyPickCache.value, cached: false };
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
return null;
|
|
1201
|
+
} finally {
|
|
1202
|
+
clearTimeout(timer);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* 从已缓存的 best 数据里按 fullName 找完整条目。
|
|
1208
|
+
*
|
|
1209
|
+
* 为什么不在 fetchDailyPick 里直接用站点给的精简 pick:dailyCard 走 renderCard,
|
|
1210
|
+
* 需要 best 条目的 pkg(安装命令)、rank、reason 等字段,/api/daily-pick 一概不给。
|
|
1211
|
+
* 找到了返回 { item, cat, sub },找不到返回 null —— 由路由层标 matched=false 回落。
|
|
1212
|
+
* best 数据由 fetchBest() 提供(有 5 分钟缓存,不会为这一条多打上游)。
|
|
1213
|
+
*/
|
|
1214
|
+
async function findBestItem(fullName) {
|
|
1215
|
+
if (!fullName) return null;
|
|
1216
|
+
const best = await fetchBest();
|
|
1217
|
+
for (const cat of Array.isArray(best.categories) ? best.categories : []) {
|
|
1218
|
+
for (const sub of Array.isArray(cat.subs) ? cat.subs : []) {
|
|
1219
|
+
for (const item of Array.isArray(sub.items) ? sub.items : []) {
|
|
1220
|
+
if ((item && item.fullName) === fullName) {
|
|
1221
|
+
return { item, cat: cat.label || cat.key || "", sub: sub.label || sub.key || "" };
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1155
1229
|
/**
|
|
1156
1230
|
* 「组合方案套装」(站点 /api/sets 的同源数据,2026-10-13 新增)。
|
|
1157
1231
|
*
|
|
@@ -2076,6 +2150,126 @@ export function apply(ctx) {
|
|
|
2076
2150
|
}
|
|
2077
2151
|
});
|
|
2078
2152
|
|
|
2153
|
+
/* 「今日推荐」的同源路由(2026-11-18):让插件端与站点推同一条。
|
|
2154
|
+
返回口径契约(client 侧 useDailyPick 依赖):
|
|
2155
|
+
· matched=true → mode:"site",item/cat/sub 是 best 的完整条目,可直接 renderCard;
|
|
2156
|
+
· matched=false → mode:"local",客户端回落到本地 pickDaily(best),并在卡片标注口径。
|
|
2157
|
+
三种 matched=false 的原因分开给 reason,便于埋点区分「站点今天没候选」与「上游挂了」。
|
|
2158
|
+
🔴 永远返回 200(除方法错误):这是「推荐降级」不是「接口故障」,让 UI 有内容显示。 */
|
|
2159
|
+
registerRoute(ctx, "/api/dpharness/daily-pick", async (req, res) => {
|
|
2160
|
+
if (req.method !== "GET") {
|
|
2161
|
+
res.writeHead(405, { allow: "GET" });
|
|
2162
|
+
res.end();
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
try {
|
|
2166
|
+
// 同一天直接用缓存的 fullName,避免每次开面板都打上游
|
|
2167
|
+
const nowDate = new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
|
2168
|
+
const cached = dailyPickCache.date === nowDate ? dailyPickCache.value : null;
|
|
2169
|
+
const pick = cached || await fetchDailyPick();
|
|
2170
|
+
if (!pick) {
|
|
2171
|
+
sendJson(res, 200, {
|
|
2172
|
+
ok: true, mode: "local", matched: false, reason: "upstream_unavailable",
|
|
2173
|
+
date: nowDate, source: `${SITE}/api/daily-pick`,
|
|
2174
|
+
});
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
if (!pick.fullName) {
|
|
2178
|
+
sendJson(res, 200, {
|
|
2179
|
+
ok: true, mode: "local", matched: false, reason: "site_empty_pool",
|
|
2180
|
+
date: pick.date, source: `${SITE}/api/daily-pick`,
|
|
2181
|
+
});
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
const found = await findBestItem(pick.fullName);
|
|
2185
|
+
if (!found) {
|
|
2186
|
+
// 站点候选池(top30 可装+已验证)与 best(月度策展)是两个集合,交集不保证非空
|
|
2187
|
+
sendJson(res, 200, {
|
|
2188
|
+
ok: true, mode: "local", matched: false, reason: "not_in_best",
|
|
2189
|
+
date: pick.date, fullName: pick.fullName, source: `${SITE}/api/daily-pick`,
|
|
2190
|
+
});
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
const withInstalled = Object.assign({}, found.item, {
|
|
2194
|
+
installed: installedOf(found.item, installedMap()),
|
|
2195
|
+
});
|
|
2196
|
+
sendJson(res, 200, {
|
|
2197
|
+
ok: true, mode: "site", matched: true, cached: !!cached,
|
|
2198
|
+
date: pick.date, fullName: pick.fullName,
|
|
2199
|
+
item: withInstalled, cat: found.cat, sub: found.sub,
|
|
2200
|
+
source: `${SITE}/api/daily-pick`,
|
|
2201
|
+
});
|
|
2202
|
+
} catch (error) {
|
|
2203
|
+
sendJson(res, 200, {
|
|
2204
|
+
ok: true, mode: "local", matched: false, reason: "error",
|
|
2205
|
+
error: String((error && error.message) || error), source: `${SITE}/api/daily-pick`,
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
});
|
|
2209
|
+
|
|
2210
|
+
/* 招商物料转发(2026-11-18,PRD-插件招商广告位)。
|
|
2211
|
+
站点的 /api/plugin-ads 只下发展示字段,插件 UI 不能直接跨域请求站点,故经本机 host 转发。
|
|
2212
|
+
🔴 免发版语义:物料在站点 overrides.json 改完即生效;本路由只缓存 60s,不缓存到自然日。
|
|
2213
|
+
上游失败/形状非法一律返回空数组 —— 插件侧不渲染、不留空角标,绝不把错误伪装成物料。 */
|
|
2214
|
+
registerRoute(ctx, "/api/dpharness/plugin-ads", async (req, res) => {
|
|
2215
|
+
if (req.method !== "GET") {
|
|
2216
|
+
res.writeHead(405, { allow: "GET" });
|
|
2217
|
+
res.end();
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
const now = Date.now();
|
|
2221
|
+
if (pluginAdsCache.value && now - pluginAdsCache.at < PLUGIN_ADS_TTL_MS) {
|
|
2222
|
+
sendJson(res, 200, { ok: true, items: pluginAdsCache.value, cached: true, fetchedAt: pluginAdsCache.at });
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
const controller = new AbortController();
|
|
2226
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
2227
|
+
try {
|
|
2228
|
+
const response = await fetch(PLUGIN_ADS_UPSTREAM, {
|
|
2229
|
+
headers: { accept: "application/json", "user-agent": `dsh-dpharness/${VERSION}` },
|
|
2230
|
+
signal: controller.signal,
|
|
2231
|
+
});
|
|
2232
|
+
if (!response.ok) throw new Error(`upstream HTTP ${response.status}`);
|
|
2233
|
+
const body = await response.json();
|
|
2234
|
+
if (!body || !Array.isArray(body.items)) throw new Error("items missing");
|
|
2235
|
+
// 形状校验:只保留能安全渲染的字段,缺关键字段的物料直接丢弃(不留空角标)
|
|
2236
|
+
const ALLOWED_SLOTS = ["plugin-rail", "plugin-inline", "plugin-footer"];
|
|
2237
|
+
const items = body.items.filter((it) => {
|
|
2238
|
+
if (!it || typeof it !== "object") return false;
|
|
2239
|
+
if (!ALLOWED_SLOTS.includes(it.slot)) return false;
|
|
2240
|
+
if (typeof it.title !== "string" || typeof it.url !== "string" || !it.url) return false;
|
|
2241
|
+
if (it.kind !== "ad" && it.kind !== "own") return false;
|
|
2242
|
+
return true;
|
|
2243
|
+
}).map((it) => ({
|
|
2244
|
+
slot: it.slot,
|
|
2245
|
+
code: typeof it.code === "string" ? it.code : it.slot,
|
|
2246
|
+
id: typeof it.id === "string" ? it.id : "",
|
|
2247
|
+
kind: it.kind,
|
|
2248
|
+
tag: typeof it.tag === "string" ? it.tag : "",
|
|
2249
|
+
brand: typeof it.brand === "string" ? it.brand : "",
|
|
2250
|
+
title: it.title.slice(0, 120),
|
|
2251
|
+
desc: typeof it.desc === "string" ? it.desc.slice(0, 280) : "",
|
|
2252
|
+
points: Array.isArray(it.points) ? it.points.slice(0, 3).filter((p) => typeof p === "string") : [],
|
|
2253
|
+
cta: typeof it.cta === "string" ? it.cta.slice(0, 60) : "",
|
|
2254
|
+
url: it.url.slice(0, 500),
|
|
2255
|
+
external: it.external !== false,
|
|
2256
|
+
}));
|
|
2257
|
+
pluginAdsCache = { at: Date.now(), value: items };
|
|
2258
|
+
sendJson(res, 200, {
|
|
2259
|
+
ok: true, items, cached: false,
|
|
2260
|
+
fetchedAt: pluginAdsCache.at, ts: typeof body.ts === "number" ? body.ts : pluginAdsCache.at,
|
|
2261
|
+
});
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
// 上游故障 ≠ 物料为空,分开给 reason 便于埋点区分;两者都不渲染卡片
|
|
2264
|
+
sendJson(res, 200, {
|
|
2265
|
+
ok: true, items: [], cached: false, reason: "upstream_unavailable",
|
|
2266
|
+
error: String((error && error.message) || error),
|
|
2267
|
+
});
|
|
2268
|
+
} finally {
|
|
2269
|
+
clearTimeout(timer);
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
|
|
2079
2273
|
// 「组合方案套装」:站点 /sets 专区的同源数据(跨插件纵向组合,见 fetchSets 注释)
|
|
2080
2274
|
registerRoute(ctx, "/api/dpharness/sets", async (req, res) => {
|
|
2081
2275
|
if (req.method !== "GET") {
|
|
@@ -2595,6 +2789,8 @@ export function apply(ctx) {
|
|
|
2595
2789
|
routes: [
|
|
2596
2790
|
"/api/dpharness/search",
|
|
2597
2791
|
"/api/dpharness/best",
|
|
2792
|
+
"/api/dpharness/daily-pick",
|
|
2793
|
+
"/api/dpharness/plugin-ads",
|
|
2598
2794
|
"/api/dpharness/sets",
|
|
2599
2795
|
"/api/dpharness/event",
|
|
2600
2796
|
"/api/dpharness/subscribe",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dpharness",
|
|
3
3
|
"icon": "./icon.svg",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Curated dpharness.com plugin catalog inside the DeepSeek Harness Web GUI: a conversation-view tab, a sidebar entry and a dismissible site-wide floating panel, offering a searchable full catalog, a monthly by-category shortlist, a daily pick and an update check (this plugin plus every installed plugin) with a red-dot reminder, with one-click install via dshmarket or the dsh CLI. Includes a settings page (General row + Plugins tab) for the widget visibility, the daily pick, the update check and the opt-out telemetry relay covering the full install funnel.",
|
|
6
6
|
"author": "zhanghao3693 <zhanghao3693@qq.com>",
|
|
7
7
|
"repository": {
|