Mobile app: - Révision flashcards : liste decks, session flip-card SM-2, couleurs harmonisées web - Génération flashcards depuis note (FlashcardSheet + route /api/mobile/flashcards/generate) - Audio Whisper : hook useAudioRecorder reécrit, MicButton avec erreurs - IA : AISheet (améliorer/clarifier/résumer), TitleSheet (titre automatique) - Suppression note (soft delete + confirmation Alert) - Note du jour : titre lisible + HTML (plus JSON TipTap brut) - Parser TipTap→HTML côté mobile (tipTapToHtml) - Icône 🎓 dans header note → génération flashcards - Endpoint flashcardGenerate dans config.ts Web fixes: - Bug flashcards groupées par carnet → deck par note (migration + schema) - Bug filtre 'cartes dues' ignoré (suppression fallback buildSessionQueue) - Suppression UI création deck manuelle (inutile) - Fix setViewType is not defined dans home-client.tsx Drag handle menu: - Fix : clearNodes() avant transformation (heading→liste/code/citation) - Ajout : option 'Texte' (paragraphe) dans Transformer en - Ajout : Monter / Descendre le bloc - Ajout : Copier le contenu du bloc - Fix : sous-menu hover stable (délai 200ms) - Fix : Supprimer en rouge via classe --danger (plus :first-child) - i18n : nouvelles clés dans 15 locales Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
||
import prisma from '@/lib/prisma'
|
||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||
import { computeSm2Update } from '@/lib/flashcards/sm2'
|
||
|
||
export async function POST(req: NextRequest) {
|
||
const userId = getMobileUserId(req)
|
||
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||
|
||
const body = await req.json()
|
||
const cardId = typeof body.cardId === 'string' ? body.cardId : null
|
||
const grade = typeof body.grade === 'number' ? body.grade : null
|
||
|
||
if (!cardId || grade === null || grade < 1 || grade > 4) {
|
||
return NextResponse.json({ error: 'cardId and grade (1–4) required' }, { status: 400 })
|
||
}
|
||
|
||
const card = await prisma.flashcard.findFirst({
|
||
where: { id: cardId, deck: { userId } },
|
||
select: { id: true, interval: true, easinessFactor: true },
|
||
})
|
||
if (!card) return NextResponse.json({ error: 'Card not found' }, { status: 404 })
|
||
|
||
const { easinessFactor, interval, nextReviewAt } = computeSm2Update(grade, {
|
||
easinessFactor: card.easinessFactor,
|
||
interval: card.interval,
|
||
})
|
||
|
||
await prisma.$transaction([
|
||
prisma.flashcard.update({
|
||
where: { id: cardId },
|
||
data: { easinessFactor, interval, nextReviewAt },
|
||
}),
|
||
prisma.flashcardReview.create({
|
||
data: { cardId, grade, reviewedAt: new Date() },
|
||
}),
|
||
])
|
||
|
||
return NextResponse.json({ ok: true, nextReviewAt, interval })
|
||
}
|