mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
code: store,nextjs,log (1 files)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { AuditLog } from './types'
|
||||
|
||||
const DEFAULT_AUDIT_LOG_LIMIT = 100
|
||||
const MAX_AUDIT_LOGS = 1000
|
||||
const auditLogs: AuditLog[] = []
|
||||
|
||||
const normalizeLimit = (limit: number): number => {
|
||||
if (!Number.isFinite(limit)) return DEFAULT_AUDIT_LOG_LIMIT
|
||||
return Math.max(0, Math.floor(limit))
|
||||
}
|
||||
|
||||
export const addAuditLog = (log: AuditLog): void => {
|
||||
auditLogs.push(log)
|
||||
|
||||
if (auditLogs.length > MAX_AUDIT_LOGS) {
|
||||
auditLogs.splice(0, auditLogs.length - MAX_AUDIT_LOGS)
|
||||
}
|
||||
}
|
||||
|
||||
export const listAuditLogs = (limit: number = DEFAULT_AUDIT_LOG_LIMIT): AuditLog[] => {
|
||||
const normalizedLimit = normalizeLimit(limit)
|
||||
if (normalizedLimit === 0) return []
|
||||
|
||||
const slice = auditLogs.slice(-normalizedLimit)
|
||||
return slice.reverse()
|
||||
}
|
||||
|
||||
export const clearAuditLogs = (): void => {
|
||||
auditLogs.length = 0
|
||||
}
|
||||
|
||||
export { DEFAULT_AUDIT_LOG_LIMIT, MAX_AUDIT_LOGS }
|
||||
Reference in New Issue
Block a user