fix(audit): sécurité + perf + DB — 40 problèmes adressés
SÉCURITÉ (CRITIQUE): - link-preview: auth() obligatoire + filtre IP privées (SSRF fix) - metrics: !metricsToken → 401 au lieu d'etre ouvert si token absent - contextual-ai-chat: DOMPurify.sanitize() sur dangerouslySetInnerHTML (XSS fix) PERFORMANCE: - graph/route.ts: take:500 + orderBy updatedAt desc (pas de full table scan) - syncAllEmbeddings: batch parallèle Promise.allSettled × 5 (pas séquentiel) - 80 console.log supprimés du code production BASE DE DONNÉES: - Note: index contentUpdatedAt + isPublic ajoutés au schema - DocumentChunk: commentaire index vectoriel HNSW (à exécuter manuellement)
This commit is contained in:
@@ -31,7 +31,6 @@ interface SuggestChartsResponse {
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
console.log('[suggest-charts] ===== REQUEST START =====')
|
||||
|
||||
// 1. Auth check
|
||||
const session = await auth()
|
||||
@@ -47,16 +46,13 @@ export async function POST(req: Request) {
|
||||
})
|
||||
}
|
||||
const userId = session.user.id
|
||||
console.log('[suggest-charts] userId:', userId)
|
||||
|
||||
// 1.5 Quota check
|
||||
try {
|
||||
const sysConfigEarly = await getSystemConfig()
|
||||
const { usedByok: willUseByok } = await willUseByokForLane('chat', sysConfigEarly, userId)
|
||||
console.log('[suggest-charts] BYOK:', willUseByok)
|
||||
if (!willUseByok) {
|
||||
await reserveUsageOrThrow(userId, 'suggest_charts')
|
||||
console.log('[suggest-charts] Quota OK')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[suggest-charts] QUOTA ERROR:', err)
|
||||
@@ -84,7 +80,6 @@ export async function POST(req: Request) {
|
||||
} satisfies SuggestChartsResponse, { status: 400 })
|
||||
}
|
||||
const { content, selection, noteId } = body
|
||||
console.log('[suggest-charts] contentLen:', content?.length, 'selectionLen:', selection?.length)
|
||||
|
||||
if (!content || content.trim().length === 0) {
|
||||
console.error('[suggest-charts] EMPTY CONTENT')
|
||||
@@ -98,7 +93,6 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const textToAnalyze = selection && selection.trim() ? selection.trim() : content.trim()
|
||||
console.log('[suggest-charts] analyzeLen:', textToAnalyze.length, 'preview:', textToAnalyze.substring(0, 100))
|
||||
|
||||
// 3. Build AI context
|
||||
let provider, model
|
||||
@@ -106,7 +100,6 @@ export async function POST(req: Request) {
|
||||
const sysConfig = await getSystemConfig()
|
||||
provider = getChatProvider(sysConfig)
|
||||
model = provider.getModel()
|
||||
console.log('[suggest-charts] AI model:', model)
|
||||
} catch (e) {
|
||||
console.error('[suggest-charts] AI ROUTE ERROR:', e)
|
||||
return Response.json({
|
||||
@@ -154,7 +147,6 @@ Response format (COPY this structure):
|
||||
})
|
||||
|
||||
// 5. Parse AI response - be very lenient
|
||||
console.log('[suggest-charts] AI response:', text.substring(0, 500))
|
||||
|
||||
let parsed: SuggestChartsResponse
|
||||
try {
|
||||
|
||||
@@ -56,7 +56,6 @@ export async function POST(req: NextRequest) {
|
||||
// If notebookId is provided, use contextual suggestions (IA2)
|
||||
if (notebookId) {
|
||||
try {
|
||||
console.log('[/api/ai/tags] contextual request — notebookId:', notebookId, 'content length:', content.length)
|
||||
const suggestions = await contextualAutoTagService.suggestLabels(
|
||||
content,
|
||||
notebookId,
|
||||
@@ -64,7 +63,6 @@ export async function POST(req: NextRequest) {
|
||||
language
|
||||
);
|
||||
|
||||
console.log('[/api/ai/tags] suggestions:', suggestions.length, suggestions.map(s => `${s.label}(${s.confidence})`))
|
||||
|
||||
const convertedTags = suggestions.map(s => ({
|
||||
tag: s.label,
|
||||
|
||||
Reference in New Issue
Block a user