import { NextResponse } from "next/server"; import { auth } from "@/app/(auth)/auth"; import { checkUserImageQuota } from "@/lib/db/queries"; export async function GET() { try { const session = await auth(); if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const quota = await checkUserImageQuota(session.user.id); return NextResponse.json({ used: quota.used, limit: quota.limit, remaining: quota.remaining, unlimited: quota.limit === null, // 计算百分比(用于进度条显示) percentage: quota.limit ? Math.round((quota.used / quota.limit) * 100) : 0, }); } catch (error) { console.error("[User Image Quota API] Error:", error); return NextResponse.json( { error: "Failed to fetch quota" }, { status: 500 } ); } }