fix: harden reminders and state handling

This commit is contained in:
Codex
2026-06-06 02:27:04 +07:00
parent ad000c722e
commit ffe80b62c4
17 changed files with 1752 additions and 288 deletions

View File

@@ -14,6 +14,7 @@
import type {
Challenge,
Exercise,
GameId,
GameStat,
Meal,
Settings,
@@ -27,6 +28,7 @@ const MAX_STR_LEN = 200
const VALID_THEMES: Theme[] = ['system', 'light', 'dark']
const VALID_LANGS: Language[] = ['ru', 'en']
const VALID_NOTIFY: NotificationMode[] = ['toast', 'modal', 'both']
const VALID_GAME_IDS: GameId[] = ['dota2']
const VALID_STATS: GameStat[] = [
'deaths',
'kills',
@@ -289,7 +291,7 @@ export function validateChallengeInput(
): Omit<Challenge, 'id'> | null {
if (!isObj(raw)) return null
const name = safeStr(raw.name)
const gameId = safeStr(raw.gameId, 32)
const gameId = oneOf(raw.gameId, VALID_GAME_IDS)
const stat = oneOf(raw.stat, VALID_STATS)
const multiplier = numInRange(raw.multiplier, 0, 1000)
const exerciseName = safeStr(raw.exerciseName)
@@ -306,7 +308,7 @@ export function validateChallengeInput(
}
return {
name,
gameId: gameId as Challenge['gameId'],
gameId,
stat,
multiplier,
exerciseName,