mirror of
https://github.com/yusufipk/dead-man-switch-2.0.git
synced 2026-09-11 09:26:07 +00:00
feat: Implement message check-in and status management, introduce flexible interval units, and add decryption routes for messages and attachments.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth/options';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function POST(
|
||||
req: Request,
|
||||
{ params }: { params: Promise<{ messageId: string }> }
|
||||
) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { messageId } = await params;
|
||||
const { status } = await req.json();
|
||||
|
||||
if (!['DRAFT', 'ACTIVE'].includes(status)) {
|
||||
return NextResponse.json({ error: 'Invalid status' }, { status: 400 });
|
||||
}
|
||||
|
||||
const message = await prisma.message.findUnique({
|
||||
where: { id: messageId, userId: session.user.id },
|
||||
});
|
||||
|
||||
if (!message) {
|
||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const updated = await prisma.message.update({
|
||||
where: { id: messageId },
|
||||
data: { status, lastPing: new Date() },
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, status: updated.status });
|
||||
}
|
||||
Reference in New Issue
Block a user