import { useState } from 'react' import type { LibrarySnapshot } from './librarySnapshots' export async function associateLegacySource(scope: string, snapshotID: string): Promise { 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 | 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 }) { 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 (
关联旧封存的原始来源证据(管理员)

只追加治理关联,保留原快照与摘要。服务端核对原捕获响应、执行器指纹及清单;备份、来源不符或证据缺失均拒绝,不凭同一范围认领。

{notice ?

{notice}

: null}
) }