mirror of
https://github.com/yusufipk/dead-man-switch-2.0.git
synced 2026-09-11 09:26:07 +00:00
30 lines
813 B
TypeScript
30 lines
813 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/lib/auth/options";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export async function GET(
|
|
req: Request,
|
|
{ params }: { params: Promise<{ messageId: string }> }
|
|
) {
|
|
const { messageId } = await params;
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (!session?.user?.id) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
const message = await prisma.message.findUnique({
|
|
where: { id: messageId, userId: session.user.id },
|
|
include: { attachments: true },
|
|
});
|
|
|
|
if (!message) {
|
|
return new NextResponse("Not found", { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json(
|
|
message.attachments.map((a) => ({ id: a.id, fileName: a.fileName }))
|
|
);
|
|
}
|