up
This commit is contained in:
@@ -6,6 +6,9 @@ import {
|
||||
networkFailure,
|
||||
type NetworkErrorCode,
|
||||
} from './request-error.js'
|
||||
import { parseTimerType } from './screen-plan.js'
|
||||
import { validQR } from '../src/utils/presentation.js'
|
||||
import type { TimerType } from '../src/types/screen.js'
|
||||
import { createHash } from 'node:crypto'
|
||||
|
||||
export const INCOMPLETE_MATERIALS_WARNING = 'Получен неполный список материалов. Подключите экран к игре для уточнения'
|
||||
@@ -21,7 +24,7 @@ export interface ScreenPackage {
|
||||
intro: string | null
|
||||
conclusion: string | null
|
||||
}
|
||||
steps: { mode: number; text: string; timerLabel: string; timerDurationSeconds: number }[]
|
||||
steps: { mode: number; text: string; timerLabel: string; timerDurationSeconds: number; qrUrl?: string; timerType?: TimerType }[]
|
||||
music: {
|
||||
scenarioPlaylistId: number | null
|
||||
gamePlaylistId: number | null
|
||||
@@ -118,16 +121,18 @@ const modes = [
|
||||
'RESULTS',
|
||||
'TIMER',
|
||||
'TEXT',
|
||||
'QR',
|
||||
'TEAMS',
|
||||
]
|
||||
function mode(value: unknown, field?: string): number {
|
||||
const result =
|
||||
typeof value === 'string' && value.startsWith('SCREEN_MODE_')
|
||||
? modes.indexOf(value.slice('SCREEN_MODE_'.length))
|
||||
: integer(value, 0, field)
|
||||
if (result < 1 || result > 8)
|
||||
if (result < 1 || result > 10)
|
||||
throw fieldError(
|
||||
field,
|
||||
'режим экрана 1–8 или enum ScreenMode',
|
||||
'режим экрана 1–10 или enum ScreenMode',
|
||||
value,
|
||||
'Неизвестный режим показа',
|
||||
)
|
||||
@@ -207,12 +212,17 @@ export function buildScreenPackage(
|
||||
const steps = list(plan.steps, 'plan.steps').map((value, index) => {
|
||||
const field = `plan.steps[${index}]`
|
||||
const step = object(value, field)
|
||||
const timerType = parseTimerType(step.timerType)
|
||||
const qrUrl = text(step.qrUrl, `${field}.qrUrl`)
|
||||
const result = {
|
||||
...(qrUrl ? { qrUrl } : {}),
|
||||
...(timerType ? { timerType } : {}),
|
||||
mode: mode(step.mode, `${field}.mode`),
|
||||
text: text(step.text, `${field}.text`),
|
||||
timerLabel: text(step.timerLabel, `${field}.timerLabel`),
|
||||
timerDurationSeconds: integer(step.timerDurationSeconds, 0, `${field}.timerDurationSeconds`),
|
||||
}
|
||||
if (result.mode === 9 && !validQR(qrUrl, result.text)) throw new Error('Некорректные параметры QR-кода')
|
||||
if (result.mode === 8 && !result.text.trim())
|
||||
throw new ResponseFieldError(
|
||||
`${field}.text`,
|
||||
@@ -510,6 +520,8 @@ export function parseScreenPackage(value: unknown): ScreenPackage {
|
||||
mode: step.mode,
|
||||
text: step.text,
|
||||
timerLabel: step.timerLabel,
|
||||
qrUrl: step.qrUrl,
|
||||
timerType: step.timerType,
|
||||
timerDurationSeconds: step.timerDurationSeconds,
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user