import type { Metadata } from "next"; import { db, users, recipePhotos, recipes, eq, desc, sql, count } from "@epicure/db"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { HardDrive } from "lucide-react"; export const metadata: Metadata = {}; export default async function AdminStoragePage() { const [totalPhotos, recipesWithPhotos, photosByTier, topUsers] = await Promise.all([ db.select({ count: count() }).from(recipePhotos).then((r) => r[0]), db .select({ count: count() }) .from(recipePhotos) .where(eq(recipePhotos.isCover, true)) .then((r) => r[0]), db .select({ tier: users.tier, photoCount: sql`count(${recipePhotos.id})`, }) .from(recipePhotos) .innerJoin(recipes, eq(recipePhotos.recipeId, recipes.id)) .innerJoin(users, eq(recipes.authorId, users.id)) .groupBy(users.tier), db .select({ userId: users.id, name: users.name, email: users.email, tier: users.tier, photoCount: sql`count(${recipePhotos.id})`, }) .from(recipePhotos) .innerJoin(recipes, eq(recipePhotos.recipeId, recipes.id)) .innerJoin(users, eq(recipes.authorId, users.id)) .groupBy(users.id, users.name, users.email, users.tier) .orderBy(desc(sql`count(${recipePhotos.id})`)) .limit(10), ]); const freePhotos = Number(photosByTier.find((r) => r.tier === "free")?.photoCount ?? 0); const proPhotos = Number(photosByTier.find((r) => r.tier === "pro")?.photoCount ?? 0); const teamPhotos = Number(photosByTier.find((r) => r.tier === "team")?.photoCount ?? 0); return (

Storage Usage

Photo storage breakdown by tier and user.

Total Photos
{(totalPhotos?.count ?? 0).toLocaleString()}

{recipesWithPhotos?.count ?? 0} cover photos

Free Tier Photos
{freePhotos.toLocaleString()}
Pro Tier Photos
{proPhotos.toLocaleString()}
Team Tier Photos
{teamPhotos.toLocaleString()}

Top 10 Users by Photo Count

{topUsers.length === 0 ? ( ) : ( topUsers.map((row) => ( )) )}
User Tier Photos
No photos uploaded yet.
{row.name ?? "Unknown"}
{row.email && (
{row.email}
)}
{row.tier ?? "—"} {Number(row.photoCount).toLocaleString()}
); }