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)
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
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 = await 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 })
|
|
}
|