Validate and deduplicate custom difficulty presets
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m4s

This commit is contained in:
2026-10-16 13:29:32 +05:00
parent 1a34eb71c2
commit 0bd05d6e0b
10 changed files with 427 additions and 41 deletions

View File

@@ -0,0 +1,13 @@
import type { DifficultyPreset } from "./protocol";
// A list fetched before a save must not remove the newly saved preset.
export function mergeDifficultyPresets(
current: DifficultyPreset[],
incoming: DifficultyPreset[],
) {
return [
...new Map(
[...current, ...incoming].map((preset) => [preset.id, preset]),
).values(),
].sort((a, b) => a.name.localeCompare(b.name));
}

View File

@@ -194,8 +194,10 @@ export const customDifficultySchema = z
name: z
.string()
.trim()
.min(2)
.max(40)
.refine(
(name) => [...name].length >= 2 && [...name].length <= 40,
"Difficulty names must contain 2–40 characters",
)
.refine(
(name) =>
!/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/u.test(