issue-ai/src/lib/audit.ts

32 lines
1.1 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.

// issue-ai/src/lib/audit.ts — 站点审计包装器(引用共享库)
import { getDb } from './db'
import { writeAuditLog as sharedWriteAuditLog, diffObjects } from '@shared/lib/audit/write-audit-log'
import type { AuditLogEntry, AuditStore } from '@shared/lib/audit/write-audit-log'
// 创建 issue-ai 的 store 适配器
const store: AuditStore = {
exec: (sql: string) => {
try {
getDb().exec(sql)
} catch (e) {
console.error('审计日志写入失败:', e)
}
},
}
// 保持原有调用方式writeAuditLog(opts) —— 内部调用共享库
export function writeAuditLog(opts: AuditLogEntry): void {
sharedWriteAuditLog(store, opts)
}
// 直接定义 getClientIP避免 Next.js tree-shaking 导致 re-export 丢失
// shared 库的 re-export 在 standalone 构建中可能被优化掉)
export function getClientIP(request: Request): string | null {
const forwarded = request.headers.get('x-forwarded-for')
if (forwarded) return forwarded.split(',')[0].trim()
return request.headers.get('x-real-ip') ?? null
}
// re-export 共享工具函数
export { diffObjects }