mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
- Fix type confusion vulnerability in comment content updates - Validate pagination offsets to prevent negative values - Validate timestamp is a valid number before parsing - Exclude guestEmail from comment API responses for privacy - Fix TypeScript error in audio upload route - Add image attachment support for comments with upload API - Update admin dashboard to track image attachments - Rename cleanup functions to handle both voice and image media
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { db } from '@/lib/db';
|
|
import { auth } from '@/lib/auth';
|
|
import { getCachedTotalStorage } from '@/lib/admin-stats';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const session = await auth();
|
|
if (!session?.user?.isAdmin) {
|
|
return new NextResponse('Unauthorized', { status: 403 });
|
|
}
|
|
|
|
// 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 NextResponse.json({
|
|
totalUsers,
|
|
totalProjects,
|
|
totalVideos,
|
|
totalComments,
|
|
totalVoiceComments,
|
|
totalImageComments,
|
|
totalStorageBytes,
|
|
});
|
|
} catch (error) {
|
|
console.error('[ADMIN_STATS_GET]', error);
|
|
return new NextResponse('Internal Error', { status: 500 });
|
|
}
|
|
}
|