157af4399f
- 恢复 IPC 类型声明 (src/electron-api.d.ts),修复 31 个 TS2339 错误 - 修复构建断裂:vite.config.ts 改回 electron.vite.config.ts - 修复 2 个 verbatimModuleSyntax type-import 报错 - 修正 .gitignore 构建产物路径 (electron-dist/ -> dist-electron/ + release/) - 清理 55+ 处过时路径注释 - 更新 AGENTS.md 架构文档与 IPC 通道表 - 修正 docs/ROADMAP.md 过时引用
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
// 命令日志记录器
|
|
|
|
export interface CommandEntry {
|
|
id: number
|
|
time: string
|
|
connection: string
|
|
command: string
|
|
duration: number
|
|
isWrite: boolean
|
|
}
|
|
|
|
const MAX_ENTRIES = 5000
|
|
let nextId = 1
|
|
const entries: CommandEntry[] = []
|
|
|
|
const WRITE_COMMANDS = new Set([
|
|
'SET', 'DEL', 'HSET', 'HDEL', 'RPUSH', 'LPUSH', 'LSET', 'LREM',
|
|
'SADD', 'SREM', 'ZADD', 'ZREM', 'XADD', 'XDEL', 'XTRIM',
|
|
'RENAME', 'EXPIRE', 'PERSIST', 'FLUSHDB', 'SELECT',
|
|
'SETEX', 'INCR', 'DECR', 'INCRBY', 'DECRBY', 'APPEND',
|
|
'HMSET', 'HINCRBY', 'HINCRBYFLOAT',
|
|
'LPOP', 'RPOP', 'BLPOP', 'BRPOP',
|
|
'ZINCRBY', 'ZREMRANGEBYRANK', 'ZREMRANGEBYSCORE',
|
|
'UNLINK', 'MOVE', 'RENAMENX',
|
|
])
|
|
|
|
export function log(connection: string, command: string, duration: number): void {
|
|
const isWrite = WRITE_COMMANDS.has(command.split(' ')[0].toUpperCase())
|
|
entries.push({
|
|
id: nextId++,
|
|
time: new Date().toISOString(),
|
|
connection,
|
|
command,
|
|
duration,
|
|
isWrite,
|
|
})
|
|
if (entries.length > MAX_ENTRIES) {
|
|
entries.splice(0, entries.length - MAX_ENTRIES)
|
|
}
|
|
}
|
|
|
|
export function getLog(): CommandEntry[] {
|
|
return entries
|
|
}
|
|
|
|
export function clearLog(): void {
|
|
entries.length = 0
|
|
}
|