fix:修复麦麦观察的一些不一致问题(混乱!?

This commit is contained in:
SengokuCola
2026-05-07 21:49:25 +08:00
parent 827cdbd441
commit 9584f13f16
11 changed files with 261 additions and 63 deletions

View File

@@ -19,6 +19,7 @@ import {
cleanupLocalCache,
getLocalCacheStats,
type CacheDirectoryStats,
type LocalCacheCleanupTarget,
type LocalCacheStats,
type LogCleanupTable,
} from '@/lib/system-api'
@@ -60,9 +61,12 @@ function DirectoryCard({
}: {
item: CacheDirectoryStats
cleanupDisabled: boolean
onCleanup: (target: 'images' | 'emoji') => void
onCleanup: (target: 'images' | 'emoji' | 'log_files') => void
}) {
const cleanupTarget = item.key === 'images' ? 'images' : item.key === 'emoji' ? 'emoji' : null
const cleanupTarget = item.key === 'images' ? 'images' : item.key === 'emoji' ? 'emoji' : item.key === 'logs' ? 'log_files' : null
const cleanupDescription = cleanupTarget === 'log_files'
? '这会删除 logs 目录中的日志文件。操作不可撤销。'
: '这会删除对应目录中的文件,并移除数据库里的相关记录。操作不可撤销。'
return (
<div className="rounded-lg border bg-card p-4">
@@ -86,7 +90,7 @@ function DirectoryCard({
<AlertDialogHeader>
<AlertDialogTitle>{item.label}</AlertDialogTitle>
<AlertDialogDescription>
{cleanupDescription}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -124,7 +128,7 @@ export function LocalCacheTab() {
const { toast } = useToast()
const [stats, setStats] = useState<LocalCacheStats | null>(null)
const [isLoading, setIsLoading] = useState(false)
const [cleanupTarget, setCleanupTarget] = useState<string | null>(null)
const [cleanupTarget, setCleanupTarget] = useState<LocalCacheCleanupTarget | null>(null)
const [selectedLogTables, setSelectedLogTables] = useState<LogCleanupTable[]>([])
const tableRows = useMemo(() => {
@@ -152,7 +156,7 @@ export function LocalCacheTab() {
}
}, [toast])
const handleDirectoryCleanup = async (target: 'images' | 'emoji') => {
const handleDirectoryCleanup = async (target: 'images' | 'emoji' | 'log_files') => {
setCleanupTarget(target)
try {
const result = await cleanupLocalCache(target)
@@ -173,18 +177,18 @@ export function LocalCacheTab() {
}
const handleLogCleanup = async () => {
setCleanupTarget('logs')
setCleanupTarget('database_logs')
try {
const result = await cleanupLocalCache('logs', selectedLogTables)
const result = await cleanupLocalCache('database_logs', selectedLogTables)
setSelectedLogTables([])
await refreshStats()
toast({
title: result.message,
description: `已清理 ${result.removed_records}日志记录。`,
description: `已清理 ${result.removed_records}数据库记录。`,
})
} catch (error) {
toast({
title: '日志清理失败',
title: '数据库清理失败',
description: error instanceof Error ? error.message : '请稍后重试',
variant: 'destructive',
})
@@ -242,22 +246,22 @@ export function LocalCacheTab() {
<div>
<h3 className="flex items-center gap-2 text-base font-semibold sm:text-lg">
<Database className="h-5 w-5" />
</h3>
<p className="mt-1 text-xs text-muted-foreground sm:text-sm">
</p>
</div>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline" className="gap-2" disabled={cleanupTarget !== null || isLoading}>
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
{formatBytes(stats?.database.total_size ?? 0)}
</AlertDialogDescription>