Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

44 Zeilen
1.5 KiB

  1. import { NextResponse } from 'next/server';
  2. import { revalidatePath } from 'next/cache'; // ADD THIS
  3. import { getPortals, savePortals } from '@/lib/db';
  4. import { isValidHexColor } from '@/lib/sanitize';
  5. import { Portal } from '@/types';
  6. export const dynamic = 'force-dynamic';
  7. export async function GET() {
  8. const portals = await getPortals();
  9. return NextResponse.json(portals[0] || null);
  10. }
  11. export async function POST(request: Request) {
  12. try {
  13. const incomingPortal: Portal = await request.json();
  14. // themeColor goes into a <style dangerouslySetInnerHTML> in PublicGrid,
  15. // so reject anything that is not a strict #RRGGBB.
  16. if (incomingPortal.themeColor !== undefined && !isValidHexColor(incomingPortal.themeColor)) {
  17. return NextResponse.json(
  18. { error: 'Validation failed', errors: [{ field: 'themeColor', message: 'Colore non valido (atteso #RRGGBB)' }] },
  19. { status: 400 }
  20. );
  21. }
  22. const portals = await getPortals();
  23. if (portals.length > 0) {
  24. portals[0] = { ...portals[0], ...incomingPortal };
  25. } else {
  26. portals.push({ ...incomingPortal, id: 'default-portal', tenantId: 'default' });
  27. }
  28. await savePortals(portals);
  29. // Rivalida sia la home che il layout (il font @font-face è applicato nel layout root)
  30. revalidatePath('/', 'layout');
  31. return NextResponse.json(portals[0], { status: 200 });
  32. } catch {
  33. return NextResponse.json({ error: 'Failed to save portal settings' }, { status: 500 });
  34. }
  35. }