feat: mobile app complet + flashcards fixes + drag handle améliorations
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>
This commit is contained in:
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { auth } from '@/auth'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { getOrCreateDeckForNotebook } from '@/lib/flashcards/deck-utils'
|
||||
import type { FlashcardStyle } from '@/lib/flashcards/generate-flashcards'
|
||||
|
||||
interface CardInput {
|
||||
@@ -35,7 +34,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
let notebookId: string | null = null
|
||||
let fallbackDeckName: string | undefined
|
||||
let noteName = 'Sans titre'
|
||||
if (noteId) {
|
||||
const note = await prisma.note.findFirst({
|
||||
where: { id: noteId, userId: session.user.id },
|
||||
@@ -45,14 +44,13 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json({ error: 'Note not found' }, { status: 404 })
|
||||
}
|
||||
notebookId = note.notebookId
|
||||
if (!notebookId) {
|
||||
fallbackDeckName = note.title?.trim() || 'General'
|
||||
}
|
||||
noteName = note.title?.trim() || 'Sans titre'
|
||||
}
|
||||
|
||||
let deckId = deckIdInput
|
||||
if (!deckId) {
|
||||
if (noteId) {
|
||||
// Chercher un deck déjà créé pour CETTE note spécifique
|
||||
const existingFromNote = await prisma.flashcard.findFirst({
|
||||
where: { noteId, deck: { userId: session.user.id } },
|
||||
select: { deckId: true },
|
||||
@@ -62,10 +60,9 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
if (!deckId) {
|
||||
const deck = await getOrCreateDeckForNotebook({
|
||||
userId: session.user.id,
|
||||
notebookId,
|
||||
manualName: fallbackDeckName,
|
||||
// Créer un nouveau deck nommé d'après la note (pas le carnet)
|
||||
const deck = await prisma.flashcardDeck.create({
|
||||
data: { userId: session.user.id, notebookId, name: noteName },
|
||||
})
|
||||
deckId = deck.id
|
||||
}
|
||||
|
||||
41
memento-note/app/api/mobile/ai/improve/route.ts
Normal file
41
memento-note/app/api/mobile/ai/improve/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { paragraphRefactorService } from '@/lib/ai/services/paragraph-refactor.service'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
|
||||
const MODE_MAP: Record<string, 'clarify' | 'shorten' | 'improveStyle' | 'fix_grammar'> = {
|
||||
improve: 'improveStyle',
|
||||
shorten: 'shorten',
|
||||
clarify: 'clarify',
|
||||
fix_grammar: 'fix_grammar',
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { text, mode = 'improve' } = await req.json().catch(() => ({}))
|
||||
if (!text?.trim()) return NextResponse.json({ error: 'Texte requis' }, { status: 400 })
|
||||
|
||||
const refactorMode = MODE_MAP[mode]
|
||||
if (!refactorMode) {
|
||||
return NextResponse.json({ error: 'Mode invalide. Valeurs: improve, shorten, clarify, fix_grammar' }, { status: 400 })
|
||||
}
|
||||
|
||||
const validation = paragraphRefactorService.validateWordCount(text)
|
||||
if (!validation.valid) return NextResponse.json({ error: validation.error }, { status: 400 })
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'reformulate')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: 'quota_exceeded' }, { status: 402 })
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
const result = await paragraphRefactorService.refactor(text, refactorMode, 'markdown', undefined)
|
||||
incrementUsageAsync(userId, 'reformulate')
|
||||
|
||||
return NextResponse.json({ improved: result.refactored, original: result.original })
|
||||
}
|
||||
38
memento-note/app/api/mobile/ai/title/route.ts
Normal file
38
memento-note/app/api/mobile/ai/title/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { runLaneWithBillingUser } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { content } = await req.json().catch(() => ({}))
|
||||
if (!content?.trim()) return NextResponse.json({ error: 'Contenu requis' }, { status: 400 })
|
||||
|
||||
const wordCount = content.split(/\s+/).length
|
||||
if (wordCount < 5) return NextResponse.json({ error: 'Contenu trop court (min 5 mots)' }, { status: 400 })
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'auto_title')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: 'quota_exceeded' }, { status: 402 })
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
const config = await getSystemConfig()
|
||||
const prompt = `Génère 3 titres concis pour ce texte. Réponds UNIQUEMENT avec un tableau JSON: [{"title":"titre1"},{"title":"titre2"},{"title":"titre3"}]\n\nTexte: ${content.slice(0, 400)}`
|
||||
|
||||
const { result: titles, usedByok } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
userId,
|
||||
(provider) => provider.generateTitles(prompt),
|
||||
)
|
||||
if (!usedByok) incrementUsageAsync(userId, 'auto_title')
|
||||
|
||||
return NextResponse.json({ suggestions: (titles ?? []).map((t: any) => t.title ?? t) })
|
||||
}
|
||||
40
memento-note/app/api/mobile/ai/transcribe/route.ts
Normal file
40
memento-note/app/api/mobile/ai/transcribe/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const formData = await req.formData().catch(() => null)
|
||||
if (!formData) return NextResponse.json({ error: 'Fichier audio requis' }, { status: 400 })
|
||||
|
||||
const file = formData.get('audio')
|
||||
if (!file || !(file instanceof Blob)) {
|
||||
return NextResponse.json({ error: 'Fichier audio manquant' }, { status: 400 })
|
||||
}
|
||||
|
||||
const config = await getSystemConfig()
|
||||
const apiKey = config.OPENAI_API_KEY
|
||||
if (!apiKey) return NextResponse.json({ error: 'Service non disponible' }, { status: 503 })
|
||||
|
||||
const whisperForm = new FormData()
|
||||
whisperForm.append('file', file, 'audio.m4a')
|
||||
whisperForm.append('model', 'whisper-1')
|
||||
whisperForm.append('response_format', 'json')
|
||||
|
||||
const whisperRes = await fetch('https://api.openai.com/v1/audio/transcriptions', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${apiKey}` },
|
||||
body: whisperForm,
|
||||
})
|
||||
|
||||
if (!whisperRes.ok) {
|
||||
const err = await whisperRes.text()
|
||||
console.error('[mobile/ai/transcribe] Whisper error:', err)
|
||||
return NextResponse.json({ error: 'Erreur transcription' }, { status: 500 })
|
||||
}
|
||||
|
||||
const { text } = await whisperRes.json()
|
||||
return NextResponse.json({ text: text ?? '' })
|
||||
}
|
||||
37
memento-note/app/api/mobile/flashcards/decks/route.ts
Normal file
37
memento-note/app/api/mobile/flashcards/decks/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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 = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
|
||||
const now = new Date()
|
||||
const decks = await prisma.flashcardDeck.findMany({
|
||||
where: { userId },
|
||||
include: {
|
||||
notebook: { select: { name: true } },
|
||||
flashcards: {
|
||||
select: {
|
||||
id: true,
|
||||
interval: true,
|
||||
nextReviewAt: true,
|
||||
front: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
})
|
||||
|
||||
const result = decks.map((deck) => ({
|
||||
id: deck.id,
|
||||
name: deck.name,
|
||||
notebookId: deck.notebookId,
|
||||
notebookName: deck.notebook?.name ?? null,
|
||||
totalCards: deck.flashcards.length,
|
||||
dueCount: deck.flashcards.filter((c) => c.nextReviewAt <= now).length,
|
||||
masteredCount: deck.flashcards.filter((c) => c.interval >= 7).length,
|
||||
}))
|
||||
|
||||
return NextResponse.json({ decks: result })
|
||||
}
|
||||
84
memento-note/app/api/mobile/flashcards/generate/route.ts
Normal file
84
memento-note/app/api/mobile/flashcards/generate/route.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { generateFlashcardsFromNote, type FlashcardStyle } from '@/lib/flashcards/generate-flashcards'
|
||||
import { stripHtmlToText } from '@/lib/flashcards/deck-utils'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const body = await req.json().catch(() => ({}))
|
||||
const noteId = typeof body.noteId === 'string' ? body.noteId : null
|
||||
const count = typeof body.count === 'number' ? Math.min(body.count, 20) : 10
|
||||
const styleRaw = typeof body.style === 'string' ? body.style : 'qa'
|
||||
const style: FlashcardStyle = ['qa', 'cloze', 'concept'].includes(styleRaw) ? (styleRaw as FlashcardStyle) : 'qa'
|
||||
|
||||
if (!noteId) return NextResponse.json({ error: 'noteId requis' }, { status: 400 })
|
||||
|
||||
const note = await prisma.note.findFirst({
|
||||
where: { id: noteId, userId, trashedAt: null },
|
||||
select: { id: true, title: true, content: true, notebookId: true, language: true },
|
||||
})
|
||||
if (!note) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
|
||||
|
||||
const textContent = stripHtmlToText(note.content)
|
||||
if (textContent.length < 80) {
|
||||
return NextResponse.json({ error: 'Contenu insuffisant pour générer des flashcards (minimum 80 caractères)' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'ai_flashcard')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: err.currentQuota === 0 ? 'Fonctionnalité non disponible sur votre abonnement' : 'Quota IA atteint' }, { status: 402 })
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
const cards = await generateFlashcardsFromNote({
|
||||
title: note.title || 'Sans titre',
|
||||
textContent,
|
||||
count,
|
||||
style,
|
||||
language: note.language || undefined,
|
||||
})
|
||||
|
||||
if (cards.length === 0) {
|
||||
return NextResponse.json({ error: 'Génération échouée — aucune carte produite' }, { status: 500 })
|
||||
}
|
||||
|
||||
// Chercher un deck existant pour cette note, ou en créer un
|
||||
const existing = await prisma.flashcard.findFirst({
|
||||
where: { noteId: note.id, deck: { userId } },
|
||||
select: { deckId: true },
|
||||
})
|
||||
|
||||
let deckId: string
|
||||
if (existing) {
|
||||
deckId = existing.deckId
|
||||
// Supprimer les anciennes cartes pour les remplacer
|
||||
await prisma.flashcard.deleteMany({ where: { noteId: note.id, deckId } })
|
||||
} else {
|
||||
const deck = await prisma.flashcardDeck.create({
|
||||
data: { userId, notebookId: note.notebookId, name: note.title || 'Sans titre' },
|
||||
})
|
||||
deckId = deck.id
|
||||
}
|
||||
|
||||
await prisma.flashcard.createMany({
|
||||
data: cards.map((c) => ({
|
||||
deckId,
|
||||
noteId: note.id,
|
||||
front: c.front,
|
||||
back: c.back,
|
||||
type: c.type,
|
||||
})),
|
||||
})
|
||||
|
||||
await prisma.flashcardDeck.update({ where: { id: deckId }, data: { updatedAt: new Date() } })
|
||||
incrementUsageAsync(userId, 'ai_flashcard')
|
||||
|
||||
return NextResponse.json({ deckId, count: cards.length, cards })
|
||||
}
|
||||
40
memento-note/app/api/mobile/flashcards/review/route.ts
Normal file
40
memento-note/app/api/mobile/flashcards/review/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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 })
|
||||
}
|
||||
38
memento-note/app/api/mobile/flashcards/session/route.ts
Normal file
38
memento-note/app/api/mobile/flashcards/session/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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 = 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 })
|
||||
}
|
||||
@@ -28,3 +28,60 @@ export async function GET(
|
||||
|
||||
return NextResponse.json({ note })
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { id } = await params
|
||||
const { title, content } = await req.json().catch(() => ({}))
|
||||
|
||||
const existing = await prisma.note.findFirst({ where: { id, userId, trashedAt: null } })
|
||||
if (!existing) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
|
||||
|
||||
const htmlContent = content !== undefined ? buildHtmlContent(content) : existing.content
|
||||
|
||||
const note = await prisma.note.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...(title?.trim() ? { title: title.trim() } : {}),
|
||||
content: htmlContent,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
select: { id: true, title: true, updatedAt: true },
|
||||
})
|
||||
|
||||
return NextResponse.json({ note })
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { id } = await params
|
||||
const note = await prisma.note.findFirst({ where: { id, userId, trashedAt: null } })
|
||||
if (!note) return NextResponse.json({ error: 'Note introuvable' }, { status: 404 })
|
||||
|
||||
await prisma.note.update({ where: { id }, data: { trashedAt: new Date() } })
|
||||
return NextResponse.json({ ok: true })
|
||||
}
|
||||
|
||||
function buildHtmlContent(text: string): string {
|
||||
if (!text.trim()) return '<p></p>'
|
||||
if (text.trimStart().startsWith('<')) return text
|
||||
return text
|
||||
.split('\n')
|
||||
.map((line) => `<p>${line.trim() ? escapeHtml(line) : ''}</p>`)
|
||||
.join('')
|
||||
}
|
||||
|
||||
function escapeHtml(s: string) {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
|
||||
59
memento-note/app/api/mobile/notes/daily/route.ts
Normal file
59
memento-note/app/api/mobile/notes/daily/route.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
|
||||
function getTodayKey(): string {
|
||||
return new Date().toISOString().slice(0, 10) // YYYY-MM-DD — clé de recherche interne
|
||||
}
|
||||
|
||||
function getTodayTitle(): string {
|
||||
return new Date().toLocaleDateString('fr-FR', {
|
||||
weekday: 'long', year: 'numeric', month: 'long', day: 'numeric',
|
||||
})
|
||||
// ex : "vendredi 29 mai 2026"
|
||||
}
|
||||
|
||||
function getTodayContent(title: string): string {
|
||||
// HTML simple lisible par la WebView mobile
|
||||
return `<h1>📅 ${title}</h1><p></p>`
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const todayKey = getTodayKey()
|
||||
const todayTitle = getTodayTitle()
|
||||
|
||||
// Chercher par clé ISO (titre interne) ou par titre lisible (migration)
|
||||
let note = await prisma.note.findFirst({
|
||||
where: {
|
||||
userId,
|
||||
type: 'daily',
|
||||
trashedAt: null,
|
||||
title: { in: [todayKey, todayTitle] },
|
||||
},
|
||||
})
|
||||
|
||||
if (!note) {
|
||||
note = await prisma.note.create({
|
||||
data: {
|
||||
userId,
|
||||
title: todayTitle,
|
||||
content: getTodayContent(todayTitle),
|
||||
type: 'daily',
|
||||
color: '#FEF9C3',
|
||||
labels: JSON.stringify(['daily']),
|
||||
},
|
||||
})
|
||||
} else if (note.title === todayKey) {
|
||||
// Migrer l'ancien titre ISO → titre lisible
|
||||
const htmlContent = getTodayContent(todayTitle)
|
||||
note = await prisma.note.update({
|
||||
where: { id: note.id },
|
||||
data: { title: todayTitle, content: htmlContent },
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({ id: note.id, note })
|
||||
}
|
||||
@@ -41,3 +41,43 @@ export async function GET(req: NextRequest) {
|
||||
...(notebookName ? { notebookName } : {}),
|
||||
})
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 })
|
||||
|
||||
const { title, content, notebookId } = await req.json().catch(() => ({}))
|
||||
if (!title?.trim()) return NextResponse.json({ error: 'Titre requis' }, { status: 400 })
|
||||
|
||||
// Convertir le texte brut en HTML TipTap simple si nécessaire
|
||||
const htmlContent = buildHtmlContent(content ?? '')
|
||||
|
||||
const note = await prisma.note.create({
|
||||
data: {
|
||||
userId,
|
||||
title: title.trim(),
|
||||
content: htmlContent,
|
||||
type: 'richtext',
|
||||
...(notebookId ? { notebookId } : {}),
|
||||
},
|
||||
select: { id: true, title: true, updatedAt: true },
|
||||
})
|
||||
|
||||
return NextResponse.json({ note }, { status: 201 })
|
||||
}
|
||||
|
||||
/** Convertit du texte brut multiligne en paragraphes HTML TipTap */
|
||||
function buildHtmlContent(text: string): string {
|
||||
if (!text.trim()) return '<p></p>'
|
||||
// Si déjà du HTML, retourner tel quel
|
||||
if (text.trimStart().startsWith('<')) return text
|
||||
return text
|
||||
.split('\n')
|
||||
.map((line) => `<p>${line.trim() ? escapeHtml(line) : ''}</p>`)
|
||||
.join('')
|
||||
}
|
||||
|
||||
function escapeHtml(s: string) {
|
||||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
}
|
||||
|
||||
|
||||
@@ -1140,16 +1140,6 @@ html.font-system * {
|
||||
color: #60a5fa;
|
||||
}
|
||||
|
||||
.block-action-item:first-child:hover {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.dark .block-action-item:first-child:hover {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
color: #f87171;
|
||||
}
|
||||
|
||||
.smart-paste-menu {
|
||||
min-width: 240px;
|
||||
padding: 8px 4px 4px;
|
||||
@@ -1188,6 +1178,21 @@ html.font-system * {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Danger item (Supprimer) */
|
||||
.block-action-item--danger:hover {
|
||||
background: rgba(239, 68, 68, 0.1) !important;
|
||||
color: #ef4444 !important;
|
||||
}
|
||||
.dark .block-action-item--danger:hover {
|
||||
background: rgba(239, 68, 68, 0.2) !important;
|
||||
color: #f87171 !important;
|
||||
}
|
||||
|
||||
/* Wrap du sous-menu pour maintenir le hover */
|
||||
.block-action-submenu-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.block-action-submenu {
|
||||
position: absolute;
|
||||
left: 100%;
|
||||
|
||||
Reference in New Issue
Block a user