import { useContext, useEffect, useState } from 'react' import { fetchCatalogSources } from './sourceCatalog' import type { CatalogSource } from './sourceCatalog' import { WorkspaceContextTabsSetter } from './workspaceContext' import './sourceLinkManager.css' const typeLabel = { dingtalk: '钉钉知识库', pp: 'PP资料下载中心', alist: 'AList文件源' } const authLabel = { dingtalk: '专用浏览器扫码登录', pp: '公开访问,无需Key', alist: '只读Token' } const actionLabel = { dingtalk: '模拟登录并验证目录', pp: '模拟验证公开目录', alist: '模拟验证只读Token' } const placeholder = { dingtalk: '粘贴钉钉知识库网页链接(模拟)', pp: '粘贴PP资料下载中心链接(模拟)', alist: '例如:https://alist.example.com(模拟)', } const linkLabel = { dingtalk: '知识库链接', pp: '资料中心地址', alist: 'AList站点地址' } interface Props { sources: CatalogSource[] selected: CatalogSource | null validated: boolean loading: boolean error: string | null onSelect: (source: CatalogSource) => void onValidate: () => void onRefresh: () => void } export function SourceLinkManagerView({ sources, selected, validated, loading, error, onSelect, onValidate, onRefresh, }: Props) { const [link, setLink] = useState('') return (

连接配置

来源链接

配置钉钉、PP和AList的入口、认证方式及目录验证。

{error ? (
{error}
) : null}
本地模拟配置 使用真实来源名称和快照数量,但不连接登录服务、不保存真实Key。
{selected ? ( <>

{selected.name}

{typeLabel[selected.source_type]} · 本地只读快照
模拟验证待执行
当前快照 文件 {selected.file_count} 目录 {selected.folder_count} 不下载文件内容,只读取目录和元数据 不执行上传、移动、重命名或删除
{validated ? (
网络连接 模拟通过
登录或Token 模拟通过
根目录 模拟通过
读取第一层目录 模拟通过
只读边界 模拟通过
以上只是本地交互模拟;迁移到测试服务器后才执行真实验证。
) : null}

真实模式下,新凭据先验证,成功后才替换旧凭据;网页永远不能读取已保存Key。

) : loading ? (
正在加载来源…
) : null}
) } export function SourceLinkManager() { const [sources, setSources] = useState([]) const [selected, setSelected] = useState(null) const [validated, setValidated] = useState(false) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [revision, setRevision] = useState(0) const setContextTabs = useContext(WorkspaceContextTabsSetter) useEffect(() => { const controller = new AbortController() setLoading(true) void fetchCatalogSources(controller.signal) .then((result) => { if (!controller.signal.aborted) { setSources(result) setSelected( (current) => (current && result.find((item) => item.connection_id === current.connection_id)) || result[0] || null ) setError(null) } }) .catch((cause) => { if (!controller.signal.aborted) setError(cause instanceof Error ? cause.message : '加载来源链接失败') }) .finally(() => { if (!controller.signal.aborted) setLoading(false) }) return () => controller.abort() }, [revision]) useEffect(() => { setContextTabs(selected ? [{ key: selected.connection_id, label: selected.name, onActivate: () => undefined }] : []) return () => setContextTabs([]) }, [selected, setContextTabs]) return ( { setSelected(source) setValidated(false) }} onValidate={() => setValidated(true)} onRefresh={() => { setValidated(false) setRevision((value) => value + 1) }} /> ) }