optimized iframe view

This commit is contained in:
2025-03-02 21:43:19 +00:00
parent db195a4ae2
commit 2561446907
21 changed files with 449 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
import { checkAdminAuth } from '@/lib/auth';
import { getAllResponses, getSurveyStats } from '@/lib/survey';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { password } = body;
// Check for admin auth
const isAuthenticated = await checkAdminAuth(password);
if (!isAuthenticated) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
);
}
// Get survey statistics and all responses
const stats = getSurveyStats();
const responses = getAllResponses();
// Filter out responses with comments, but don't include IDs to ensure anonymity
const comments = responses
.filter(response => response.comment && response.comment.trim() !== '')
.map(response => ({
vote: response.vote,
comment: response.comment,
timestamp: response.timestamp
}));
return NextResponse.json({ stats, comments });
} catch (error) {
console.error('Error getting stats:', error);
return NextResponse.json(
{ error: 'Failed to get survey statistics' },
{ status: 500 }
);
}
}