6d92024b63
- 修复API测试认证问题:创建全局认证设置,更新Playwright配置 - 优化回归测试稳定性:增加超时时间到15秒,修复定位器 - 创建Woodpecker CI工作流:CI、部署和质量门禁配置 - 添加Jest配置和测试脚本 - 移除登录页面的默认账号密码显示(安全问题修复)
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { db } from '@/db';
|
|
import { auditLogs } from '@/db/schema';
|
|
import { nanoid } from 'nanoid';
|
|
|
|
export type AuditAction = 'create' | 'update' | 'delete' | 'publish' | 'login' | 'logout' | 'upload';
|
|
|
|
export interface AuditLogData {
|
|
userId?: string;
|
|
action: AuditAction;
|
|
resourceType: string;
|
|
resourceId?: string;
|
|
details?: Record<string, any>;
|
|
ipAddress?: string;
|
|
userAgent?: string;
|
|
}
|
|
|
|
export async function createAuditLog(data: AuditLogData) {
|
|
try {
|
|
await db.insert(auditLogs).values({
|
|
id: nanoid(),
|
|
userId: data.userId || null,
|
|
action: data.action,
|
|
resourceType: data.resourceType,
|
|
resourceId: data.resourceId || null,
|
|
details: data.details || null,
|
|
ipAddress: data.ipAddress || null,
|
|
userAgent: data.userAgent || null,
|
|
timestamp: new Date(),
|
|
});
|
|
} catch (error) {
|
|
console.error('创建审计日志失败:', error);
|
|
}
|
|
}
|
|
|
|
export function getActionLabel(action: AuditAction): string {
|
|
const labels: Record<AuditAction, string> = {
|
|
create: '创建',
|
|
update: '更新',
|
|
delete: '删除',
|
|
publish: '发布',
|
|
login: '登录',
|
|
logout: '登出',
|
|
upload: '上传',
|
|
};
|
|
return labels[action];
|
|
}
|
|
|
|
export function getActionColor(action: AuditAction): string {
|
|
const colors: Record<AuditAction, string> = {
|
|
create: 'bg-green-100 text-green-800',
|
|
update: 'bg-blue-100 text-blue-800',
|
|
delete: 'bg-red-100 text-red-800',
|
|
publish: 'bg-purple-100 text-purple-800',
|
|
login: 'bg-cyan-100 text-cyan-800',
|
|
logout: 'bg-gray-100 text-gray-800',
|
|
upload: 'bg-yellow-100 text-yellow-800',
|
|
};
|
|
return colors[action];
|
|
}
|