import { Metadata } from 'next'; import { db } from '@/lib/db'; import { auth } from '@/lib/auth'; import { redirect } from 'next/navigation'; import { getCachedTotalStorage } from '@/lib/admin-stats'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Users, Folder, Video, MessageSquare, Mic, HardDrive, Image as ImageIcon } from 'lucide-react'; export const metadata: Metadata = { title: 'Admin Dashboard | OpenFrame', description: 'Admin overview dashboard', }; function formatBytes(bytes: number, decimals = 2) { if (bytes < 0) return 'Error Fetching'; if (!+bytes) return '0 Bytes'; const k = 1024; const dm = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; } export default async function AdminDashboardPage() { const session = await auth(); if (!session?.user?.isAdmin) { redirect('/'); } // 1. Database Stats const [ totalUsers, totalProjects, totalVideos, totalComments, totalVoiceComments, totalImageComments, ] = await Promise.all([ db.user.count(), db.project.count(), db.video.count(), db.comment.count(), db.comment.count({ where: { voiceUrl: { not: null } }, }), db.comment.count({ where: { imageUrl: { not: null } }, }), ]); // 2. Storage Stats (Cached) const totalStorageBytes = await getCachedTotalStorage(); return (
Total active projects on the platform