Files
Momento/memento-note/app/api/mobile/flashcards/session/route.ts
Antigravity a84c7e80d6
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 6m13s
CI / Deploy production (on server) (push) Successful in 24s
fix(critique): 2 régressions introduites par les fixes précédents
Bug #1 — Memory Echo cassé (runtime crash):
- lib/ai/services/memory-echo.service.ts: lignes adjustedThreshold restaurées
- Cause: sed console.log avait supprimé les lignes de définition
- Effet: findConnections() crashait (ReferenceError)

Bug #2 — Auth mobile totalement cassée (sécurité):
- 14 routes app/api/mobile/*/: getMobileUserId(req) → await getMobileUserId(req)
- Cause: verifyMobileToken devenu async mais callers non mis à jour
- Effet: auth bypassée (Promise truthy au lieu de string)

i18n:
- searchModal.* + insightsView.* propagés dans 13 locales (EN fallback)
2026-07-05 16:53:36 +00:00

39 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
export async function GET(req: NextRequest) {
const userId = await getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { searchParams } = new URL(req.url)
const deckId = searchParams.get('deckId')
const limit = Math.min(parseInt(searchParams.get('limit') ?? '20', 10), 50)
if (!deckId) return NextResponse.json({ error: 'deckId required' }, { status: 400 })
// Vérifier ownership
const deck = await prisma.flashcardDeck.findFirst({
where: { id: deckId, userId },
select: { id: true, name: true },
})
if (!deck) return NextResponse.json({ error: 'Deck not found' }, { status: 404 })
const now = new Date()
const cards = await prisma.flashcard.findMany({
where: { deckId, nextReviewAt: { lte: now } },
select: {
id: true,
front: true,
back: true,
interval: true,
easinessFactor: true,
type: true,
},
orderBy: { nextReviewAt: 'asc' },
take: limit,
})
return NextResponse.json({ deck: { id: deck.id, name: deck.name }, cards })
}