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