feat(admin): add manual R2 stats refresh endpoint/button and share in-memory storage snapshot cache

This commit is contained in:
Yusuf İpek
2026-02-24 17:35:42 +03:00
parent 6a6b48f6a9
commit 6e14d4d19f
4 changed files with 187 additions and 75 deletions
+2
View File
@@ -4,6 +4,7 @@ import { auth } from '@/lib/auth';
import { redirect } from 'next/navigation';
import { getCachedBunnyStorageStats, getCachedTotalStorage } from '@/lib/admin-stats';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { RefreshR2StatsButton } from '@/components/admin/refresh-r2-stats-button';
import { Users, Folder, Video, MessageSquare, Mic, HardDrive, Image as ImageIcon, Film, MessageSquareQuote, Star } from 'lucide-react';
export const metadata: Metadata = {
@@ -79,6 +80,7 @@ export default async function AdminDashboardPage() {
<div className="flex-1 space-y-4 px-4 md:px-8">
<div className="flex items-center justify-between space-y-2">
<h2 className="text-3xl font-bold tracking-tight">Dashboard Overview</h2>
<RefreshR2StatsButton />
</div>
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
<Card>
+22
View File
@@ -0,0 +1,22 @@
import { auth } from '@/lib/auth';
import { apiErrors, successResponse } from '@/lib/api-response';
import { refreshR2StorageSnapshot } from '@/lib/admin-stats';
export async function POST() {
try {
const session = await auth();
if (!session?.user?.isAdmin) {
return apiErrors.forbidden('Admin access required');
}
const refreshedAt = await refreshR2StorageSnapshot();
return successResponse({
ok: true,
refreshedAt,
});
} catch (error) {
console.error('Error refreshing R2 admin stats cache:', error);
return apiErrors.internalError('Failed to refresh R2 stats');
}
}