Files
Momento/memento-note/app/api/mobile/ai/title/route.ts
Antigravity a84c7e80d6
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 6m13s
CI / Deploy production (on server) (push) Successful in 24s
fix(critique): 2 régressions introduites par les fixes précédents
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)
2026-07-05 16:53:36 +00:00

41 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getMobileUserId } from '@/lib/mobile-auth'
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
import { getSystemConfig } from '@/lib/config'
import { reserveUsageOrThrow, QuotaExceededError } from '@/lib/entitlements'
export async function POST(req: NextRequest) {
const userId = await 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 })
const config = await getSystemConfig()
const { usedByok: willUseByok } = await willUseByokForLane('tags', config, userId)
if (!willUseByok) {
try {
await reserveUsageOrThrow(userId, 'auto_title')
} catch (err) {
if (err instanceof QuotaExceededError) {
return NextResponse.json({ error: 'quota_exceeded' }, { status: 402 })
}
throw err
}
}
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 } = await runLaneWithBillingUser(
'tags',
config,
userId,
(provider) => provider.generateTitles(prompt),
)
return NextResponse.json({ suggestions: (titles ?? []).map((t: any) => t.title ?? t) })
}