feat(catalog): 首次扫描中的来源也出现在「来源与目录」,并显示实时进度

用户反馈:加了钉盘来源后「来源与目录」里看不到。根因不是丢数据,而是列表只列"已经有快照"
的来源 —— 首次扫描要几分钟到几十分钟(钉盘空间 2900+ 个文件夹),这段时间页面上什么都没有。

- 新 Store 方法 ListCatalogScanProgress:已启用 + 还没有 catalog head + 有在跑/排队的
  source.catalog.refresh(三条件同时成立)。进度直接取 worker 写在任务载荷里的同一份计数
  (progress/message/scanned_directories/discovered_directories/scanned_files),不另立口径。
- /api/v1/source-catalog/sources 在既有列表后追加这些行(snapshot_status="scanning" +
  scan_progress/scan_message)。走窄接口按需接线:未接线时安静跳过,不会把旧列表弄坏。
- 前端:左列显示「首次扫描中 44%」,选中后是进度面板(百分比 + 进度条 + 当前文案 +
  已发现文件数),并说明"扫完自动出现目录";有来源在扫描时每 3 秒自动刷新列表,
  扫完那一行自动变成「本地只读快照」。扫描中不拉目录节点、也不显示标注/格式入口。
- 解析器保持严格:snapshot_status 只接受 ready/scanning,scanning 必须带 scan_progress,
  否则整包拒绝 —— 不给"假装 0%"的机会。

测试:postgres 集成测试(真库)覆盖四种不该出现的来源(停用、已有快照、任务类型不符、
历史上已完成的那次任务);前端 parser + 渲染各一条;Go 全绿、前端 192 条 + tsc 干净。

面板实测:左列「公司级营销资料管理 · 首次扫描中 44%」,主区「首次扫描中 · 44% /
正在扫描目录:已完成 1540 个文件夹 / 已发现约 4934 份文件」。
This commit is contained in:
姚章浩
2026-10-10 17:04:59 +08:00
parent ed60b20790
commit 1283f65a95
9 changed files with 248 additions and 6 deletions
+37
View File
@@ -617,9 +617,46 @@ func listCatalogSources(w http.ResponseWriter, r *http.Request, store Store) {
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "could not list source catalogs"})
return
}
sources = append(sources, scanningCatalogSources(r.Context(), store)...)
writeJSON(w, http.StatusOK, map[string]any{"data": sources, "summary": map[string]int{"total": len(sources)}})
}
// catalogScanProgressLister 是本路由需要的最小能力面:列出「已登记、还没有快照」的来源的
// 首次扫描进度。真实 Store 实现它;未接线时安静跳过(只是没有"扫描中"那几行,不影响既有列表)。
type catalogScanProgressLister interface {
ListCatalogScanProgress(context.Context) ([]governance.CatalogScanProgress, error)
}
// scanningCatalogSources 把首次扫描中的来源投影成目录列表里的行:新来源不必等快照落地才出现。
func scanningCatalogSources(ctx context.Context, store Store) []governance.CatalogSource {
lister, ok := store.(catalogScanProgressLister)
if !ok {
return nil
}
progress, err := lister.ListCatalogScanProgress(ctx)
if err != nil {
return nil
}
out := make([]governance.CatalogSource, 0, len(progress))
for _, item := range progress {
out = append(out, governance.CatalogSource{
ConnectionID: item.ConnectionID,
SourceType: item.SourceType,
Name: item.Name,
// 还没有快照:根节点与计数只报"已扫到多少",由前端按"首次扫描中"呈现。
RootNodeID: "",
FolderCount: item.DiscoveredDirectories,
FileCount: item.ScannedFiles,
ObservedAt: item.StartedAt,
SnapshotOnly: true,
SnapshotStatus: "scanning",
ScanProgress: item.Progress,
ScanMessage: item.Message,
})
}
return out
}
func listCatalogNodes(w http.ResponseWriter, r *http.Request, store Store) {
filter := governance.CatalogNodeFilter{ConnectionID: r.URL.Query().Get("connection_id"), ParentNodeID: r.URL.Query().Get("parent_id"), Limit: 50}
if !validCatalogID(filter.ConnectionID) || !validCatalogID(filter.ParentNodeID) {