Add profile photo uploads and custom difficulty support

This commit is contained in:
2026-10-13 20:50:54 +05:00
parent 8c3de302e7
commit de812453ec
37 changed files with 1139 additions and 74 deletions

View File

@@ -7,7 +7,7 @@ import { accountControlsApi } from "./account-controls-api";
import {
datasetSchema,
faces,
difficulties,
customDifficultySchema,
parseUploadManifest,
panoramaPath,
viewpointSchema,
@@ -144,6 +144,36 @@ export async function handle(request: NextRequest, path: string[]) {
headers: { "Cache-Control": "no-store" },
});
}
if (path[0] === "difficulty-presets" && path.length === 1) {
if (method === "GET") {
const presets = required(
await client
.from("difficulty_presets")
.select("id,name,seconds,zoom")
.order("name", { ascending: true }),
);
return NextResponse.json({ presets });
}
if (method === "POST") {
const body = customDifficultySchema.parse(await jsonBody(request));
const address =
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
"unknown";
await limit("difficulty-presets:" + hash(address), 8, 3600);
const { data, error } = await client
.from("difficulty_presets")
.insert(body)
.select("id,name,seconds,zoom")
.single();
if (error?.code === "23505")
throw new ServiceError(
"A difficulty with that name already exists",
409,
);
checkServiceError(error);
return NextResponse.json({ preset: data });
}
}
if (path[0] === "health" && path.length === 1 && method === "GET") {
const { error } = await client
.from("catalog_servers")
@@ -172,7 +202,10 @@ export async function handle(request: NextRequest, path: string[]) {
const body = z
.object({
datasetId: idSchema,
difficulty: z.enum(["easy", "normal", "hard"]),
difficulty: z.union([
z.enum(["easy", "normal", "hard"]),
idSchema,
]),
})
.parse(await jsonBody(request));
const secret = cookieSecret(request) || randomBytes(32).toString("hex");
@@ -231,6 +264,7 @@ export async function handle(request: NextRequest, path: string[]) {
{
id: s.id,
difficulty: s.difficulty,
difficultySettings: s.difficulty_settings,
round: s.current_round,
bounds: manifest.bounds,
name: manifest.name,