klg-asutk-app/app/api/audit/rollback/route.ts
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

55 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const dynamic = "force-dynamic";
import { NextRequest, NextResponse } from 'next/server';
import { rollbackChange } from '@/lib/audit/audit-service';
import { rateLimit, getRateLimitIdentifier } from '@/lib/rate-limit';
import { logSecurity } from '@/lib/logger';
/**
* POST /api/audit/rollback - Откат изменений
*/
export async function POST(request: NextRequest) {
try {
// Rate limiting
const identifier = getRateLimitIdentifier(request);
const rateLimitResult = rateLimit(identifier);
if (!rateLimitResult.allowed) {
return NextResponse.json(
{ error: 'Слишком много запросов' },
{ status: 429 }
);
}
const body = await request.json();
const { auditLogId } = body;
if (!auditLogId) {
return NextResponse.json(
{ error: 'Не указан ID записи аудита' },
{ status: 400 }
);
}
// Логируем попытку отката
logSecurity('Попытка отката изменений', {
auditLogId,
ip: request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined,
});
const success = await rollbackChange(auditLogId);
if (success) {
return NextResponse.json({ success: true, message: 'Изменения успешно откачены' });
} else {
return NextResponse.json(
{ error: 'Не удалось откатить изменения' },
{ status: 500 }
);
}
} catch (error: any) {
return NextResponse.json(
{ error: error.message || 'Ошибка при откате изменений' },
{ status: 500 }
);
}
}