Validate and deduplicate custom difficulty presets
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m4s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m4s
This commit is contained in:
18
lib/api.ts
18
lib/api.ts
@@ -13,7 +13,11 @@ import {
|
||||
viewpointSchema,
|
||||
} from "../shared/protocol";
|
||||
import { mediaUrl, mediaUrls } from "./catalog";
|
||||
import { ServiceError, checkServiceError } from "./service-error";
|
||||
import {
|
||||
ServiceError,
|
||||
checkServiceError,
|
||||
checkDifficultyPresetError,
|
||||
} from "./service-error";
|
||||
import { requestOrigin, verifyOrigin } from "./request-origin";
|
||||
import { browserAccount } from "./request-security";
|
||||
import { jsonBody } from "./json-body";
|
||||
@@ -165,12 +169,7 @@ export async function handle(request: NextRequest, path: string[]) {
|
||||
.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);
|
||||
checkDifficultyPresetError(error);
|
||||
return NextResponse.json({ preset: data });
|
||||
}
|
||||
}
|
||||
@@ -202,10 +201,7 @@ export async function handle(request: NextRequest, path: string[]) {
|
||||
const body = z
|
||||
.object({
|
||||
datasetId: idSchema,
|
||||
difficulty: z.union([
|
||||
z.enum(["easy", "normal", "hard"]),
|
||||
idSchema,
|
||||
]),
|
||||
difficulty: z.union([z.enum(["easy", "normal", "hard"]), idSchema]),
|
||||
})
|
||||
.parse(await jsonBody(request));
|
||||
const secret = cookieSecret(request) || randomBytes(32).toString("hex");
|
||||
|
||||
Reference in New Issue
Block a user