feat(flashcards): révision SM-2, génération IA et page /revision
Livre US-FLASHCARDS avec decks, session de révision, stats et migration Prisma. Finalise le Web Clipper (i18n 15 langues) et corrige les erreurs ESLint bloquant la CI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
55
memento-note/lib/flashcards/deck-utils.ts
Normal file
55
memento-note/lib/flashcards/deck-utils.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
|
||||
export async function getOrCreateDeckForNotebook(params: {
|
||||
userId: string
|
||||
notebookId: string | null
|
||||
notebookName?: string | null
|
||||
manualName?: string
|
||||
}) {
|
||||
const { userId, notebookId, notebookName, manualName } = params
|
||||
|
||||
if (notebookId) {
|
||||
const existing = await prisma.flashcardDeck.findFirst({
|
||||
where: { userId, notebookId },
|
||||
})
|
||||
if (existing) return existing
|
||||
|
||||
const notebook = await prisma.notebook.findFirst({
|
||||
where: { id: notebookId, userId },
|
||||
select: { name: true },
|
||||
})
|
||||
if (!notebook) {
|
||||
throw new Error('Notebook not found')
|
||||
}
|
||||
|
||||
return prisma.flashcardDeck.create({
|
||||
data: {
|
||||
userId,
|
||||
notebookId,
|
||||
name: notebook.name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const name = (manualName || notebookName || 'Deck').trim().slice(0, 120)
|
||||
if (!name) {
|
||||
throw new Error('Deck name required')
|
||||
}
|
||||
|
||||
return prisma.flashcardDeck.create({
|
||||
data: {
|
||||
userId,
|
||||
name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function stripHtmlToText(html: string): string {
|
||||
return html
|
||||
.replace(/<script[\s\S]*?<\/script>/gi, ' ')
|
||||
.replace(/<style[\s\S]*?<\/style>/gi, ' ')
|
||||
.replace(/<[^>]+>/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
}
|
||||
Reference in New Issue
Block a user