[Video] speculative .vtt file selection fix (#5296)

* speculative vtt fix

* add logging
zio/stable^2^2
Samuel Newman 2024-09-12 15:16:38 +01:00 committed by GitHub
parent ae71f5ce84
commit 7da3ddbe24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {logger} from '#/logger'
import * as Toast from '#/view/com/util/Toast'
import {atoms as a} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
@ -25,9 +26,16 @@ export function SubtitleFilePicker({
const handlePick = (evt: React.ChangeEvent<HTMLInputElement>) => {
const selectedFile = evt.target.files?.[0]
if (selectedFile) {
if (selectedFile.type === 'text/vtt') {
if (
selectedFile.type === 'text/vtt' ||
(selectedFile.type === 'text/plain' &&
selectedFile.name.endsWith('.vtt'))
) {
onSelectFile(selectedFile)
} else {
logger.error('Invalid subtitle file type', {
safeMessage: `File: ${selectedFile.name} (${selectedFile.type})`,
})
Toast.show(_(msg`Only WebVTT (.vtt) files are supported`))
}
}