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:
13
shared/difficulty-presets.ts
Normal file
13
shared/difficulty-presets.ts
Normal 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));
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user