Add MineGeo gameplay systems and interface
This commit is contained in:
29
app/api/integrations/discord/dispatch/route.ts
Normal file
29
app/api/integrations/discord/dispatch/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { dispatchDiscordAnnouncements } from "@/lib/discord-announcements";
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
export const maxDuration = 300;
|
||||
export async function GET(request: NextRequest) {
|
||||
const secret = process.env.CRON_SECRET;
|
||||
const actual = Buffer.from(request.headers.get("authorization") ?? "");
|
||||
const expected = Buffer.from(`Bearer ${secret ?? ""}`);
|
||||
if (
|
||||
!secret ||
|
||||
actual.length !== expected.length ||
|
||||
!timingSafeEqual(actual, expected)
|
||||
)
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
try {
|
||||
await dispatchDiscordAnnouncements();
|
||||
return NextResponse.json(
|
||||
{ ok: true },
|
||||
{ headers: { "Cache-Control": "no-store" } },
|
||||
);
|
||||
} catch {
|
||||
return NextResponse.json(
|
||||
{ error: "Discord dispatch will retry" },
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user