fix: harden reminders and state handling
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user