fix mime checks (#5118)

zio/stable
Samuel Newman 2024-09-03 20:55:10 +01:00 committed by GitHub
parent ea4d8bc1ab
commit 0bd0146efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 14 deletions

View File

@ -136,3 +136,12 @@ export const GIF_FEATURED = (params: string) =>
`${GIF_SERVICE}/tenor/v2/featured?${params}` `${GIF_SERVICE}/tenor/v2/featured?${params}`
export const MAX_LABELERS = 20 export const MAX_LABELERS = 20
export const SUPPORTED_MIME_TYPES = [
'video/mp4',
'video/mpeg',
'video/webm',
'video/quicktime',
] as const
export type SupportedMimeTypes = (typeof SUPPORTED_MIME_TYPES)[number]

View File

@ -30,5 +30,5 @@ export async function compressVideo(
const info = await getVideoMetaData(compressed) const info = await getVideoMetaData(compressed)
return {uri: compressed, size: info.size, mimeType: `video/${info.extension}`} return {uri: compressed, size: info.size, mimeType: `video/mp4`}
} }

View File

@ -1,6 +1,8 @@
import {useMemo} from 'react' import {useMemo} from 'react'
import {AtpAgent} from '@atproto/api' import {AtpAgent} from '@atproto/api'
import {SupportedMimeTypes} from '#/lib/constants'
const UPLOAD_ENDPOINT = 'https://video.bsky.app/' const UPLOAD_ENDPOINT = 'https://video.bsky.app/'
export const createVideoEndpointUrl = ( export const createVideoEndpointUrl = (
@ -25,7 +27,7 @@ export function useVideoAgent() {
}, []) }, [])
} }
export function mimeToExt(mimeType: string) { export function mimeToExt(mimeType: SupportedMimeTypes | (string & {})) {
switch (mimeType) { switch (mimeType) {
case 'video/mp4': case 'video/mp4':
return 'mp4' return 'mp4'
@ -33,6 +35,8 @@ export function mimeToExt(mimeType: string) {
return 'webm' return 'webm'
case 'video/mpeg': case 'video/mpeg':
return 'mpeg' return 'mpeg'
case 'video/quicktime':
return 'mov'
default: default:
throw new Error(`Unsupported mime type: ${mimeType}`) throw new Error(`Unsupported mime type: ${mimeType}`)
} }

View File

@ -5,6 +5,7 @@ import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query' import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query'
import {SUPPORTED_MIME_TYPES, SupportedMimeTypes} from '#/lib/constants'
import {logger} from '#/logger' import {logger} from '#/logger'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {ServerError, VideoTooLargeError} from 'lib/media/video/errors' import {ServerError, VideoTooLargeError} from 'lib/media/video/errors'
@ -175,19 +176,19 @@ export function useUploadVideo({
}) })
const selectVideo = (asset: ImagePickerAsset) => { const selectVideo = (asset: ImagePickerAsset) => {
switch (getMimeType(asset)) { // compression step on native converts to mp4, so no need to check there
case 'video/mp4': if (isWeb) {
case 'video/mpeg': const mimeType = getMimeType(asset)
case 'video/webm': if (!SUPPORTED_MIME_TYPES.includes(mimeType as SupportedMimeTypes)) {
dispatch({ throw new Error(_(msg`Unsupported video type: ${mimeType}`))
type: 'SetAsset', }
asset,
})
onSelectVideo(asset)
break
default:
throw new Error(_(msg`Unsupported video type: ${getMimeType(asset)}`))
} }
dispatch({
type: 'SetAsset',
asset,
})
onSelectVideo(asset)
} }
const clearVideo = () => { const clearVideo = () => {