Files
top-tickets/src/app/api/ldap/directory/route.ts
T
Claude Sonnet 5 52ca317e9c Restore from Gitea ZIP snapshot (12.08.2026) after full instance reinstall
Git history was lost when the previous Gitea instance was wiped and
reinstalled due to an unresolved corruption bug — this commit is the
last known-good file content, exported before the reinstall. Prior
commit history is not recoverable through this path.
2026-08-12 19:24:03 +00:00

28 lines
1.1 KiB
TypeScript

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