mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 21:27:46 +00:00
Compare commits
No commits in common. "975d55bd19b329b1042458cf9192678fadeb46f1" and "12c0205bf5b498c2cf18c5ce76c6810dd654990a" have entirely different histories.
975d55bd19
...
12c0205bf5
8 changed files with 50 additions and 71 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { settings } from "@/lib/settings";
|
||||
|
||||
let canSubmit = true;
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ success: true, value: settings.canSubmit });
|
||||
return NextResponse.json({ success: true, value: canSubmit });
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest) {
|
||||
|
|
@ -14,9 +15,9 @@ export async function PATCH(request: NextRequest) {
|
|||
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 validated = z.boolean().safeParse(body);
|
||||
if (!validated.success) return NextResponse.json({ error: "Failed to validate body" }, { status: 400 });
|
||||
const validatedCanSubmit = z.boolean().safeParse(body);
|
||||
if (!validatedCanSubmit.success) return NextResponse.json({ error: "Failed to validate body" }, { status: 400 });
|
||||
|
||||
settings.canSubmit = validated.data;
|
||||
canSubmit = validatedCanSubmit.data;
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { settings } from "@/lib/settings";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ success: true, value: settings.queueEnabled });
|
||||
}
|
||||
|
||||
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 validated = z.boolean().safeParse(body);
|
||||
if (!validated.success) return NextResponse.json({ error: "Failed to validate body" }, { status: 400 });
|
||||
|
||||
settings.queueEnabled = validated.data;
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
|
@ -21,7 +21,6 @@ import { ThreeDsTomodachiLifeMii } from "@/lib/three-ds-tomodachi-life-mii";
|
|||
|
||||
import { SwitchMiiInstructions } from "@/types";
|
||||
import { minifyInstructions } from "@/lib/switch";
|
||||
import { settings } from "@/lib/settings";
|
||||
|
||||
const uploadsDirectory = path.join(process.cwd(), "uploads", "mii");
|
||||
|
||||
|
|
@ -75,7 +74,10 @@ export async function POST(request: NextRequest) {
|
|||
const rateLimit = new RateLimit(request, 3);
|
||||
const check = await rateLimit.handle();
|
||||
if (check) return check;
|
||||
if (!settings.canSubmit) return rateLimit.sendResponse({ error: "Submissions are temporarily disabled" }, 503);
|
||||
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/can-submit`);
|
||||
const { value } = await response.json();
|
||||
if (!value) return rateLimit.sendResponse({ error: "Submissions are temporarily disabled" }, 503);
|
||||
|
||||
// Parse tags and QR code as JSON
|
||||
const formData = await request.formData();
|
||||
|
|
@ -153,7 +155,6 @@ export async function POST(request: NextRequest) {
|
|||
const description = uncensoredDescription && profanity.censor(uncensoredDescription);
|
||||
|
||||
// Validate image files
|
||||
let wasImagesModerated = false;
|
||||
const customImages: File[] = [];
|
||||
|
||||
for (const img of [image1, image2, image3]) {
|
||||
|
|
@ -163,7 +164,7 @@ export async function POST(request: NextRequest) {
|
|||
if (imageValidation.valid) {
|
||||
customImages.push(img);
|
||||
} else {
|
||||
wasImagesModerated = true;
|
||||
return rateLimit.sendResponse({ error: `Failed to verify custom image: ${imageValidation.error}` }, imageValidation.status ?? 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +172,10 @@ export async function POST(request: NextRequest) {
|
|||
if (platform === "SWITCH") {
|
||||
const portraitValidation = await validateImage(miiPortraitImage);
|
||||
const featuresValidation = await validateImage(miiFeaturesImage);
|
||||
if (!portraitValidation.valid) wasImagesModerated = true;
|
||||
if (!featuresValidation.valid) wasImagesModerated = true;
|
||||
if (!portraitValidation.valid)
|
||||
return rateLimit.sendResponse({ error: `Failed to verify portrait: ${portraitValidation.error}` }, portraitValidation.status ?? 400);
|
||||
if (!featuresValidation.valid)
|
||||
return rateLimit.sendResponse({ error: `Failed to verify features: ${featuresValidation.error}` }, featuresValidation.status ?? 400);
|
||||
}
|
||||
|
||||
const qrBytes = new Uint8Array(qrBytesRaw ?? []);
|
||||
|
|
@ -196,8 +199,8 @@ export async function POST(request: NextRequest) {
|
|||
name,
|
||||
tags,
|
||||
description,
|
||||
gender: gender ?? "MALE",
|
||||
in_queue: wasImagesModerated || settings.queueEnabled,
|
||||
gender: gender ?? "MALE",
|
||||
in_queue: true,
|
||||
|
||||
// Automatically detect certain information if on 3DS
|
||||
...(platform === "THREE_DS"
|
||||
|
|
@ -334,5 +337,5 @@ export async function POST(request: NextRequest) {
|
|||
return rateLimit.sendResponse({ error: "Failed to store user images" }, 500);
|
||||
}
|
||||
|
||||
return rateLimit.sendResponse({ success: true, id: miiRecord.id, inQueue: wasImagesModerated });
|
||||
return rateLimit.sendResponse({ success: true, id: miiRecord.id });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import Description from "@/components/description";
|
|||
import MiiInstructions from "@/components/mii/instructions";
|
||||
|
||||
import { SwitchMiiInstructions } from "@/types";
|
||||
import { settings } from "@/lib/settings";
|
||||
|
||||
interface Props {
|
||||
params: Promise<{ id: string }>;
|
||||
|
|
@ -129,15 +128,6 @@ export default async function MiiPage({ params }: Props) {
|
|||
<p className="font-medium">This Mii is flagged as controversial and only appears when the filter is enabled</p>
|
||||
</div>
|
||||
)}
|
||||
{mii.in_queue && (
|
||||
<div className="bg-zinc-50 border-2 border-zinc-400 rounded-2xl shadow-lg p-4 flex items-center gap-3 text-zinc-700">
|
||||
<Icon icon="material-symbols:timer" className="text-2xl shrink-0" />
|
||||
<p className="font-medium">
|
||||
This Mii is waiting to be manually reviewed {!settings.queueEnabled && "due to inappropriate images "}
|
||||
and is hidden from the main page.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="relative grid grid-cols-3 gap-4 max-md:grid-cols-1">
|
||||
<div className="bg-amber-50 rounded-3xl border-2 border-amber-500 shadow-lg p-4 h-min flex flex-col items-center max-w-md w-full max-md:place-self-center max-md:row-start-2">
|
||||
{/* Mii Image */}
|
||||
|
|
@ -345,7 +335,7 @@ export default async function MiiPage({ params }: Props) {
|
|||
|
||||
{/* Author and Created date */}
|
||||
<div className="mt-2">
|
||||
<Link href={`/profile/${mii.userId}`} className="text-lg wrap-break-word">
|
||||
<Link href={`/profile/${mii.userId}`} className="text-lg">
|
||||
By <span className="font-bold">{mii.user.name}</span>
|
||||
</Link>
|
||||
<h4 className="text-sm">
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { auth } from "@/lib/auth";
|
|||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
import SubmitForm from "@/components/submit-form";
|
||||
import { settings } from "@/lib/settings";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Submit a Mii - TomodachiShare",
|
||||
|
|
@ -31,8 +30,16 @@ export default async function SubmitPage() {
|
|||
});
|
||||
if (activePunishment) redirect("/off-the-island");
|
||||
|
||||
if (!settings.canSubmit)
|
||||
return (
|
||||
// Check if submissions are disabled
|
||||
let value: boolean | null = true;
|
||||
try {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/can-submit`);
|
||||
value = await response.json();
|
||||
} catch (error) {
|
||||
return <p>An error occurred!</p>;
|
||||
}
|
||||
|
||||
if (!value) return (
|
||||
<div className="grow flex items-center justify-center">
|
||||
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg p-8 max-w-xs w-full text-center flex flex-col">
|
||||
<h2 className="text-5xl font-black">Sorry</h2>
|
||||
|
|
@ -43,7 +50,7 @@ export default async function SubmitPage() {
|
|||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
|
||||
return <SubmitForm />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,25 @@
|
|||
"use client";
|
||||
|
||||
import { settings } from "@/lib/settings";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function ControlCenter() {
|
||||
const [canSubmit, setCanSubmit] = useState(settings.canSubmit);
|
||||
const [isQueueEnabled, setIsQeueueEnabled] = useState(settings.queueEnabled);
|
||||
const [canSubmit, setCanSubmit] = useState(true);
|
||||
|
||||
const onClickSet = async () => {
|
||||
await fetch("/api/admin/can-submit", { method: "PATCH", body: JSON.stringify(canSubmit) });
|
||||
await fetch("/api/admin/queue", { method: "PATCH", body: JSON.stringify(isQueueEnabled) });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const check = async () => {
|
||||
const response = await fetch("/api/admin/can-submit");
|
||||
const { value } = await response.json();
|
||||
|
||||
setCanSubmit(value);
|
||||
};
|
||||
|
||||
check();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="bg-orange-100 rounded-xl border-2 border-orange-400 p-2 flex flex-col gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
|
|
@ -25,17 +33,6 @@ export default function ControlCenter() {
|
|||
/>
|
||||
<label htmlFor="submit">Enable Submissions</label>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="queue"
|
||||
type="checkbox"
|
||||
className="checkbox size-6!"
|
||||
placeholder="Enter banner text"
|
||||
checked={isQueueEnabled}
|
||||
onChange={(e) => setIsQeueueEnabled(e.target.checked)}
|
||||
/>
|
||||
<label htmlFor="queue">Enable Queue</label>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 self-end">
|
||||
<button type="submit" className="pill button" onClick={onClickSet}>
|
||||
|
|
|
|||
|
|
@ -60,6 +60,13 @@ export async function validateImage(file: File): Promise<{ valid: boolean; error
|
|||
formData.append("image", blob);
|
||||
|
||||
const moderationResponse = await fetch("https://api.trafficlunar.net/moderate/image", { method: "POST", body: formData });
|
||||
|
||||
if (!moderationResponse.ok) {
|
||||
console.error("Moderation API error");
|
||||
Sentry.captureException("Moderation API error", { extra: { stage: "moderation-api-response", status: moderationResponse.status } });
|
||||
return { valid: false, error: "Content moderation check failed", status: 500 };
|
||||
}
|
||||
|
||||
const result = await moderationResponse.json();
|
||||
if (result.error) {
|
||||
return { valid: false, error: result.error };
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
export const settings = {
|
||||
canSubmit: true,
|
||||
queueEnabled: false,
|
||||
};
|
||||
Loading…
Reference in a new issue