mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 14:44:15 +00:00
feat: allow admins to disable submissions
This commit is contained in:
parent
769dd0b863
commit
c5437ed3e7
5 changed files with 104 additions and 0 deletions
23
src/app/api/admin/can-submit/route.ts
Normal file
23
src/app/api/admin/can-submit/route.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
let canSubmit = true;
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ success: true, value: canSubmit });
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
if (Number(session.user.id) !== Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID)) return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
|
||||
const body = await request.json();
|
||||
const validatedCanSubmit = z.boolean().safeParse(body);
|
||||
if (!validatedCanSubmit.success) return NextResponse.json({ error: "Failed to validate body" }, { status: 400 });
|
||||
|
||||
canSubmit = validatedCanSubmit.data;
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
|
@ -41,6 +41,11 @@ export async function POST(request: NextRequest) {
|
|||
const check = await rateLimit.handle();
|
||||
if (check) return check;
|
||||
|
||||
const response = await fetch(`${process.env.BASE_URL}/api/admin/can-submit`);
|
||||
const { value } = await response.json();
|
||||
if (!value) return rateLimit.sendResponse({ error: "Submissions are disabled" }, 409);
|
||||
|
||||
// Parse data
|
||||
const formData = await request.formData();
|
||||
|
||||
let rawTags: string[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue