fix: 5 bugs critiques de l'éditeur (Phase 1 audit)
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)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { paragraphRefactorService } from '@/lib/ai/services/paragraph-refactor.service'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
import { reserveUsageOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||
|
||||
const MODE_MAP: Record<string, 'clarify' | 'shorten' | 'improveStyle' | 'fix_grammar'> = {
|
||||
improve: 'improveStyle',
|
||||
@@ -26,7 +26,7 @@ export async function POST(req: NextRequest) {
|
||||
if (!validation.valid) return NextResponse.json({ error: validation.error }, { status: 400 })
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'reformulate')
|
||||
await reserveUsageOrThrow(userId, 'reformulate')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: 'quota_exceeded' }, { status: 402 })
|
||||
@@ -35,7 +35,6 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
const result = await paragraphRefactorService.refactor(text, refactorMode, 'markdown', undefined)
|
||||
incrementUsageAsync(userId, 'reformulate')
|
||||
|
||||
return NextResponse.json({ improved: result.refactored, original: result.original })
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { runLaneWithBillingUser } from '@/lib/ai/provider-for-user'
|
||||
import { runLaneWithBillingUser, willUseByokForLane } from '@/lib/ai/provider-for-user'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
import { reserveUsageOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
@@ -14,25 +14,27 @@ export async function POST(req: NextRequest) {
|
||||
const wordCount = content.split(/\s+/).length
|
||||
if (wordCount < 5) return NextResponse.json({ error: 'Contenu trop court (min 5 mots)' }, { status: 400 })
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'auto_title')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: 'quota_exceeded' }, { status: 402 })
|
||||
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
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
const config = await getSystemConfig()
|
||||
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, usedByok } = await runLaneWithBillingUser(
|
||||
const { result: titles } = await runLaneWithBillingUser(
|
||||
'tags',
|
||||
config,
|
||||
userId,
|
||||
(provider) => provider.generateTitles(prompt),
|
||||
)
|
||||
if (!usedByok) incrementUsageAsync(userId, 'auto_title')
|
||||
|
||||
return NextResponse.json({ suggestions: (titles ?? []).map((t: any) => t.title ?? t) })
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import prisma from '@/lib/prisma'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { generateFlashcardsFromNote, type FlashcardStyle } from '@/lib/flashcards/generate-flashcards'
|
||||
import { stripHtmlToText } from '@/lib/flashcards/deck-utils'
|
||||
import { checkEntitlementOrThrow, QuotaExceededError, incrementUsageAsync } from '@/lib/entitlements'
|
||||
import { reserveUsageOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = getMobileUserId(req)
|
||||
@@ -29,7 +29,7 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
await checkEntitlementOrThrow(userId, 'ai_flashcard')
|
||||
await reserveUsageOrThrow(userId, 'ai_flashcard')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json({ error: err.currentQuota === 0 ? 'Fonctionnalité non disponible sur votre abonnement' : 'Quota IA atteint' }, { status: 402 })
|
||||
@@ -78,7 +78,6 @@ export async function POST(req: NextRequest) {
|
||||
})
|
||||
|
||||
await prisma.flashcardDeck.update({ where: { id: deckId }, data: { updatedAt: new Date() } })
|
||||
incrementUsageAsync(userId, 'ai_flashcard')
|
||||
|
||||
return NextResponse.json({ deckId, count: cards.length, cards })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user