@befe/vault-system 0.1.8 → 0.1.9
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/INSTALL.md +1 -1
- package/package.json +1 -1
- package/src/core/points-search.ts +126 -81
- package/src/server/app.ts +23 -30
- package/web/dist/assets/{abnfDiagram-WEYOIA3C-Clrrz6aO.js → abnfDiagram-WEYOIA3C-BXPPleTe.js} +1 -1
- package/web/dist/assets/{arc-BTwSwHaO.js → arc-HoNJREB3.js} +1 -1
- package/web/dist/assets/{architectureDiagram-ZHVYKT53-Cc2t0GuJ.js → architectureDiagram-ZHVYKT53-CzMnx_bm.js} +1 -1
- package/web/dist/assets/{blockDiagram-RJAE7QA3-CNbK1ZgZ.js → blockDiagram-RJAE7QA3-DfEdouDo.js} +1 -1
- package/web/dist/assets/{c4Diagram-XDPPPE54-Cyf0T8lC.js → c4Diagram-XDPPPE54-B3VtXWpx.js} +1 -1
- package/web/dist/assets/channel-I80V3bYi.js +1 -0
- package/web/dist/assets/{chunk-2E7WHVMD-cO1HGtgb.js → chunk-2E7WHVMD-0rpwX68B.js} +1 -1
- package/web/dist/assets/{chunk-2Q5K7J3B-heFuFebF.js → chunk-2Q5K7J3B-DdN098jO.js} +1 -1
- package/web/dist/assets/{chunk-4EMNKR2T-BtTSTbx1.js → chunk-4EMNKR2T-CLHTeDV1.js} +1 -1
- package/web/dist/assets/{chunk-55XCU76K-CsuzGVuA.js → chunk-55XCU76K-DTgiCUJ7.js} +1 -1
- package/web/dist/assets/{chunk-5VM5RSS4-CHkUK7Na.js → chunk-5VM5RSS4-Dqu6qQpy.js} +1 -1
- package/web/dist/assets/{chunk-JWPE2WC7-BcdRnDBp.js → chunk-JWPE2WC7-DtMyCK8M.js} +1 -1
- package/web/dist/assets/{chunk-VQ5W62QI-Dm-aVCex.js → chunk-VQ5W62QI-C0G_rmch.js} +1 -1
- package/web/dist/assets/{chunk-XXDRQBXY-DvFdV7cE.js → chunk-XXDRQBXY-C7Pbaft0.js} +1 -1
- package/web/dist/assets/{chunk-ZCHMQSOR-_GMZJOh2.js → chunk-ZCHMQSOR-D9XieFZk.js} +2 -2
- package/web/dist/assets/{classDiagram-v2-4MYWR3UA-Dyu-f5sY.js → classDiagram-v2-4MYWR3UA-CgQPweeb.js} +1 -1
- package/web/dist/assets/{cose-bilkent-JH36ORCC-Dc00FcYn.js → cose-bilkent-JH36ORCC-Dj8WpPAy.js} +1 -1
- package/web/dist/assets/{cynefin-EF2NZ3EQ-CGRcYY9z.js → cynefin-EF2NZ3EQ-Bo3yzOy7.js} +1 -1
- package/web/dist/assets/{cynefinDiagram-WF24UDRP-CaQ8qEG7.js → cynefinDiagram-WF24UDRP-CxwvvGmh.js} +1 -1
- package/web/dist/assets/{dagre-NK4GIZVX-BJ3S0JEO.js → dagre-NK4GIZVX-CuoWSBaY.js} +1 -1
- package/web/dist/assets/{diagram-CBK3MWTC-DFwGBHGn.js → diagram-CBK3MWTC-ConCszDY.js} +1 -1
- package/web/dist/assets/{diagram-I5XIIV2D-pcKmZ9Kk.js → diagram-I5XIIV2D-CI_kjLq8.js} +1 -1
- package/web/dist/assets/{diagram-ODIL2UCW-D6oJ8t6N.js → diagram-ODIL2UCW-CEcoQOYd.js} +1 -1
- package/web/dist/assets/{diagram-PFBEJUXE-ypywCTOp.js → diagram-PFBEJUXE-BJrPgyCv.js} +1 -1
- package/web/dist/assets/{diagram-RJA3I4VV-BorkY5MS.js → diagram-RJA3I4VV-BZVjaKHQ.js} +1 -1
- package/web/dist/assets/{diagram-TYUNFSNR-T7Bwi21B.js → diagram-TYUNFSNR-BfsISi7f.js} +1 -1
- package/web/dist/assets/{ebnfDiagram-V4P3TTPT-CW3R519W.js → ebnfDiagram-V4P3TTPT-DWfk6l5m.js} +1 -1
- package/web/dist/assets/{elk-QONTBCTQ-BdiasG_x.js → elk-QONTBCTQ-p3AY-e_h.js} +1 -1
- package/web/dist/assets/{erDiagram-KYQIGQAA-CH9y_Q7o.js → erDiagram-KYQIGQAA-Czz3r3ev.js} +1 -1
- package/web/dist/assets/{flowDiagram-IUGLLWBU-6vX12g0V.js → flowDiagram-IUGLLWBU-BFQRe9M_.js} +1 -1
- package/web/dist/assets/{ganttDiagram-R7GPNTJY-Ca9Z5SFi.js → ganttDiagram-R7GPNTJY-YJtpGx6P.js} +1 -1
- package/web/dist/assets/{gitGraphDiagram-PDYL7XHY-DtD9IOhj.js → gitGraphDiagram-PDYL7XHY-wx70K_3o.js} +1 -1
- package/web/dist/assets/index-P7tQdfR2.js +72 -0
- package/web/dist/assets/index-q9CZUHXc.css +1 -0
- package/web/dist/assets/{infoDiagram-MVDRKAX5-BttRtmtq.js → infoDiagram-MVDRKAX5-BCBkjZk6.js} +1 -1
- package/web/dist/assets/{ishikawaDiagram-HPEHV2GE-BuGLCWo1.js → ishikawaDiagram-HPEHV2GE-DwPgVGLb.js} +1 -1
- package/web/dist/assets/{journeyDiagram-BOSHW7O7-DLtiEu9c.js → journeyDiagram-BOSHW7O7-C0ITkHQ8.js} +1 -1
- package/web/dist/assets/{kanban-definition-FNSA4HC5-CQGtMsyR.js → kanban-definition-FNSA4HC5-BgrezEqk.js} +1 -1
- package/web/dist/assets/{linear-BO_V_WOi.js → linear-cNx-nJKk.js} +1 -1
- package/web/dist/assets/{mermaid.core-BrDOEsu6.js → mermaid.core-C9W9pVWO.js} +4 -4
- package/web/dist/assets/{mindmap-definition-6OY57UG3-_GFTucKM.js → mindmap-definition-6OY57UG3-CnKhqNz4.js} +1 -1
- package/web/dist/assets/{pegDiagram-ECIUJNBX-DfYCgLb5.js → pegDiagram-ECIUJNBX-BSAAJqxB.js} +1 -1
- package/web/dist/assets/{pieDiagram-GNMPY74T-BB9oPfj7.js → pieDiagram-GNMPY74T-Cr3ddn58.js} +1 -1
- package/web/dist/assets/{quadrantDiagram-D57K4MC3-GT0rwvgr.js → quadrantDiagram-D57K4MC3-D0tM8Eya.js} +1 -1
- package/web/dist/assets/{railroadDiagram-Y72NRBL7-DzFREWND.js → railroadDiagram-Y72NRBL7-DMvKr9yz.js} +1 -1
- package/web/dist/assets/{requirementDiagram-EQYSW5RA-Co1D_k0J.js → requirementDiagram-EQYSW5RA-BT-oFZ-T.js} +1 -1
- package/web/dist/assets/{sankeyDiagram-SY24JHO5-BSVsJWqK.js → sankeyDiagram-SY24JHO5-B0IAUO2H.js} +1 -1
- package/web/dist/assets/{sequenceDiagram-BLEHNHQU-20qZx9Pi.js → sequenceDiagram-BLEHNHQU-BlaVWoOF.js} +1 -1
- package/web/dist/assets/{sizeCapture-INFHLROL-BnQdq-uZ.js → sizeCapture-INFHLROL-C2y3i_R-.js} +1 -1
- package/web/dist/assets/{stateDiagram-v2-A6IESKWZ-BE5XhAjE.js → stateDiagram-v2-A6IESKWZ-DTidoXR1.js} +1 -1
- package/web/dist/assets/{swimlanes-B3ENRKFQ-icvIkwDn.js → swimlanes-B3ENRKFQ-CYbomg8a.js} +1 -1
- package/web/dist/assets/swimlanesDiagram-AYQRV4AK-C5BezPoe.js +8 -0
- package/web/dist/assets/{timeline-definition-JXYKGLGB-96dGf2vq.js → timeline-definition-JXYKGLGB-Dt-UlXrO.js} +1 -1
- package/web/dist/assets/{usecaseDiagram-WPOLBNNX-CFXSct0C.js → usecaseDiagram-WPOLBNNX-DBDYiXOS.js} +1 -1
- package/web/dist/assets/{vennDiagram-Q3Y3IDCW-D_03GSvC.js → vennDiagram-Q3Y3IDCW-B3s3QFHf.js} +1 -1
- package/web/dist/assets/{wardleyDiagram-IVAIDKWA-vOd1Jr4V.js → wardleyDiagram-IVAIDKWA-B-7RwGMN.js} +1 -1
- package/web/dist/assets/{xychartDiagram-4URNHDU4-hGZ69wh6.js → xychartDiagram-4URNHDU4-C6R5To8o.js} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/channel-DUo0Wm1H.js +0 -1
- package/web/dist/assets/index-MjsRRm95.css +0 -1
- package/web/dist/assets/index-eTYW5dTL.js +0 -72
- package/web/dist/assets/swimlanesDiagram-AYQRV4AK-lOuiHvx1.js +0 -8
package/INSTALL.md
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* points-search.ts — ⌘K
|
|
2
|
+
* points-search.ts — ⌘K 搜索的匹配逻辑(纯函数,无 IO,供 /points 路由与单测共用)。
|
|
3
3
|
*
|
|
4
|
-
* 口径(
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
4
|
+
* 口径(261027 拍板,见 ref#question_搜索两种输入.261027_xehjx_ctag.):
|
|
5
|
+
* - 不按输入形状分流:无论输入什么,都同时拿去匹配两类内容源,各出一组,没命中的组不出现。
|
|
6
|
+
* - ctag 组:只匹配 key(`YYMMDD_5位hash`);输入是完整 ctag / 裸 key 时按 key 精确匹配。
|
|
7
|
+
* 信息点的 descr 与定义文件路径不参与匹配(descr 匹配自由文本范围太广)。
|
|
8
|
+
* - 话题组:只匹配话题的标题(目录 descr 与 `_index.md` 首个标题)、标签、描述(summary)。
|
|
9
|
+
* - 多个词(空白或 `.` 分隔)要全部命中;每个词在话题的任一字段里命中即可。
|
|
10
|
+
* - 话题组按轻量打分排序(字段权重 × 位置权重),同分按 key 倒序(新的在前)。
|
|
11
|
+
* - 空输入:只出话题组,列最近的话题。
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
/** 一条信息点的搜索行(由索引点精简而来) */
|
|
@@ -17,33 +20,50 @@ export interface PointRow {
|
|
|
17
20
|
defFile: string;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
/** 一个话题(vault)的搜索行 */
|
|
24
|
+
export interface TopicRow {
|
|
25
|
+
keyCore: string;
|
|
26
|
+
/** 目录名里的 descr(话题名) */
|
|
27
|
+
descr: string;
|
|
28
|
+
/** `_index.md` 首个标题;没有就是空串 */
|
|
29
|
+
title: string;
|
|
30
|
+
/** 话题目录,相对 $WK */
|
|
31
|
+
path: string;
|
|
32
|
+
summary: string;
|
|
33
|
+
labels: string[];
|
|
34
|
+
}
|
|
21
35
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
export type TopicField = 'title' | 'labels' | 'summary';
|
|
37
|
+
|
|
38
|
+
export interface TopicHit extends TopicRow {
|
|
39
|
+
/** 本次实际命中的字段 */
|
|
40
|
+
fields: TopicField[];
|
|
41
|
+
score: number;
|
|
28
42
|
}
|
|
29
43
|
|
|
30
|
-
export type
|
|
44
|
+
export type SearchGroup =
|
|
45
|
+
| { name: 'ctag'; total: number; items: PointRow[] }
|
|
46
|
+
| { name: 'topic'; total: number; items: TopicHit[] };
|
|
31
47
|
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
groups?: PointGroup[];
|
|
36
|
-
/** 扁平结果(key → descr → 路径顺序,最多 limit 条),给旧调用方用 */
|
|
37
|
-
points: PointRow[];
|
|
48
|
+
export interface SearchResult {
|
|
49
|
+
/** 只含有命中的组;顺序固定 ctag → topic */
|
|
50
|
+
groups: SearchGroup[];
|
|
38
51
|
total: number;
|
|
39
|
-
limit: number;
|
|
40
52
|
perGroup: number;
|
|
41
|
-
|
|
53
|
+
/** 输入为空(只列最近的话题) */
|
|
54
|
+
empty: boolean;
|
|
42
55
|
}
|
|
43
56
|
|
|
57
|
+
/** 字段权重:话题名 > 标签 > 描述 */
|
|
58
|
+
const FIELD_WEIGHT: Record<TopicField, number> = { title: 100, labels: 60, summary: 30 };
|
|
59
|
+
|
|
60
|
+
/** ctag 组里的词至少这么长才按 key 子串匹配,避免 1~2 个字符撞上随机的 hash */
|
|
61
|
+
const MIN_KEY_WORD = 3;
|
|
62
|
+
|
|
63
|
+
const BOUNDARY = /[\s_\-./\\#::,,;;()()[\]【】]/;
|
|
64
|
+
|
|
44
65
|
/**
|
|
45
|
-
* 搜索词归一:去掉 def#/ref# 前缀与 _ctag.
|
|
46
|
-
* 原来长在前端 NavColumn 里,随「只回前 N 条」一起搬到服务端,避免两边口径漂移。
|
|
66
|
+
* 搜索词归一:去掉 def#/ref# 前缀与 _ctag. 尾缀、转小写、按空白与 `.` 拆词。
|
|
47
67
|
*/
|
|
48
68
|
export function normPointQuery(raw: string): string[] {
|
|
49
69
|
const s = raw
|
|
@@ -51,7 +71,7 @@ export function normPointQuery(raw: string): string[] {
|
|
|
51
71
|
.toLowerCase()
|
|
52
72
|
.replace(/^(def|ref)#/, '')
|
|
53
73
|
.replace(/_ctag\.?$/, '');
|
|
54
|
-
return s ? s.split(
|
|
74
|
+
return s ? s.split(/[\s.]+/).filter(Boolean) : [];
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
/** 完整 ctag / 裸 key:可选 def#|ref#、可选 `descr.` 前缀、key = YYMMDD_5位hash、可选 _ctag. 尾巴 */
|
|
@@ -63,69 +83,94 @@ export function extractFullKey(raw: string): string | null {
|
|
|
63
83
|
return m ? m[1] : null;
|
|
64
84
|
}
|
|
65
85
|
|
|
86
|
+
/** 词在文本里的位置权重:整段相等 1 > 前缀 0.85 > 词首(前一个字符是分隔符)0.7 > 其他子串 0.5;没命中 0 */
|
|
87
|
+
export function positionWeight(text: string, word: string): number {
|
|
88
|
+
const t = text.toLowerCase();
|
|
89
|
+
if (!word) return 0;
|
|
90
|
+
if (t === word) return 1;
|
|
91
|
+
const i = t.indexOf(word);
|
|
92
|
+
if (i < 0) return 0;
|
|
93
|
+
if (i === 0) return 0.85;
|
|
94
|
+
return BOUNDARY.test(t[i - 1]) ? 0.7 : 0.5;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface WordScore {
|
|
98
|
+
score: number;
|
|
99
|
+
fields: Set<TopicField>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 一个词对一个话题的得分:各字段里取最高,并记下命中的字段;全不命中得 0 */
|
|
103
|
+
function scoreWord(topic: TopicRow, word: string): WordScore {
|
|
104
|
+
const fields = new Set<TopicField>();
|
|
105
|
+
const titleW = Math.max(positionWeight(topic.descr, word), positionWeight(topic.title, word));
|
|
106
|
+
const labelW = topic.labels.reduce((m, l) => Math.max(m, positionWeight(l, word)), 0);
|
|
107
|
+
const summaryW = positionWeight(topic.summary, word);
|
|
108
|
+
if (titleW > 0) fields.add('title');
|
|
109
|
+
if (labelW > 0) fields.add('labels');
|
|
110
|
+
if (summaryW > 0) fields.add('summary');
|
|
111
|
+
const score = Math.max(titleW * FIELD_WEIGHT.title, labelW * FIELD_WEIGHT.labels, summaryW * FIELD_WEIGHT.summary);
|
|
112
|
+
return { score, fields };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** key 新的在前(key 以 YYMMDD 开头,字符序倒过来就是时间倒序) */
|
|
116
|
+
function byKeyDesc(a: { keyCore: string }, b: { keyCore: string }): number {
|
|
117
|
+
return b.keyCore.localeCompare(a.keyCore);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function searchCtag(points: PointRow[], raw: string, words: string[]): PointRow[] {
|
|
121
|
+
const full = extractFullKey(raw);
|
|
122
|
+
if (full) return points.filter((p) => p.keyCore === full);
|
|
123
|
+
if (!words.length) return [];
|
|
124
|
+
// 只有像 key 的词才去撞 key;带中文、标点或太短的词不参与(自由文本不该命中信息点)
|
|
125
|
+
if (!words.every((w) => w.length >= MIN_KEY_WORD && /^[0-9a-z_]+$/.test(w))) return [];
|
|
126
|
+
const hits = points.filter((p) => words.every((w) => p.keyCore.includes(w)));
|
|
127
|
+
const rank = (p: PointRow): number => (words.some((w) => p.keyCore.startsWith(w)) ? 1 : 0);
|
|
128
|
+
return hits.sort((a, b) => rank(b) - rank(a) || byKeyDesc(a, b));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function searchTopics(topics: TopicRow[], words: string[]): TopicHit[] {
|
|
132
|
+
if (!words.length) {
|
|
133
|
+
return [...topics].sort(byKeyDesc).map((t) => ({ ...t, fields: [], score: 0 }));
|
|
134
|
+
}
|
|
135
|
+
const hits: TopicHit[] = [];
|
|
136
|
+
for (const t of topics) {
|
|
137
|
+
let score = 0;
|
|
138
|
+
const fields = new Set<TopicField>();
|
|
139
|
+
let all = true;
|
|
140
|
+
for (const w of words) {
|
|
141
|
+
const s = scoreWord(t, w);
|
|
142
|
+
if (s.score <= 0) {
|
|
143
|
+
all = false;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
score += s.score;
|
|
147
|
+
s.fields.forEach((f) => fields.add(f));
|
|
148
|
+
}
|
|
149
|
+
if (all) hits.push({ ...t, fields: [...fields], score });
|
|
150
|
+
}
|
|
151
|
+
return hits.sort((a, b) => b.score - a.score || byKeyDesc(a, b));
|
|
152
|
+
}
|
|
153
|
+
|
|
66
154
|
/**
|
|
67
|
-
*
|
|
155
|
+
* 搜索。`points` 是全部信息点,`topics` 是全部话题;两类各自匹配、各自截断到 perGroup 条。
|
|
68
156
|
*/
|
|
69
157
|
export function searchPoints(
|
|
70
|
-
|
|
158
|
+
points: PointRow[],
|
|
159
|
+
topics: TopicRow[],
|
|
71
160
|
rawQuery: string,
|
|
72
|
-
opts: {
|
|
73
|
-
):
|
|
74
|
-
const {
|
|
75
|
-
|
|
76
|
-
// 1) 完整 ctag / 裸 key:只出 key 组,按 key 精确匹配
|
|
77
|
-
const fullKey = extractFullKey(rawQuery);
|
|
78
|
-
if (fullKey) {
|
|
79
|
-
const hits = rows.filter((r) => r.keyCore === fullKey);
|
|
80
|
-
const group: PointGroup = { name: 'key', total: hits.length, points: hits.slice(0, perGroup) };
|
|
81
|
-
return {
|
|
82
|
-
mode: 'key',
|
|
83
|
-
groups: [group],
|
|
84
|
-
points: group.points.slice(0, limit),
|
|
85
|
-
total: group.total,
|
|
86
|
-
limit,
|
|
87
|
-
perGroup,
|
|
88
|
-
truncated: group.total > group.points.length,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 2) 空输入:不分组,原样前 limit 条
|
|
161
|
+
opts: { perGroup: number },
|
|
162
|
+
): SearchResult {
|
|
163
|
+
const { perGroup } = opts;
|
|
93
164
|
const words = normPointQuery(rawQuery);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
limit,
|
|
100
|
-
perGroup,
|
|
101
|
-
truncated: rows.length > limit,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 3) 三个维度各自匹配;一个点只进优先级最高的组
|
|
106
|
-
const hitsBy: Record<PointGroupName, PointRow[]> = { key: [], descr: [], path: [] };
|
|
107
|
-
for (const r of rows) {
|
|
108
|
-
const keyLc = r.keyCore.toLowerCase();
|
|
109
|
-
const descrLc = r.descr.toLowerCase();
|
|
110
|
-
const pathLc = r.defFile.toLowerCase();
|
|
111
|
-
if (words.every((w) => keyLc.includes(w))) hitsBy.key.push(r);
|
|
112
|
-
else if (words.every((w) => descrLc.includes(w))) hitsBy.descr.push(r);
|
|
113
|
-
else if (words.every((w) => pathLc.includes(w))) hitsBy.path.push(r);
|
|
114
|
-
}
|
|
115
|
-
const groups: PointGroup[] = (['key', 'descr', 'path'] as const).map((name) => ({
|
|
116
|
-
name,
|
|
117
|
-
total: hitsBy[name].length,
|
|
118
|
-
points: hitsBy[name].slice(0, perGroup),
|
|
119
|
-
}));
|
|
120
|
-
const total = groups.reduce((n, g) => n + g.total, 0);
|
|
121
|
-
const flat = groups.flatMap((g) => g.points);
|
|
165
|
+
const ctag = searchCtag(points, rawQuery, words);
|
|
166
|
+
const topic = searchTopics(topics, words);
|
|
167
|
+
const groups: SearchGroup[] = [];
|
|
168
|
+
if (ctag.length) groups.push({ name: 'ctag', total: ctag.length, items: ctag.slice(0, perGroup) });
|
|
169
|
+
if (topic.length) groups.push({ name: 'topic', total: topic.length, items: topic.slice(0, perGroup) });
|
|
122
170
|
return {
|
|
123
|
-
mode: 'grouped',
|
|
124
171
|
groups,
|
|
125
|
-
|
|
126
|
-
total,
|
|
127
|
-
limit,
|
|
172
|
+
total: ctag.length + topic.length,
|
|
128
173
|
perGroup,
|
|
129
|
-
|
|
174
|
+
empty: words.length === 0,
|
|
130
175
|
};
|
|
131
176
|
}
|
package/src/server/app.ts
CHANGED
|
@@ -102,13 +102,6 @@ function contentHash(text: string): string {
|
|
|
102
102
|
return createHash('sha1').update(text).digest('hex');
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
/** 请求的 Host 是不是本机回环地址(任意端口);没有 Host 头(非浏览器 / HTTP/1.0)放行。挡 DNS rebinding 对写接口的利用 */
|
|
106
|
-
function isLoopbackHost(host: string | undefined): boolean {
|
|
107
|
-
if (!host) return true;
|
|
108
|
-
const name = host.startsWith('[') ? host.slice(0, host.indexOf(']') + 1) : host.replace(/:\d+$/, '');
|
|
109
|
-
return name === '127.0.0.1' || name === 'localhost' || name === '[::1]';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
105
|
/** 评论接口单文件大小上限(字节),超过不处理 */
|
|
113
106
|
const COMMENT_MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
114
107
|
|
|
@@ -243,25 +236,31 @@ export function createApp(wk: string = resolveWk()) {
|
|
|
243
236
|
return c.json({ ok: true, ...r });
|
|
244
237
|
});
|
|
245
238
|
|
|
246
|
-
//
|
|
247
|
-
//
|
|
239
|
+
// ⌘K 搜索的数据源。匹配口径在 core/points-search.ts:输入同时去匹配两类内容源——
|
|
240
|
+
// ctag(只匹配 key)与话题(标题 / 标签 / 描述),分两组回传,没命中的组不回;每组先回 perGroup 条。
|
|
248
241
|
app.get('/points', (c) => {
|
|
249
242
|
const clampInt = (raw: string | undefined, def: number): number => {
|
|
250
243
|
const n = Number(raw);
|
|
251
244
|
return Number.isFinite(n) && n > 0 ? Math.min(Math.floor(n), 500) : def;
|
|
252
245
|
};
|
|
253
|
-
const limit = clampInt(c.req.query('limit'), 100);
|
|
254
246
|
const perGroup = clampInt(c.req.query('perGroup'), 20);
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
.
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
247
|
+
const idx = getIndex(wk);
|
|
248
|
+
const points = Object.values(idx.points).map((p) => ({
|
|
249
|
+
keyCore: p.keyCore,
|
|
250
|
+
descr: p.descrs[0] ?? '',
|
|
251
|
+
defs: p.defs.length,
|
|
252
|
+
refs: p.refs.length,
|
|
253
|
+
defFile: p.defs[0]?.file ?? '',
|
|
254
|
+
}));
|
|
255
|
+
const topics = idx.vaults.map((v) => ({
|
|
256
|
+
keyCore: v.keyCore,
|
|
257
|
+
descr: v.descr,
|
|
258
|
+
title: v.title ?? '',
|
|
259
|
+
path: v.path,
|
|
260
|
+
summary: v.summary ?? '',
|
|
261
|
+
labels: v.labels ?? [],
|
|
262
|
+
}));
|
|
263
|
+
return c.json({ ok: true, ...searchPoints(points, topics, c.req.query('q') ?? '', { perGroup }) });
|
|
265
264
|
});
|
|
266
265
|
|
|
267
266
|
// 导航树数据源:只列「一层」——不传 path 回所有 root,传了就回该目录的子目录 + 文件。
|
|
@@ -384,16 +383,10 @@ export function createApp(wk: string = resolveWk()) {
|
|
|
384
383
|
),
|
|
385
384
|
(c) => {
|
|
386
385
|
const body = c.req.valid('json');
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
} catch {
|
|
392
|
-
originHost = '?';
|
|
393
|
-
}
|
|
394
|
-
if (!isLoopbackHost(c.req.header('host')) || (originHost !== undefined && !isLoopbackHost(originHost))) {
|
|
395
|
-
return c.json({ ok: false, code: 'bad_host', error: '只接受本机页面发起的写评论请求' }, 403);
|
|
396
|
-
}
|
|
386
|
+
// 这里不校验请求来源(Host / Origin):能连上服务就视为可信,经端口转发、代理访问时也能正常写评论。
|
|
387
|
+
// 取舍(261027 用户拍板,见 ref#question_本机校验去留.261027_8nlxo_ctag.):
|
|
388
|
+
// 以前这里拒绝 Host / Origin 不是回环的请求,用来挡 DNS rebinding;去掉后这一道防护不再存在,
|
|
389
|
+
// 本机浏览器里的其他网页理论上可以借 DNS rebinding 向本服务写评论(要知道端口、路径与文件当前摘要)。
|
|
397
390
|
const rel = safeIndexed(wk, body.path);
|
|
398
391
|
if (!rel || !rel.toLowerCase().endsWith('.md')) {
|
|
399
392
|
return c.json({ ok: false, code: 'bad_path', error: '只能给工作区内的 .md 文件留评论' }, 400);
|
package/web/dist/assets/{abnfDiagram-WEYOIA3C-Clrrz6aO.js → abnfDiagram-WEYOIA3C-BXPPleTe.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as p,r as u,d as a}from"./chunk-2E7WHVMD-
|
|
1
|
+
import{g as p,r as u,d as a}from"./chunk-2E7WHVMD-0rpwX68B.js";import{p as f}from"./chunk-JWPE2WC7-DtMyCK8M.js";import{_ as n,l as o}from"./mermaid.core-C9W9pVWO.js";import{M as c,b as d}from"./cynefin-EF2NZ3EQ-Bo3yzOy7.js";import"./index-P7tQdfR2.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a6 as ln,a7 as an,a8 as G,a9 as j,aa as z,ab as un,ac as g,ad as tn,ae as K,af as _,ag as rn,ah as o,ai as on,aj as sn,ak as fn}from"./mermaid.core-
|
|
1
|
+
import{a6 as ln,a7 as an,a8 as G,a9 as j,aa as z,ab as un,ac as g,ad as tn,ae as K,af as _,ag as rn,ah as o,ai as on,aj as sn,ak as fn}from"./mermaid.core-C9W9pVWO.js";function cn(l){return l.innerRadius}function gn(l){return l.outerRadius}function yn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,E,q,v,A,B,a){var I=E-l,i=q-h,n=B-v,d=a-A,u=d*I-n*i;if(!(u*u<g))return u=(n*(h-A)-d*(l-v))/u,[l+u*I,h+u*i]}function V(l,h,E,q,v,A,B){var a=l-E,I=h-q,i=(B?A:-A)/K(a*a+I*I),n=i*I,d=-i*a,u=l+n,s=h+d,f=E+n,c=q+d,C=(u+f)/2,t=(s+c)/2,m=f-u,y=c-s,R=m*m+y*y,T=v-A,P=u*c-f*s,O=(y<0?-1:1)*K(on(0,T*T*R-P*P)),S=(P*y-m*O)/R,k=(-P*m-y*O)/R,w=(P*y+m*O)/R,p=(-P*m+y*O)/R,x=S-C,e=k-t,r=w-C,F=p-t;return x*x+e*e>r*r+F*F&&(S=w,k=p),{cx:S,cy:k,x01:-n,y01:-d,x11:S*(v/T-1),y11:k*(v/T-1)}}function hn(){var l=cn,h=gn,E=z(0),q=null,v=yn,A=dn,B=mn,a=null,I=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,C=rn(c-f),t=c>f;if(a||(a=n=I()),s<u&&(d=s,s=u,u=d),!(s>g))a.moveTo(0,0);else if(C>tn-g)a.moveTo(s*G(f),s*j(f)),a.arc(0,0,s,f,c,!t),u>g&&(a.moveTo(u*G(c),u*j(c)),a.arc(0,0,u,c,f,t));else{var m=f,y=c,R=f,T=c,P=C,O=C,S=B.apply(this,arguments)/2,k=S>g&&(q?+q.apply(this,arguments):K(u*u+s*s)),w=_(rn(s-u)/2,+E.apply(this,arguments)),p=w,x=w,e,r;if(k>g){var F=sn(k/u*j(S)),L=sn(k/s*j(S));(P-=F*2)>g?(F*=t?1:-1,R+=F,T-=F):(P=0,R=T=(f+c)/2),(O-=L*2)>g?(L*=t?1:-1,m+=L,y-=L):(O=0,m=y=(f+c)/2)}var H=s*G(m),J=s*j(m),M=u*G(T),N=u*j(T);if(w>g){var Q=s*G(y),U=s*j(y),W=u*G(R),X=u*j(R),D;if(C<an)if(D=pn(H,J,W,X,Q,U,M,N)){var Y=H-D[0],Z=J-D[1],$=Q-D[0],b=U-D[1],nn=1/j(fn((Y*$+Z*b)/(K(Y*Y+Z*Z)*K($*$+b*b)))/2),en=K(D[0]*D[0]+D[1]*D[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}O>g?x>g?(e=V(W,X,H,J,s,x,t),r=V(Q,U,M,N,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(H,J),a.arc(0,0,s,m,y,!t)):a.moveTo(H,J),!(u>g)||!(P>g)?a.lineTo(M,N):p>g?(e=V(M,N,Q,U,u,-p,t),r=V(H,J,W,X,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[G(d)*n,j(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:z(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:z(+n),i):h},i.cornerRadius=function(n){return arguments.length?(E=typeof n=="function"?n:z(+n),i):E},i.padRadius=function(n){return arguments.length?(q=n==null?null:typeof n=="function"?n:z(+n),i):q},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:z(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:z(+n),i):A},i.padAngle=function(n){return arguments.length?(B=typeof n=="function"?n:z(+n),i):B},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|