24 lines
915 B
TypeScript

"use server";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { setCountdown } from "~/server/functions";
export const POST = async (request: NextRequest) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get("apiKey");
if (apiKey !== process.env.API_KEY) {
console.log("Invalid API Key");
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const countdown = url.searchParams.get("countdown") ?? "2023-01-01T00:00:00.000Z";
await setCountdown(new Date(countdown));
return NextResponse.json({ message: "Countdown set successfully" });
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/setCountdown?apiKey=I_Love_Madeline&countdown=2024-09-20T12:00:00.000Z