Files
Momento/memento-note/app/api/ai/notebook-summary/route.ts
Antigravity f7da22d409
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 4m44s
CI / Deploy production (on server) (push) Has been skipped
feat(score): rate limiting + focus trap + skip-link + touch targets + cache
SÉCURITÉ 8→9:
- lib/rate-limit.ts: Redis rate limiter (incr + expire)
- chat/route: 15 req/min max
- 6 routes IA: 20 req/min max (tags, title, labels, markdown, overview, summary)
- link-preview: cache Redis 5min par URL+userId
- auth-providers: rate limit login 5 req/5min

UX 7.5→8.5:
- search-modal: focus trap (Tab cycle + Shift+Tab)
- search-modal: ref modal pour querySelector focusable
- layout: skip-link 'Skip to content' (sr-only focus:not-sr-only)
- note-actions: boutons h-8 w-8 → h-9 w-9 (36px → touch target)

0 erreur TS, 199/199 tests
2026-07-05 18:31:06 +00:00

83 lines
2.0 KiB
TypeScript

import { rateLimit } from '@/lib/rate-limit'
import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import { notebookSummaryService } from '@/lib/ai/services'
import { hasUserAiConsent } from '@/lib/consent/server-consent'
/**
* POST /api/ai/notebook-summary - Generate summary for a notebook
*/
export async function POST(request: NextRequest) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: 'Unauthorized' },
{ status: 401 }
)
}
if (!(await hasUserAiConsent())) {
return NextResponse.json(
{ success: false, error: 'ai_consent_required' },
{ status: 403 }
)
}
const body = await request.json()
const { notebookId, language = 'en' } = body
if (!notebookId || typeof notebookId !== 'string') {
return NextResponse.json(
{ success: false, error: 'Missing required field: notebookId' },
{ status: 400 }
)
}
// Check if notebook belongs to user
const { prisma } = await import('@/lib/prisma')
const notebook = await prisma.notebook.findFirst({
where: {
id: notebookId,
userId: session.user.id,
},
})
if (!notebook) {
return NextResponse.json(
{ success: false, error: 'Notebook not found' },
{ status: 404 }
)
}
// Generate summary
const summary = await notebookSummaryService.generateSummary(
notebookId,
session.user.id,
language
)
if (!summary) {
return NextResponse.json({
success: true,
data: null,
message: 'No summary available (notebook may be empty)',
})
}
return NextResponse.json({
success: true,
data: summary,
})
} catch (error) {
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Failed to generate notebook summary',
},
{ status: 500 }
)
}
}