@@ -0,0 +1,48 @@
|
||||
export type SourceAuditItem = {
|
||||
id: string
|
||||
connection_id: string
|
||||
source_name: string
|
||||
action: string
|
||||
actor: string
|
||||
created_at: string
|
||||
detail: string
|
||||
}
|
||||
export type SourceAuditPage = { items: SourceAuditItem[]; total: number; limit: number; offset: number }
|
||||
export async function fetchSourceAudit(offset = 0, signal?: AbortSignal): Promise<SourceAuditPage> {
|
||||
const response = await fetch(`/api/v1/source-connections/audit?limit=100&offset=${offset}`, {
|
||||
signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
if (!response.ok) throw new Error('无法读取数据源操作记录,请重试')
|
||||
const { data } = await response.json()
|
||||
if (
|
||||
!data ||
|
||||
!Array.isArray(data.items) ||
|
||||
!Number.isInteger(data.total) ||
|
||||
data.total < 0 ||
|
||||
data.offset !== offset ||
|
||||
!Number.isInteger(data.limit) ||
|
||||
data.limit < 1
|
||||
)
|
||||
throw new Error('数据源操作记录格式无效')
|
||||
for (const item of data.items) {
|
||||
if (
|
||||
!item ||
|
||||
['id', 'connection_id', 'source_name', 'action', 'actor', 'created_at', 'detail'].some(
|
||||
(key) => typeof item[key] !== 'string'
|
||||
) ||
|
||||
!Number.isFinite(Date.parse(item.created_at))
|
||||
)
|
||||
throw new Error('数据源操作记录格式无效')
|
||||
}
|
||||
return data
|
||||
}
|
||||
export const sourceAuditActions: Record<string, string> = {
|
||||
created: '添加连接',
|
||||
settings_updated: '修改配置',
|
||||
paused: '暂停自动刷新',
|
||||
resumed: '恢复自动刷新',
|
||||
archived: '移除连接',
|
||||
restored: '恢复连接',
|
||||
historical_settings: '历史设置记录',
|
||||
}
|
||||
Reference in New Issue
Block a user