import { prisma } from "@/lib/db"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Package, Download, FileUp, Eye, Users, TrendingUp, Monitor, Wifi } from "lucide-react"; export const dynamic = "force-dynamic"; function getLast7Days() { const days: string[] = []; for (let i = 6; i >= 0; i--) { const d = new Date(); d.setDate(d.getDate() - i); days.push(d.toISOString().slice(0, 10)); } return days; } export default async function DashboardPage() { const today = new Date().toISOString().slice(0, 10); const days = getLast7Days(); const onlineThreshold = new Date(Date.now() - 3 * 60 * 1000); const [ addonCount, totalDownloads, releaseCount, recentReleases, todayPV, totalPV, todayUV, pvByDay, launcherDownloads, launcherUpdateDownloads, onlineCount, ] = await Promise.all([ prisma.addon.count(), prisma.addon.aggregate({ _sum: { totalDownloads: true } }), prisma.release.count(), prisma.release.findMany({ take: 5, orderBy: { createdAt: "desc" }, include: { addon: { select: { name: true } } }, }), prisma.pageView.count({ where: { date: today } }), prisma.pageView.count(), prisma.pageView.groupBy({ by: ["ip"], where: { date: today, ip: { not: "" } }, }).then((r) => r.length), prisma.pageView.groupBy({ by: ["date"], where: { date: { in: days } }, _count: true, orderBy: { date: "asc" }, }), prisma.softwareVersion.aggregate({ _sum: { downloadCount: true } }), prisma.softwareVersion.aggregate({ _sum: { launcherDownloadCount: true } }), prisma.launcherOnline.count({ where: { lastSeen: { gte: onlineThreshold } } }), ]); const pvMap = new Map(pvByDay.map((d) => [d.date, d._count])); const chartData = days.map((d) => ({ date: d.slice(5), pv: pvMap.get(d) || 0, })); const maxPV = Math.max(...chartData.map((d) => d.pv), 1); const totalSwDownloads = launcherDownloads._sum.downloadCount || 0; const totalLauncherUpdates = launcherUpdateDownloads._sum.launcherDownloadCount || 0; const webDownloads = totalSwDownloads - totalLauncherUpdates; const stats = [ { title: "插件总数", value: addonCount, icon: Package }, { title: "插件总下载量", value: totalDownloads._sum.totalDownloads || 0, icon: Download }, { title: "版本发布数", value: releaseCount, icon: FileUp }, { title: "启动器下载量 (网页)", value: webDownloads, icon: Monitor }, { title: "启动器更新量 (客户端)", value: totalLauncherUpdates, icon: Download }, { title: "启动器在线人数", value: onlineCount, icon: Wifi }, { title: "今日访问 (PV)", value: todayPV, icon: Eye }, { title: "今日独立访客 (UV)", value: todayUV, icon: Users }, { title: "累计访问量", value: totalPV, icon: TrendingUp }, ]; return (

仪表盘

{stats.map((stat) => ( {stat.title}
{stat.value.toLocaleString()}
))}
{/* 7-day PV chart */} 近 7 天访问趋势 页面浏览量 (PV)
{chartData.map((d) => (
{d.pv}
{d.date}
))}
最近发布 最近发布的版本更新 {recentReleases.length === 0 ? (

暂无发布记录

) : (
{recentReleases.map((release) => (

{release.addon.name}

v{release.version} {release.gameVersion && ` · WoW ${release.gameVersion}`}

{release.downloadCount} 次下载

{new Date(release.createdAt).toLocaleDateString("zh-CN")}

))}
)}
); }