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)
84 lines
2.4 KiB
TypeScript
84 lines
2.4 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: 'Non autorisé' }, { status: 401 })
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
const notebookId = searchParams.get('notebookId')
|
|
|
|
const notes = await prisma.note.findMany({
|
|
where: {
|
|
userId,
|
|
trashedAt: null,
|
|
...(notebookId ? { notebookId } : {}),
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
updatedAt: true,
|
|
color: true,
|
|
notebook: { select: { name: true } },
|
|
},
|
|
orderBy: { updatedAt: 'desc' },
|
|
take: 50,
|
|
})
|
|
|
|
const notebookName = notebookId
|
|
? (await prisma.notebook.findUnique({ where: { id: notebookId }, select: { name: true } }))?.name
|
|
: undefined
|
|
|
|
return NextResponse.json({
|
|
notes: notes.map((n) => ({
|
|
id: n.id,
|
|
title: n.title,
|
|
updatedAt: n.updatedAt,
|
|
color: n.color,
|
|
notebookName: n.notebook?.name,
|
|
})),
|
|
...(notebookName ? { notebookName } : {}),
|
|
})
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const userId = await 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, '>')
|
|
}
|
|
|