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)
43 lines
1.1 KiB
TypeScript
43 lines
1.1 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 q = searchParams.get('q')?.trim()
|
|
if (!q) return NextResponse.json({ results: [] })
|
|
|
|
const notes = await prisma.note.findMany({
|
|
where: {
|
|
userId,
|
|
trashedAt: null,
|
|
OR: [
|
|
{ title: { contains: q, mode: 'insensitive' } },
|
|
{ content: { contains: q, mode: 'insensitive' } },
|
|
],
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
content: true,
|
|
notebook: { select: { name: true } },
|
|
},
|
|
take: 20,
|
|
orderBy: { updatedAt: 'desc' },
|
|
})
|
|
|
|
const results = notes.map((n) => ({
|
|
id: n.id,
|
|
title: n.title,
|
|
notebookName: n.notebook?.name,
|
|
snippet: n.content
|
|
? n.content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 160)
|
|
: '',
|
|
}))
|
|
|
|
return NextResponse.json({ results })
|
|
}
|