Files
knowledge-governance/web/src/LegacySourceAssociation.tsx
T
姚章浩 8d838d9cb4
build / build (push) Successful in 1m45s
feat(library): 整库发布身份、写集合与收尾边界
执行时真实时钟与持久授权回读(撤销/过期即停并保留预备份)、写集合写前落盘、
租约与 attempt 身份、恢复队列与原发送身份分离、成功收尾必须释放维护后再登记终态。
2026-11-01 11:35:10 +08:00

84 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react'
import type { LibrarySnapshot } from './librarySnapshots'
export async function associateLegacySource(scope: string, snapshotID: string): Promise<string> {
const response = await fetch('/api/v1/library/source-associations', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({ scope, snapshot_id: snapshotID }),
})
const value = (await response.json().catch(() => null)) as Record<string, unknown> | null
if (!response.ok)
throw new Error(typeof value?.error === 'string' ? value.error : `来源关联失败(HTTP ${response.status})`)
if (
value?.associated !== true ||
value.published !== false ||
value.snapshot_id !== snapshotID ||
typeof value.source_id !== 'string' ||
!/^[a-f0-9]{64}$/.test(value.source_id)
) {
throw new Error('来源关联回执不完整或快照身份不符')
}
return value.source_id
}
export function LegacySourceAssociation({
scope,
snapshots,
admin,
onBound,
}: {
scope: string
snapshots: LibrarySnapshot[]
admin: boolean
onBound: () => Promise<void>
}) {
const [snapshotID, setSnapshotID] = useState('')
const [pending, setPending] = useState(false)
const [notice, setNotice] = useState('')
if (!admin) return null
const choices = snapshots.filter((item) => item.scope === scope)
const bind = async () => {
if (pending || !choices.some((item) => item.snapshot_id === snapshotID)) return
setPending(true)
setNotice('')
try {
const sourceID = await associateLegacySource(scope, snapshotID)
setNotice(`来源证据已核验关联:${sourceID}。没有发布内容;发布授权与写入闸门仍独立检查。`)
await onBound()
} catch (error) {
setNotice(error instanceof Error ? error.message : '来源关联失败')
} finally {
setPending(false)
}
}
return (
<details className="rel-source-identity">
<summary>关联旧封存的原始来源证据(管理员)</summary>
<p>
只追加治理关联,保留原快照与摘要。服务端核对原捕获响应、执行器指纹及清单;备份、来源不符或证据缺失均拒绝,不凭同一范围认领。
</p>
<label>
待核验的历史快照
<select
aria-label="待核验的历史快照"
value={snapshotID}
disabled={pending}
onChange={(event) => setSnapshotID(event.target.value)}
>
<option value="">选择准确快照摘要</option>
{choices.map((item) => (
<option key={item.snapshot_id} value={item.snapshot_id}>
{item.snapshot_id}
</option>
))}
</select>
</label>
<button type="button" disabled={pending || !snapshotID} onClick={() => void bind()}>
{pending ? '核验中…' : '核验原证据并关联'}
</button>
{notice ? <p role="status">{notice}</p> : null}
</details>
)
}