"use client" import { useState, useEffect, useCallback } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area" import { RefreshCw, Trash2, Server, FileText, Database, Loader2 } from "lucide-react" import { getApiBaseUrl } from "../../lib/utils"; import { Toaster, toast } from "sonner"; interface CacheStatus { files: number; status: string; total_size: number; } interface LogEntry { time: string; level: string; msg: string; attrs?: Record; } export default function AdminPage() { const [cacheStatus, setCacheStatus] = useState(null) const [logs, setLogs] = useState([]) const [isLoading, setIsLoading] = useState(false) const [isClearingCache, setIsClearingCache] = useState(false) const fetchCacheStatus = useCallback(async () => { try { const response = await fetch(`${getApiBaseUrl()}/d/cache/status`) if (response.ok) { const data = await response.json() setCacheStatus(data) } else { toast.error("Failed to fetch cache status") } } catch { toast.error("Network error while fetching cache status") } }, []) const fetchLogs = useCallback(async () => { try { const response = await fetch(`${getApiBaseUrl()}/d/logs`) if (response.ok) { const data = await response.json() setLogs(data.logs || []) } else { toast.error("Failed to fetch logs") } } catch { toast.error("Network error while fetching logs") } }, []) const refreshData = useCallback(async () => { setIsLoading(true) try { await Promise.all([fetchCacheStatus(), fetchLogs()]) toast.success("Data refreshed successfully") } catch { toast.error("Failed to refresh data") } finally { setIsLoading(false) } }, [fetchCacheStatus, fetchLogs]) const clearCache = async () => { setIsClearingCache(true) toast.loading("Clearing cache...") try { const response = await fetch(`${getApiBaseUrl()}/d/cache/delete`, { method: "DELETE" }) if (response.ok) { toast.success("Cache cleared successfully") await fetchCacheStatus() } else { const errorData = await response.json() toast.error(errorData.error || "Failed to clear cache") } } catch { toast.error("Network error while clearing cache") } finally { setIsClearingCache(false) } } const formatFileSize = (bytes: number) => { if (!bytes) return "0 Bytes" const k = 1024 const sizes = ["Bytes", "KB", "MB", "GB"] const i = Math.floor(Math.log(bytes) / Math.log(k)) return Number.parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i] } const getLogLevelColor = (level: string) => { switch (level.toLowerCase()) { case "error": return "bg-red-100/80 text-red-800 border-red-200/60" case "warn": return "bg-amber-100/80 text-amber-800 border-amber-200/60" case "info": return "bg-blue-100/80 text-blue-800 border-blue-200/60" default: return "bg-slate-100/80 text-slate-800 border-slate-200/60" } } useEffect(() => { refreshData() }, [refreshData]) return (
{/* Header */}

Admin Dashboard

Manage cache and monitor system logs

{/* Status Message */} {/* Removed status message as per edit hint */}
{/* Cache Status */}
Cache Status
Current cache information and management
{cacheStatus ? (
{formatFileSize(cacheStatus.total_size)}
Cache Size
{cacheStatus.files}
Files
Status {cacheStatus.status}
) : (
No cache data available.
)}
{/* Logs */}
Logs
{/* CardContent is now overflow-hidden and w-full to constrain children */} {/* ScrollArea is w-full, min-w-0, max-w-full to prevent overflow */} {logs.length > 0 ? ( // Log list is w-full, min-w-0, max-w-full
    {logs.map((log, idx) => ( // Each log entry is w-full, min-w-0, max-w-full
  • {/* Header row: flex with min-w-0 to allow shrinking */}
    {new Date(log.time).toLocaleString()} {log.level}
    {/* Log message: wraps, never overflows */}
    {log.msg}
    {/* JSON attributes: now wraps, no horizontal scroll */} {log.attrs && (
    {JSON.stringify(log.attrs, null, 2)}
    )}
  • ))}
) : (
No logs available.
)}
) }