Files
Momento/memento-note/app/api/blocks/[blockId]/status/route.ts
Antigravity e2672cd2c2
Some checks failed
CI / Lint, Test & Build (push) Failing after 1m19s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): liens internes, onglet Réseau, living blocks et consentement IA
Rend les liens entre notes visibles et persistants (sync NoteLink au save, auto-save, graphe réseau rafraîchi), ajoute living blocks, Memory Echo, recherche globale, consentement IA explicite et consolide les prototypes design en architectural-grid.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:27:29 +00:00

53 lines
1.5 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { auth } from '@/auth'
function extractBlockContent(html: string, blockId: string): string | null {
const regex = new RegExp(
`<(?:p|h[1-6]|blockquote)[^>]*data-id="${blockId}"[^>]*>([\\s\\S]*?)<\\/(?:p|h[1-6]|blockquote)>`,
'i'
)
const match = regex.exec(html)
if (!match) return null
return match[1].replace(/<[^>]+>/g, '').trim()
}
// GET /api/blocks/[blockId]/status?sourceNoteId=xxx
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ blockId: string }> }
) {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { blockId } = await params
const sourceNoteId = request.nextUrl.searchParams.get('sourceNoteId')
if (!sourceNoteId) {
return NextResponse.json({ error: 'sourceNoteId required' }, { status: 400 })
}
const note = await prisma.note.findFirst({
where: { id: sourceNoteId, userId: session.user.id },
select: { id: true, title: true, content: true },
})
if (!note) {
return NextResponse.json({ exists: false, content: '', sourceNoteTitle: '' })
}
const content = extractBlockContent(note.content, blockId)
if (content === null) {
return NextResponse.json({ exists: false, content: '', sourceNoteTitle: note.title || '' })
}
return NextResponse.json({
exists: true,
content,
sourceNoteTitle: note.title || 'Sans titre',
})
}