export const runtime = "nodejs"; import { NextResponse } from "next/server"; import { requireAdminSession } from "@/lib/auth/require"; import { getLdapSettings } from "@/lib/auth/ldap-config"; import { searchLdapDirectory } from "@/lib/ldap/client"; import { listUsers } from "@/lib/auth/users"; export async function GET() { const { session, response } = await requireAdminSession(); if (!session) return response; const settings = await getLdapSettings(); if (!settings) { return NextResponse.json({ configured: false, entries: [] }); } try { const [entries, existing] = await Promise.all([searchLdapDirectory(), listUsers()]); const existingEmails = new Set(existing.map((u) => u.email.toLowerCase())); const fresh = entries.filter((e) => !existingEmails.has(e.email.toLowerCase())); return NextResponse.json({ configured: true, entries: fresh }); } catch (err) { const message = err instanceof Error ? err.message : "Unknown error"; return NextResponse.json({ error: `Не удалось получить список из LDAP: ${message}` }, { status: 502 }); } }