feat(settings): 数据源配置改成「列出来、勾选、变成来源」,并去掉文件格式筛选
用户对 系统设置 → 数据源配置 的四条要求: ① 这里不要做文件格式筛选(格式归目录级标注决定); ② 列出我账号下能看到的知识库;③ 列出钉盘能看到哪些;④ 勾选那些作为来源。 ① 来源卡片不再渲染 FilenameFilterEditor(目录级筛选仍在「来源与目录」里,按目录就近覆盖)。 ②③ 新端点 GET /api/v1/dingtalk-spaces/available(管理员,只读):用 dws 列举 - 知识库:wiki +space-list --type orgWikiSpace/myWikiSpace(实测 17 + 1 个) - 钉盘:wiki space list --type mySpace/orgSpace(实测 我的文件 + 6 个组织空间) 实测约束写进命令形态:--limit 上限是 50;翻页必须 --page-all(--max-items 兜底), 否则超过一页的知识库会被静默截断(被截断时页面显示"可能不全"而不是假装列全)。 列不出来 ≠ 空列表:dws 未登录/权限不足 → 503 + 原因;某一类失败只丢那一类。 ④ 面板勾选后走既有登记路径(/api/v1/dingtalk-spaces),首次目录扫描自动排队; 已登记的按空间名标「已是来源」并禁用勾选;扫码会话失效时直接弹二维码,扫完自动重试。 基础设施:api 与 worker 共享同一份 dws 状态(bind mount 同一份,refresh token 是轮换制, 不能各留一份)。子进程 HOME 必须指向 DWS_HOME —— 这条是实测踩出来的:漏了会报"未登录", 已有回归测试钉住。dws 子进程沿用白名单环境,库口令等变量不进子进程。 测试:新包 internal/dingtalkdiscovery(fixture 用真实 dws 输出形状):paging 约束、 截断提示、一类失败不连带、全部失败→ErrUnavailable、子进程环境;httpapi 侧 401/501/503/500 与不泄漏内部错误;OpenAPI 契约(400/503 组件)通过。前端 189 条 + tsc 干净。 面板实测:知识库(18)/钉盘(7)都列出来,已有三条钉钉来源自动标「已是来源」; 勾选「视觉文档」→ 加入为来源 → 新来源 sc-8a4be5b8293d1c9a048c3c7e9b194155(dingtalk,enabled) + source.catalog.refresh 已完成。
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { DingtalkSourceDiscovery } from './DingtalkSourceDiscovery'
|
||||
|
||||
describe('DingtalkSourceDiscovery', () => {
|
||||
it('renders the discovery shell without any file-format filter', () => {
|
||||
const html = renderToStaticMarkup(<DingtalkSourceDiscovery registeredNames={['ATOM知识库']} onRegistered={vi.fn()} />)
|
||||
for (const text of ['可加入的来源', '刷新列表', '加入为来源(选中 0)', '已是来源']) {
|
||||
expect(html).toContain(text)
|
||||
}
|
||||
// 需求(2026-10-10):数据源配置这里不再做文件格式筛选——格式归目录级标注决定。
|
||||
for (const removed of ['文件格式筛选', '未勾选的一律不取件', '保存保留格式', '恢复继承上级规则']) {
|
||||
expect(html).not.toContain(removed)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,137 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { DingtalkRequestError, registerDingtalkSpace } from './dingtalkSession'
|
||||
import { DingtalkSessionControl } from './DingtalkSessionControl'
|
||||
import { discoveryCandidates, fetchAvailableDingtalkSources, type AvailableDingtalkSources, type DiscoveryCandidate } from './dingtalkSources'
|
||||
|
||||
// 「系统设置 → 数据源配置」里的数据源发现面板(管理员):
|
||||
// ① 列出当前钉钉账号(dws)能看到的钉钉知识库;
|
||||
// ② 列出钉盘空间(我的文件 / 组织空间);
|
||||
// ③ 勾选后加入为来源(登记走既有路径,首次目录扫描自动排队);
|
||||
// ④ 登记需要有效的钉钉扫码会话:会话失效时直接弹二维码,扫完自动重试本次登记。
|
||||
// 这里不显示文件格式筛选:格式由目录级标注决定,不在这张卡上做。
|
||||
|
||||
export function DingtalkSourceDiscovery({ registeredNames, onRegistered }: { registeredNames: string[]; onRegistered: () => void }) {
|
||||
const [list, setList] = useState<AvailableDingtalkSources | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [loadError, setLoadError] = useState<string | null>(null)
|
||||
const [checked, setChecked] = useState<string[]>([])
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [message, setMessage] = useState<string | null>(null)
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [loginRequired, setLoginRequired] = useState(false)
|
||||
|
||||
const load = useCallback(async (signal?: AbortSignal) => {
|
||||
setLoading(true); setLoadError(null)
|
||||
try {
|
||||
const next = await fetchAvailableDingtalkSources(signal)
|
||||
setList(next)
|
||||
// 已登记的默认不再勾选:避免重复登记。
|
||||
setChecked([])
|
||||
} catch (cause) {
|
||||
if (cause instanceof DOMException && cause.name === 'AbortError') return
|
||||
setLoadError(cause instanceof Error ? cause.message : '列举数据源失败')
|
||||
setList(null)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
void load(controller.signal)
|
||||
return () => controller.abort()
|
||||
}, [load])
|
||||
|
||||
const candidates = discoveryCandidates(list, registeredNames)
|
||||
const knowledgeBases = candidates.filter((item) => item.kind === 'knowledge_base')
|
||||
const driveSpaces = candidates.filter((item) => item.kind === 'drive_space')
|
||||
const selected = candidates.filter((item) => checked.includes(item.key))
|
||||
const toggle = (key: string) => setChecked((current) => current.includes(key) ? current.filter((item) => item !== key) : [...current, key])
|
||||
|
||||
const submit = async (retryAfterLogin = false) => {
|
||||
setBusy(true); setFailure(null); setMessage(null)
|
||||
const added: string[] = []
|
||||
const failed: string[] = []
|
||||
let needLogin = false
|
||||
for (const candidate of selected) {
|
||||
try {
|
||||
const result = await registerDingtalkSpace(candidate.url)
|
||||
added.push(result.name || candidate.name)
|
||||
} catch (cause) {
|
||||
// 扫码会话失效:登记本身没问题,直接弹二维码,扫完自动重试剩下的。
|
||||
if (cause instanceof DingtalkRequestError && cause.code === 'login_required' && !retryAfterLogin) {
|
||||
needLogin = true
|
||||
break
|
||||
}
|
||||
failed.push(`${candidate.name}:${cause instanceof Error ? cause.message : '登记失败'}`)
|
||||
}
|
||||
}
|
||||
setBusy(false)
|
||||
if (needLogin) {
|
||||
setLoginRequired(true)
|
||||
setFailure('钉钉扫码会话已失效:请扫码登录,登录成功后会自动继续这次登记。')
|
||||
return
|
||||
}
|
||||
if (added.length) {
|
||||
setMessage(`已加入 ${added.length} 个来源:${added.join('、')}。首次目录扫描已在后台排队。`)
|
||||
onRegistered()
|
||||
void load()
|
||||
}
|
||||
if (failed.length) setFailure(failed.join(';'))
|
||||
}
|
||||
|
||||
const resumeAfterLogin = () => {
|
||||
setLoginRequired(false)
|
||||
setFailure(null)
|
||||
void submit(true)
|
||||
}
|
||||
|
||||
const renderRow = (candidate: DiscoveryCandidate) => {
|
||||
const already = candidate.alreadyRegistered
|
||||
return <li key={candidate.key} className={already ? 'discovery-row registered' : 'discovery-row'}>
|
||||
<label>
|
||||
<input type="checkbox" aria-label={`选择${candidate.name}`} checked={checked.includes(candidate.key)} disabled={already || busy} onChange={() => toggle(candidate.key)} />
|
||||
<span><strong>{candidate.name}</strong><small>{candidate.detail}</small></span>
|
||||
</label>
|
||||
{already ? <span className="safe-badge">已是来源</span> : null}
|
||||
</li>
|
||||
}
|
||||
|
||||
return <section className="dingtalk-discovery" aria-label="可加入的数据源">
|
||||
<div className="dingtalk-discovery-heading">
|
||||
<div>
|
||||
<strong>可加入的来源</strong>
|
||||
<small>按当前钉钉账号列出能访问的知识库与钉盘空间;勾选后加入为来源,首次目录扫描自动排队。</small>
|
||||
</div>
|
||||
<button type="button" className="secondary" onClick={() => void load()} disabled={loading}>{loading ? '正在列举…' : '刷新列表'}</button>
|
||||
</div>
|
||||
{loadError ? <p className="error-message" role="alert">{loadError}</p> : null}
|
||||
{list ? <div className="dingtalk-discovery-groups">
|
||||
<div className="discovery-group">
|
||||
<h4>知识库({knowledgeBases.length})</h4>
|
||||
{list.knowledge_notice ? <small className="empty-inline">知识库列表可能不全:{list.knowledge_notice}</small> : null}
|
||||
{knowledgeBases.length ? <ul>{knowledgeBases.map(renderRow)}</ul> : <small className="empty-inline">当前账号下没有可访问的知识库。</small>}
|
||||
</div>
|
||||
<div className="discovery-group">
|
||||
<h4>钉盘({driveSpaces.length})</h4>
|
||||
{list.drive_notice ? <small className="empty-inline">钉盘这次列不出来:{list.drive_notice}</small> : null}
|
||||
{!list.drive_notice && !driveSpaces.length ? <small className="empty-inline">当前账号下没有可见的钉盘空间。</small> : null}
|
||||
{driveSpaces.length ? <ul>{driveSpaces.map(renderRow)}</ul> : null}
|
||||
</div>
|
||||
</div> : null}
|
||||
<div className="dingtalk-discovery-actions">
|
||||
<button type="button" disabled={!selected.length || busy} onClick={() => void submit()}>{busy ? '正在加入…' : `加入为来源(选中 ${selected.length})`}</button>
|
||||
<small>勾选的知识库会登记为来源连接;已登记的条目标为「已是来源」,不会重复登记。</small>
|
||||
</div>
|
||||
{message ? <p className="success-message" role="status">{message}</p> : null}
|
||||
{failure ? <p className="error-message" role="alert">{failure}</p> : null}
|
||||
{loginRequired ? <DingtalkSessionControl
|
||||
autoStart
|
||||
hideTrigger
|
||||
space={selected[0]?.url}
|
||||
onSuccess={resumeAfterLogin}
|
||||
onClose={() => setLoginRequired(false)}
|
||||
/> : null}
|
||||
</section>
|
||||
}
|
||||
@@ -29,6 +29,8 @@ describe('SystemSettingsView',()=>{
|
||||
it('separates document-engineer settings from locked administrator and production controls',()=>{
|
||||
const html=renderToStaticMarkup(<SystemSettingsView sources={sources} connections={connections} monitor={monitor} settings={settings} productionEnabled={false} routingCapabilities={{internal_enabled:true,external_enabled:true}} loading={false} saving={false} error={null} saveMessage="刷新与告警参数已验证并启用:文档15秒、资源30秒、停滞30分钟、finalizing 2小时" onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} />)
|
||||
for(const text of ['系统设置','数据源配置','服务配置','存储与备份','刷新策略','设置服务已启用','当前活动版本','公司级技术支持知识库','钉钉知识库','认证方式','端点与凭据','文档工程师可调整','管理员设置已锁定'])expect(html).toContain(text)
|
||||
// 需求(2026-10-10):数据源配置不再做文件格式筛选(格式由目录级标注决定)。
|
||||
for(const removed of ['文件格式筛选','未勾选的一律不取件','保存保留格式','恢复继承上级规则'])expect(html).not.toContain(removed)
|
||||
const servicesHtml=renderToStaticMarkup(<SystemSettingsView sources={sources} connections={connections} monitor={monitor} settings={settings} productionEnabled={false} routingCapabilities={{internal_enabled:true,external_enabled:true}} loading={false} saving={false} error={null} saveMessage={null} onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} initialSection="services" />)
|
||||
for(const text of ['测试 WeKnora','生产 WeKnora','测试地址','生产地址','生产 ID','知识库 ID'])expect(servicesHtml).toContain(text)
|
||||
const storageHtml=renderToStaticMarkup(<SystemSettingsView sources={sources} connections={connections} monitor={monitor} settings={settings} productionEnabled={false} routingCapabilities={{internal_enabled:true,external_enabled:true}} loading={false} saving={false} error={null} saveMessage={null} onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} initialSection="storage" />)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DingtalkSessionControl } from './DingtalkSessionControl'
|
||||
import { RoutingBindingsSection } from './RoutingBindingsSection'
|
||||
import { ProductionBindingsSection } from './ProductionBindingsSection'
|
||||
import { DingtalkSpaceRegistrar } from './DingtalkSpaceRegistrar'
|
||||
import { FilenameFilterEditor } from './FilenameFilterEditor'
|
||||
import { DingtalkSourceDiscovery } from './DingtalkSourceDiscovery'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import { fetchMonitorOverview } from './monitor'
|
||||
import type { MonitorOverview } from './monitor'
|
||||
@@ -164,7 +164,6 @@ function SourceSettingsCard({ connection, onSourcesChanged }: { connection: Sour
|
||||
<button className="danger" disabled={!canApply} onClick={() => setPendingDisable(true)}>停用来源</button></div>
|
||||
: <div className="source-schedule-actions"><button className="secondary" disabled={!canApply} onClick={() => void submit(true)}>保存并启用</button></div>}
|
||||
{connection.source_type === "dingtalk" && isAdmin ? <DingtalkSessionControl /> : null}
|
||||
<FilenameFilterEditor connectionID={connection.id} label="整个来源" onChanged={onSourcesChanged} />
|
||||
<button className="link" onClick={() => void loadHistory()}>{showHistory ? '收起修订历史' : '查看修订历史'}</button>
|
||||
</div>
|
||||
{message ? <p className="success-message" role="status">{message}</p> : null}
|
||||
@@ -237,6 +236,7 @@ export function SystemSettingsView({ sources, connections, monitor, settings, pr
|
||||
<div className="simulation-banner server-settings-banner"><strong>设置服务已启用</strong><span>当前活动版本 · 启用人 {settings.updated_by} · 启用时间 {settings.activated_at ? new Date(settings.activated_at).toLocaleString('zh-CN') : '待激活'};新设置先验证,再原子切换。</span></div>
|
||||
{section === 'sources' ? <section className="settings-panel wide source-settings-panel" id="settings-sources">
|
||||
<div className="settings-section-heading"><div><h2>数据源配置</h2><p>逐来源设置自动刷新周期或保持仅手动;保存会先生成修订、验证后原子启用,旧版本保留用于审计。</p></div>{identity?.role === 'admin' ? <DingtalkSpaceRegistrar onRegistered={onSourcesChanged} /> : null}</div>
|
||||
{identity?.role === 'admin' ? <DingtalkSourceDiscovery registeredNames={connections.map((item) => item.name)} onRegistered={onSourcesChanged} /> : null}
|
||||
{connections.length ? <div className="settings-source-list">
|
||||
{connections.map((connection) => <SourceSettingsCard key={connection.id} connection={connection} onSourcesChanged={onSourcesChanged}/>)}
|
||||
{sources.length ? null : <small className="empty-inline">尚无快照数据;快照将在来源首次刷新完成后出现。</small>}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { discoveryCandidates, driveSpaceURL, fetchAvailableDingtalkSources } from './dingtalkSources'
|
||||
|
||||
const payload = {
|
||||
data: {
|
||||
knowledge_bases: [
|
||||
{ name: 'ATOM知识库', space_id: '9JOGOQneRgkneX4Q', space_type: 'orgWikiSpace', url: 'https://alidocs.dingtalk.com/i/spaces/9JOGOQneRgkneX4Q/overview', description: '' },
|
||||
{ name: '视觉文档', space_id: '9JOGO9EEOMLMWX4Q', space_type: 'orgWikiSpace', url: '', description: '2d/2.5D/3D 视觉' },
|
||||
{ name: '我的文档', space_id: '9JOGOxeo90ybnz4Q', space_type: 'myWikiSpace', url: 'https://alidocs.dingtalk.com/i/spaces/9JOGOxeo90ybnz4Q/overview', description: '' },
|
||||
],
|
||||
drive_spaces: [
|
||||
{ name: '我的文件', space_id: '28122692916', space_type: 'mySpace', root_folder_id: '65Y1OQX0' },
|
||||
{ name: '全员文件夹', space_id: '102571304', space_type: 'orgSpace', root_folder_id: 'g1YGl6Pm' },
|
||||
],
|
||||
knowledge_notice: '',
|
||||
drive_notice: '',
|
||||
fetched_at: '2026-10-10T08:00:00Z',
|
||||
},
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('fetchAvailableDingtalkSources', () => {
|
||||
it('parses knowledge bases and drive spaces', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify(payload), { status: 200 })))
|
||||
const list = await fetchAvailableDingtalkSources()
|
||||
expect(list.knowledge_bases).toHaveLength(3)
|
||||
expect(list.knowledge_bases[1].url).toBe('https://alidocs.dingtalk.com/i/spaces/9JOGO9EEOMLMWX4Q/overview')
|
||||
expect(list.drive_spaces).toHaveLength(2)
|
||||
expect(list.drive_spaces[1].space_type).toBe('orgSpace')
|
||||
expect(list.knowledge_notice).toBe('')
|
||||
expect(list.drive_notice).toBe('')
|
||||
})
|
||||
|
||||
it('explains environment problems instead of pretending the list is empty', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response('{"error":"dingtalk_discovery_unavailable"}', { status: 503 })))
|
||||
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/暂时列不出来/)
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response('{}', { status: 501 })))
|
||||
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/后端未接线/)
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response('{}', { status: 403 })))
|
||||
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/需要管理员身份/)
|
||||
})
|
||||
|
||||
it('carries the drive notice so the page can explain a missing 钉盘 list', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ data: { knowledge_bases: [], drive_spaces: [], drive_notice: 'list orgSpace: permission denied' } }), { status: 200 })))
|
||||
const list = await fetchAvailableDingtalkSources()
|
||||
expect(list.drive_notice).toContain('permission denied')
|
||||
})
|
||||
})
|
||||
|
||||
describe('discoveryCandidates', () => {
|
||||
it('flattens both groups and marks the ones already registered as sources', () => {
|
||||
const candidates = discoveryCandidates(payload.data as never, ['ATOM知识库', ' (空名字) '])
|
||||
expect(candidates.map((item) => item.key)).toEqual([
|
||||
'kb:9JOGOQneRgkneX4Q', 'kb:9JOGO9EEOMLMWX4Q', 'kb:9JOGOxeo90ybnz4Q', 'drive:28122692916', 'drive:102571304',
|
||||
])
|
||||
expect(candidates[0].alreadyRegistered).toBe(true)
|
||||
expect(candidates[1].alreadyRegistered).toBe(false)
|
||||
expect(candidates[0].detail).toBe('钉钉知识库 · 组织知识库')
|
||||
expect(candidates[2].detail).toBe('钉钉知识库 · 我的知识库')
|
||||
expect(candidates[3].detail).toBe('钉盘 · 我的文件')
|
||||
expect(candidates[4].detail).toBe('钉盘 · 组织空间')
|
||||
expect(candidates[4].url).toBe(driveSpaceURL('102571304'))
|
||||
})
|
||||
|
||||
it('returns nothing for an empty list', () => {
|
||||
expect(discoveryCandidates(null, ['X'])).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,105 @@
|
||||
// 「系统设置 → 数据源配置」的数据源发现客户端:列出当前 dws 账号能看到的钉钉知识库与钉盘空间。
|
||||
// 只读;勾选后的登记仍走既有的 /api/v1/dingtalk-spaces(由扫码会话解析空间根目录)。
|
||||
|
||||
export interface AvailableKnowledgeBase {
|
||||
name: string
|
||||
space_id: string
|
||||
space_type?: string
|
||||
url: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export interface AvailableDriveSpace {
|
||||
name: string
|
||||
space_id: string
|
||||
space_type: string
|
||||
root_folder_id?: string
|
||||
}
|
||||
|
||||
export interface AvailableDingtalkSources {
|
||||
knowledge_bases: AvailableKnowledgeBase[]
|
||||
drive_spaces: AvailableDriveSpace[]
|
||||
/** 知识库这一类为什么不全(某类无权限、被上限截断)。 */
|
||||
knowledge_notice?: string
|
||||
/** 钉盘这一类为什么列不出来(租户权限差异)。 */
|
||||
drive_notice?: string
|
||||
fetched_at: string
|
||||
}
|
||||
|
||||
// 钉盘空间的链接形态与知识库一致(空间 id 决定地址),勾选后按同一条登记路径提交。
|
||||
export function driveSpaceURL(spaceID: string): string {
|
||||
return `https://alidocs.dingtalk.com/i/spaces/${spaceID}/overview`
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
}
|
||||
|
||||
export async function fetchAvailableDingtalkSources(signal?: AbortSignal): Promise<AvailableDingtalkSources> {
|
||||
const response = await fetch('/api/v1/dingtalk-spaces/available', { headers: { Accept: 'application/json' }, signal })
|
||||
if (!response.ok) {
|
||||
// 503 是环境问题(dws 未登录/权限不足),501 是后端没接线:都要说清楚"不是没有来源"。
|
||||
if (response.status === 503) throw new Error('暂时列不出来:dws 未登录或缺少租户目录读权限。先刷新钉钉会话,或让管理员检查 dws 凭据。')
|
||||
if (response.status === 501) throw new Error('后端未接线:数据源发现接口不可用。')
|
||||
if (response.status === 401 || response.status === 403) throw new Error('需要管理员身份才能列举数据源。')
|
||||
throw new Error(`列举数据源失败(HTTP ${response.status})`)
|
||||
}
|
||||
const payload = await response.json() as unknown
|
||||
const data = isRecord(payload) && isRecord(payload.data) ? payload.data : {}
|
||||
const knowledgeBases = Array.isArray(data.knowledge_bases) ? data.knowledge_bases : []
|
||||
const driveSpaces = Array.isArray(data.drive_spaces) ? data.drive_spaces : []
|
||||
return {
|
||||
knowledge_bases: knowledgeBases.flatMap((item) => {
|
||||
if (!isRecord(item)) return []
|
||||
const name = typeof item.name === 'string' ? item.name : ''
|
||||
const spaceID = typeof item.space_id === 'string' ? item.space_id : ''
|
||||
const url = typeof item.url === 'string' && item.url ? item.url : driveSpaceURL(spaceID)
|
||||
const spaceType = typeof item.space_type === 'string' ? item.space_type : ''
|
||||
return name && spaceID ? [{ name, space_id: spaceID, space_type: spaceType, url, description: typeof item.description === 'string' ? item.description : '' }] : []
|
||||
}),
|
||||
drive_spaces: driveSpaces.flatMap((item) => {
|
||||
if (!isRecord(item)) return []
|
||||
const name = typeof item.name === 'string' ? item.name : ''
|
||||
const spaceID = typeof item.space_id === 'string' ? item.space_id : ''
|
||||
const spaceType = typeof item.space_type === 'string' ? item.space_type : ''
|
||||
return name && spaceID ? [{ name, space_id: spaceID, space_type: spaceType, root_folder_id: typeof item.root_folder_id === 'string' ? item.root_folder_id : '' }] : []
|
||||
}),
|
||||
knowledge_notice: typeof data.knowledge_notice === 'string' ? data.knowledge_notice : '',
|
||||
drive_notice: typeof data.drive_notice === 'string' ? data.drive_notice : '',
|
||||
fetched_at: typeof data.fetched_at === 'string' ? data.fetched_at : '',
|
||||
}
|
||||
}
|
||||
export interface DiscoveryCandidate {
|
||||
key: string
|
||||
kind: 'knowledge_base' | 'drive_space'
|
||||
name: string
|
||||
spaceID: string
|
||||
url: string
|
||||
detail: string
|
||||
alreadyRegistered: boolean
|
||||
}
|
||||
|
||||
// 把发现结果拍平成可勾选列表:已登记(按空间名比对来源连接名)的条目打标,页面据此禁用勾选,
|
||||
// 避免重复登记。
|
||||
export function discoveryCandidates(list: AvailableDingtalkSources | null, registeredNames: string[]): DiscoveryCandidate[] {
|
||||
const registered = new Set(registeredNames.map((name) => name.trim()).filter(Boolean))
|
||||
const knowledgeBases = (list?.knowledge_bases ?? []).map((item): DiscoveryCandidate => ({
|
||||
key: `kb:${item.space_id}`,
|
||||
kind: 'knowledge_base',
|
||||
name: item.name,
|
||||
spaceID: item.space_id,
|
||||
url: item.url || driveSpaceURL(item.space_id),
|
||||
detail: item.space_type === 'myWikiSpace' ? '钉钉知识库 · 我的知识库' : '钉钉知识库 · 组织知识库',
|
||||
alreadyRegistered: registered.has(item.name.trim()),
|
||||
}))
|
||||
const driveSpaces = (list?.drive_spaces ?? []).map((item): DiscoveryCandidate => ({
|
||||
key: `drive:${item.space_id}`,
|
||||
kind: 'drive_space',
|
||||
name: item.name,
|
||||
spaceID: item.space_id,
|
||||
url: driveSpaceURL(item.space_id),
|
||||
detail: item.space_type === 'mySpace' ? '钉盘 · 我的文件' : '钉盘 · 组织空间',
|
||||
alreadyRegistered: registered.has(item.name.trim()),
|
||||
}))
|
||||
return [...knowledgeBases, ...driveSpaces]
|
||||
}
|
||||
@@ -45,3 +45,20 @@ button.link{background:none;border:none;color:var(--c-run);cursor:pointer;text-d
|
||||
.filename-filter-group>div{display:flex;flex-wrap:wrap;gap:4px}.filename-filter-group button{border:1px solid var(--border-base);background:var(--bg-panel);color:var(--ink-base);border-radius:999px;padding:2px 8px;font-size:10px;font-family:inherit;cursor:pointer}
|
||||
.filename-filter-group button.picked{background:var(--c-run);border-color:var(--c-run);color:var(--bg-panel);font-weight:650}.filename-filter-group button.blocked{color:var(--c-fail)}
|
||||
@media(max-width:900px){.filename-filter-groups{grid-template-columns:1fr 1fr}}
|
||||
|
||||
/* 数据源发现(系统设置 → 数据源配置):列出可勾选为来源的钉钉知识库与钉盘空间。 */
|
||||
.dingtalk-discovery { display: flex; flex-direction: column; gap: 10px; padding: 12px; margin-bottom: 14px; border: 1px solid var(--border, #e3e8ec); border-radius: 10px; background: var(--card, #fff); }
|
||||
.dingtalk-discovery-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
||||
.dingtalk-discovery-heading strong { display: block; font-size: 14px; }
|
||||
.dingtalk-discovery-heading small { display: block; color: var(--muted-foreground, #5b6773); font-size: 12px; }
|
||||
.dingtalk-discovery-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.discovery-group h4 { margin: 0 0 6px; font-size: 13px; }
|
||||
.discovery-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
|
||||
.discovery-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; border-radius: 6px; }
|
||||
.discovery-row:hover { background: var(--accent, #f2f5f8); }
|
||||
.discovery-row label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
|
||||
.discovery-row.registered label { cursor: default; color: var(--muted-foreground, #5b6773); }
|
||||
.discovery-row strong { font-size: 13px; font-weight: 500; }
|
||||
.discovery-row small { display: block; font-size: 11px; color: var(--muted-foreground, #5b6773); }
|
||||
.dingtalk-discovery-actions { display: flex; align-items: center; gap: 10px; }
|
||||
.dingtalk-discovery-actions small { color: var(--muted-foreground, #5b6773); font-size: 12px; }
|
||||
|
||||
Reference in New Issue
Block a user