2025-04-17 14:13:21 +02:00
|
|
|
import { NextResponse, NextRequest } from "next/server";
|
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
|
|
|
|
|
|
interface AddRequest {
|
|
|
|
|
type: string;
|
2025-04-27 14:49:36 +02:00
|
|
|
name: string;
|
2025-04-17 14:13:21 +02:00
|
|
|
smtpHost?: string;
|
|
|
|
|
smtpPort?: number;
|
|
|
|
|
smtpSecure?: boolean;
|
|
|
|
|
smtpUsername?: string;
|
|
|
|
|
smtpPassword?: string;
|
|
|
|
|
smtpFrom?: string;
|
|
|
|
|
smtpTo?: string;
|
|
|
|
|
telegramToken?: string;
|
|
|
|
|
telegramChatId?: string;
|
|
|
|
|
discordWebhook?: string;
|
2025-04-19 13:11:18 +02:00
|
|
|
gotifyUrl?: string;
|
|
|
|
|
gotifyToken?: string;
|
|
|
|
|
ntfyUrl?: string;
|
|
|
|
|
ntfyToken?: string;
|
2025-04-21 15:28:36 +02:00
|
|
|
pushoverUrl?: string;
|
|
|
|
|
pushoverToken?: string;
|
|
|
|
|
pushoverUser?: string;
|
2025-04-17 14:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function POST(request: NextRequest) {
|
|
|
|
|
try {
|
|
|
|
|
const body: AddRequest = await request.json();
|
2025-04-27 14:49:36 +02:00
|
|
|
const { type, name, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook, gotifyUrl, gotifyToken, ntfyUrl, ntfyToken, pushoverUrl, pushoverToken, pushoverUser } = body;
|
2025-04-17 14:13:21 +02:00
|
|
|
|
|
|
|
|
const notification = await prisma.notification.create({
|
|
|
|
|
data: {
|
|
|
|
|
type: type,
|
2025-04-27 14:49:36 +02:00
|
|
|
name: name,
|
2025-04-17 14:13:21 +02:00
|
|
|
smtpHost: smtpHost,
|
|
|
|
|
smtpPort: smtpPort,
|
|
|
|
|
smtpFrom: smtpFrom,
|
|
|
|
|
smtpUser: smtpUsername,
|
|
|
|
|
smtpPass: smtpPassword,
|
|
|
|
|
smtpSecure: smtpSecure,
|
|
|
|
|
smtpTo: smtpTo,
|
|
|
|
|
telegramChatId: telegramChatId,
|
|
|
|
|
telegramToken: telegramToken,
|
|
|
|
|
discordWebhook: discordWebhook,
|
2025-04-19 13:11:18 +02:00
|
|
|
gotifyUrl: gotifyUrl,
|
|
|
|
|
gotifyToken: gotifyToken,
|
|
|
|
|
ntfyUrl: ntfyUrl,
|
|
|
|
|
ntfyToken: ntfyToken,
|
2025-04-21 15:28:36 +02:00
|
|
|
pushoverUrl: pushoverUrl,
|
|
|
|
|
pushoverToken: pushoverToken,
|
|
|
|
|
pushoverUser: pushoverUser,
|
2025-04-17 14:13:21 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ message: "Success", notification });
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|