portal 搜尋濾殘影(#46 治標)+四件套單測

/portal/data/search 拿到 KBDB 回應後 server-side 過濾 metadata_json.status=
'deprecated' 與 content 以「(舊管線產物」開頭的 entries(metadata parse 失敗
視為保留,不誤殺),count 重算。這是 Arcrun#46 上游修好前的 portal 端治標,
上游清完資料後整段(含 filterDeprecatedEntries)可拔。
單測:sanitizeUploadFilename(路徑穿越/副檔名/長度)、filterDeprecatedEntries
(濾殘影/壞 metadata 保留)、mapGraphWorkflowOutput(#57 輸出映射);
/portal/session 補 upload_enabled=false 斷言。另修 portal-ui 一處註解字樣
(誤用產品名,撞零 Mira 斷言)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BH7LdhuCdVUHfHXbM7N8r5
This commit is contained in:
Claude
2026-07-17 06:28:04 +00:00
parent fde1827928
commit 8accdacc3c
3 changed files with 92 additions and 3 deletions
+37 -1
View File
@@ -94,6 +94,28 @@ function canReadLibrary(userLibraries: string[], library: string): boolean {
return userLibraries.includes('*') || userLibraries.includes(library);
}
/**
* 搜尋殘影過濾(**Arcrun#46 上游修好前的 portal 端治標**——舊管線的 deprecated 產物還躺在
* KBDB 裡污染搜尋結果;根治=上游清資料/重建索引,那修好後這段可整段拔掉)。
* 濾掉:metadata_json.status === 'deprecated' 的 entry、content 以「(舊管線產物」開頭的 entry。
* metadata_json parse 失敗 → 視為保留(治標不誤殺;壞 metadata ≠ deprecated)。
* 純函式(單測用 export)。
*/
export function filterDeprecatedEntries<T extends { metadata_json?: string | null; content?: string | null }>(
entries: T[],
): T[] {
return entries.filter((e) => {
try {
const meta = JSON.parse(e.metadata_json ?? 'null') as { status?: unknown } | null;
if (meta && meta.status === 'deprecated') return false;
} catch {
/* parse 失敗 → 保留 */
}
if (String(e.content ?? '').startsWith('(舊管線產物')) return false;
return true;
});
}
// GET /portal/data/search?q=&mode=&entry_type=&limit= — 三模式中的 keyword/semantic
//graph 走 /portal/data/graph/*)。server 注入 owner_idlibrary;回應照 KBDB 原形
//entries 含 metadata_json,前端自取 source 溯源;mode/capability_hint 誠實透傳——
@@ -122,7 +144,21 @@ portalDataRouter.get('/portal/data/search', (c) =>
if (limit && /^\d{1,3}$/.test(limit)) params.set('limit', limit);
const res = await kbdbFetch(c.env, `/entries/search?${params.toString()}`);
return new Response(res.body, { status: res.status, headers: { 'Content-Type': 'application/json' } });
if (!res.ok) {
// 錯誤回應照原樣透傳(誠實,不加工)
return new Response(res.body, { status: res.status, headers: { 'Content-Type': 'application/json' } });
}
// Arcrun#46 治標:server-side 濾掉舊管線 deprecated 殘影再回(count 重算)。
// 上游修好(清資料/重建索引)後,這段連同 filterDeprecatedEntries 一起拔掉。
const body = (await res.json().catch(() => null)) as
| { entries?: { metadata_json?: string | null; content?: string | null }[]; count?: number }
| null;
if (!body || !Array.isArray(body.entries)) {
// 回應不是預期形狀 → 照原樣回(不因治標把正常錯誤形狀吃掉)
return c.json(body ?? { error: 'KBDB 回應不是 JSON' }, body ? 200 : 502);
}
const entries = filterDeprecatedEntries(body.entries);
return c.json({ ...body, entries, count: entries.length });
}),
);
+1 -1
View File
@@ -554,7 +554,7 @@ function renderPortalHtml(brand: string): string {
$('side-foot').innerHTML = esc(p.display_name || '') + '<br>' + esc(location.host);
$('nav-workflows').classList.toggle('hide', !p.workflows_visible);
$('tab-workflows').classList.toggle('hide', !p.workflows_visible);
// 上傳 nav:一般用戶可見,但只在實例啟用上傳(bindings 齊全)時顯示(Mira 零影響)
// 上傳 nav:一般用戶可見,但只在實例啟用上傳(bindings 齊全)時顯示(未啟用的實例零影響)
$('nav-upload').classList.toggle('hide', !p.upload_enabled);
$('tab-upload').classList.toggle('hide', !p.upload_enabled);
$('nav-admin').classList.toggle('hide', p.role !== 'admin');