// ═══════════════════════════════════════════════════════════════════════════ // REACT API - Send emoji reactions // ═══════════════════════════════════════════════════════════════════════════ // POST /api/react - Send a reaction // GET /api/react?sessionId=xxx - Get current reactions // ═══════════════════════════════════════════════════════════════════════════ import { NextRequest, NextResponse } from 'next/server'; import { sessionManager } from '@/lib/session-manager'; import { ReactionType } from '@/lib/types'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; // Valid reaction emojis const VALID_REACTIONS: ReactionType[] = ['👍', '❤️', '🎉', '😕', '🚀', '👏', '🔥']; // ═══════════════════════════════════════════════════════════════════════════ // GET REACTIONS // ═══════════════════════════════════════════════════════════════════════════ // GET /api/react?sessionId=xxx // Returns current reaction counts for a session // ═══════════════════════════════════════════════════════════════════════════ export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url); const sessionId = searchParams.get('sessionId'); if (!sessionId) { return NextResponse.json({ success: false, error: 'Missing required parameter: sessionId' }, { status: 400 }); } const session = sessionManager.getSession(sessionId); if (!session) { return NextResponse.json({ success: false, error: 'Session not found' }, { status: 404 }); } const reactions = sessionManager.getReactions(sessionId); return NextResponse.json({ success: true, data: { reactions, availableReactions: VALID_REACTIONS } }); } // ═══════════════════════════════════════════════════════════════════════════ // SEND REACTION // ═══════════════════════════════════════════════════════════════════════════ // POST /api/react // Body: { // sessionId: string, // Required: Session ID // emoji: string // Required: Emoji reaction (👍 ❤️ 🎉 😕 🚀 👏 🔥) // } // ═══════════════════════════════════════════════════════════════════════════ export async function POST(request: NextRequest) { try { const body = await request.json(); const { sessionId, emoji } = body; // Validate sessionId if (!sessionId) { return NextResponse.json({ success: false, error: 'Missing required field: sessionId' }, { status: 400 }); } // Validate emoji if (!emoji) { return NextResponse.json({ success: false, error: 'Missing required field: emoji' }, { status: 400 }); } // Check if emoji is valid if (!VALID_REACTIONS.includes(emoji as ReactionType)) { return NextResponse.json({ success: false, error: `Invalid emoji. Valid reactions: ${VALID_REACTIONS.join(' ')}` }, { status: 400 }); } // Check session exists const session = sessionManager.getSession(sessionId); if (!session) { return NextResponse.json({ success: false, error: 'Session not found' }, { status: 404 }); } // Add reaction const reactions = await sessionManager.addReaction(sessionId, emoji as ReactionType); return NextResponse.json({ success: true, data: { emoji, reactions, timestamp: new Date().toISOString() }, message: 'Reaction recorded' }); } catch (error) { return NextResponse.json({ success: false, error: 'Invalid JSON body' }, { status: 400 }); } }