Skip to content

Commit a705670

Browse files
committed
fix(play): a progress message's numbers are held to finite and not negative (#90)
1 parent 3de3ca0 commit a705670

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎src/h5p/play/play-page.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,17 @@ main.addEventListener('drop', (event) => {
264264
take([...event.dataTransfer.files])
265265
})
266266

267+
/** A count of bytes as a message gives it: a number that is one, and not below nothing. */
268+
const amount = (value: unknown): number | null => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null
269+
267270
// From the frame's parent, which may hold what the person attached in the chat: the files, how
268271
// much of one has come so far, and the chat's theme where it is not the system's.
269272
window.addEventListener('message', (event) => {
270273
if (!framed || event.source !== window.parent) return
271274
const message = event.data as { source?: unknown, type?: unknown, files?: unknown, name?: unknown, received?: unknown, total?: unknown, theme?: unknown } | null
272275
if (message?.source !== 'h5p-play-host') return
273276
if (message.type === 'files' && Array.isArray(message.files)) take(message.files.filter((file): file is File => file instanceof File))
274-
else if (message.type === 'progress' && typeof message.received === 'number') fetching(typeof message.name === 'string' ? message.name : '', message.received, typeof message.total === 'number' ? message.total : 0)
277+
else if (message.type === 'progress' && amount(message.received) !== null) fetching(typeof message.name === 'string' ? message.name : '', amount(message.received)!, amount(message.total) ?? 0)
275278
else if (message.type === 'theme' && (message.theme === 'light' || message.theme === 'dark')) document.querySelector<HTMLMetaElement>('meta[name="color-scheme"]')!.content = message.theme
276279
})
277280

0 commit comments

Comments
 (0)