1. replaceAll (Find & Replace) — une seule transaction ProseMirror au lieu d'un forEach cassé. Tous les matchs sont maintenant remplacés. 2. Link Preview unwrap — deleteNode() au lieu de clearer les attrs qui laissaient un nœud fantôme invisible dans le document. 3. Conversion Markdown → richtext — breaks: true dans marked.parse() Les simple newlines sont maintenant convertis en <br>. + préserve les blocs custom (toggle, callout, math, columns, outline, link-preview) en commentaires HTML lors de l'export MD. 4. emitNoteChange exercices — shape corrigée (type:'created' attend un objet Note, pas noteId/notebookId séparés). 5. Raccourcis clavier sans conflit : Cmd+Shift+C → Cmd+Alt+C (callout, avant: copier) Cmd+Shift+O → Cmd+Alt+O (outline, avant: historique/signets) Cmd+Shift+L → Cmd+Alt+L (colonnes, avant: lock screen macOS)
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getMobileUserId } from '@/lib/mobile-auth'
|
|
import { paragraphRefactorService } from '@/lib/ai/services/paragraph-refactor.service'
|
|
import { reserveUsageOrThrow, QuotaExceededError } 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 reserveUsageOrThrow(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)
|
|
|
|
return NextResponse.json({ improved: result.refactored, original: result.original })
|
|
}
|