Your Name 3f3eed53be
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
添加每月出图限额功能
2025-12-18 11:08:14 +08:00

32 lines
875 B
TypeScript

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 }
);
}
}