备注功能

This commit is contained in:
2025-11-15 15:47:11 +08:00
parent 03b2ce017a
commit ed6b3393d7
7 changed files with 177 additions and 27 deletions
+32 -4
View File
@@ -2,10 +2,11 @@ import { NextRequest } from 'next/server'
import { prisma } from '@/src/lib/prisma'
import { isAuthorizedDelete } from '@/src/lib/utils'
export async function GET(_req: NextRequest, { params }: { params: { id: string } }) {
export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
try {
const rec = await prisma.recording.findUnique({
where: { id: params.id },
where: { id },
select: {
id: true,
timestamp: true,
@@ -46,12 +47,13 @@ export async function GET(_req: NextRequest, { params }: { params: { id: string
}
}
export async function DELETE(req: NextRequest, { params }: { params: { id: string } }) {
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
try {
if (!isAuthorizedDelete(req)) {
return Response.json({ error: 'unauthorized' }, { status: 401 })
}
const rec = await prisma.recording.delete({ where: { id: params.id } })
const rec = await prisma.recording.delete({ where: { id } })
return Response.json({ success: true, id: rec.id })
} catch (err: any) {
if (err?.code === 'P2025') {
@@ -61,3 +63,29 @@ export async function DELETE(req: NextRequest, { params }: { params: { id: strin
return Response.json({ error: 'internal error' }, { status: 500 })
}
}
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params
try {
const body = await req.json()
const { note } = body
if (note !== undefined && typeof note !== 'string') {
return Response.json({ error: 'invalid note' }, { status: 400 })
}
const rec = await prisma.recording.update({
where: { id },
data: { note: note || null },
select: { id: true, note: true },
})
return Response.json({ success: true, id: rec.id, note: rec.note })
} catch (err: any) {
if (err?.code === 'P2025') {
return Response.json({ error: 'not found' }, { status: 404 })
}
console.error(err)
return Response.json({ error: 'internal error' }, { status: 500 })
}
}