Types: - NoteType: 'daily' ajouté - PROPERTY_TYPES: 'relation' ajouté - SlashItem: isFavorite? ajouté - SuggestChartsResponse: error? ajouté Fixes propres: - import/route: Date | null → ?? undefined (3 occ) - notes/route: JSON.stringify sur checkItems/labels - user/export: b.title → b.seedIdea, Buffer → Uint8Array - study-plan: language column inexistante → défaut 'fr' - notebooks/[id]: parentId → parent connect/disconnect - brainstorm convert/finalize: async callback - next.config: @ts-expect-error inutile supprimé - ai-settings: revalidateTag(tag, 'default') Casts (TipTap/Prisma, safe at runtime): - tiptap-chart/math extensions: InputRule/options as any - chat/route: system messages as any - note-graph-view: ForceGraph2D as any - property-value-editor: relation comparison - sanitize-content: TrustedHTML cast
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import prisma from '@/lib/prisma'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const { slug, reason, details } = await request.json()
|
|
if (!slug || !reason) {
|
|
return NextResponse.json({ error: 'slug and reason required' }, { status: 400 })
|
|
}
|
|
|
|
const note = await prisma.note.findFirst({
|
|
where: { publicSlug: slug, isPublic: true },
|
|
select: { id: true, userId: true },
|
|
})
|
|
if (!note) return NextResponse.json({ error: 'Note not found' }, { status: 404 })
|
|
|
|
// Store as a notification to the note owner + admin
|
|
await prisma.notification.create({
|
|
data: {
|
|
userId: note.userId!,
|
|
type: 'content_report',
|
|
title: `Signalement : ${reason}`,
|
|
message: details || `Un visiteur a signalé votre note publiée pour: ${reason}`,
|
|
actionUrl: `/p/${slug}`,
|
|
relatedId: note.id,
|
|
},
|
|
}).catch(() => {})
|
|
|
|
// Also notify admins
|
|
const admins = await prisma.user.findMany({
|
|
where: { role: 'ADMIN' },
|
|
select: { id: true },
|
|
})
|
|
for (const admin of admins) {
|
|
await prisma.notification.create({
|
|
data: {
|
|
userId: admin.id,
|
|
type: 'content_report',
|
|
title: `Signalement de contenu : ${reason}`,
|
|
message: `Note /p/${slug} signalée pour: ${reason}${details ? ` — ${details}` : ''}`,
|
|
actionUrl: `/admin/published`,
|
|
relatedId: note.id,
|
|
},
|
|
}).catch(() => {})
|
|
}
|
|
|
|
return NextResponse.json({ success: true })
|
|
} catch (error: any) {
|
|
return NextResponse.json({ error: error.message }, { status: 500 })
|
|
}
|
|
}
|