feat: 初始化慧遇书院官网一期
This commit is contained in:
24
server/utils/audit.ts
Normal file
24
server/utils/audit.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { useDatabase } from './db'
|
||||
|
||||
export function writeAuditLog(event: H3Event, input: {
|
||||
operatorId?: number
|
||||
action: string
|
||||
entityType: string
|
||||
entityKey?: string
|
||||
metadata?: Record<string, unknown>
|
||||
}) {
|
||||
const db = useDatabase()
|
||||
db.prepare(`
|
||||
INSERT INTO audit_logs (operator_id, action, entity_type, entity_key, ip_address, metadata_json, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
input.operatorId ?? null,
|
||||
input.action,
|
||||
input.entityType,
|
||||
input.entityKey ?? null,
|
||||
getRequestIP(event, { xForwardedFor: true }) ?? null,
|
||||
JSON.stringify(input.metadata ?? {}),
|
||||
new Date().toISOString(),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user