Ungate video upload size change (#10683)
This commit is contained in:
@@ -16,7 +16,6 @@ export enum Features {
|
|||||||
DmsNewMessageComposerEnable = 'dms:new_message_composer:enable',
|
DmsNewMessageComposerEnable = 'dms:new_message_composer:enable',
|
||||||
ComposerLanguageDetectionEnable = 'composer:language_detection:enable',
|
ComposerLanguageDetectionEnable = 'composer:language_detection:enable',
|
||||||
PostGalleryEmbedEnable = 'post_gallery_embed:enable',
|
PostGalleryEmbedEnable = 'post_gallery_embed:enable',
|
||||||
LargeVideoUploads = 'large_video_uploads:enable',
|
|
||||||
|
|
||||||
AATest = 'aa-test',
|
AATest = 'aa-test',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ export const VIDEO_MAX_DURATION_MS = 3 * 60 * 1000 // 3 minutes in milliseconds
|
|||||||
* Maximum size of a video in megabytes, _not_ mebibytes. Backend uses
|
* Maximum size of a video in megabytes, _not_ mebibytes. Backend uses
|
||||||
* ISO megabytes.
|
* ISO megabytes.
|
||||||
*/
|
*/
|
||||||
export const VIDEO_MAX_SIZE_REDUCED = 1000 * 1000 * 100 // 100mb
|
export const VIDEO_MAX_SIZE_MB = 300
|
||||||
export const VIDEO_MAX_SIZE = 3000 * 1000 * 100 // 300mb
|
export const VIDEO_MAX_SIZE = VIDEO_MAX_SIZE_MB * 1000 * 1000 // 300mb
|
||||||
|
|
||||||
export const SUPPORTED_MIME_TYPES = [
|
export const SUPPORTED_MIME_TYPES = [
|
||||||
'video/mp4',
|
'video/mp4',
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export async function compressVideo(
|
|||||||
opts?: {
|
opts?: {
|
||||||
signal?: AbortSignal
|
signal?: AbortSignal
|
||||||
onProgress?: (progress: number) => void
|
onProgress?: (progress: number) => void
|
||||||
TEMP_enableLargeVideoUploads?: boolean
|
|
||||||
},
|
},
|
||||||
): Promise<CompressedVideo> {
|
): Promise<CompressedVideo> {
|
||||||
const {onProgress, signal} = opts || {}
|
const {onProgress, signal} = opts || {}
|
||||||
|
|||||||
@@ -1,28 +1,22 @@
|
|||||||
import {type ImagePickerAsset} from 'expo-image-picker'
|
import {type ImagePickerAsset} from 'expo-image-picker'
|
||||||
|
|
||||||
import {VIDEO_MAX_SIZE, VIDEO_MAX_SIZE_REDUCED} from '#/lib/constants'
|
import {VIDEO_MAX_SIZE} from '#/lib/constants'
|
||||||
import {VideoTooLargeError} from '#/lib/media/video/errors'
|
import {VideoTooLargeError} from '#/lib/media/video/errors'
|
||||||
import {type CompressedVideo} from './types'
|
import {type CompressedVideo} from './types'
|
||||||
|
|
||||||
// doesn't actually compress, converts to ArrayBuffer
|
// doesn't actually compress, converts to ArrayBuffer
|
||||||
export async function compressVideo(
|
export async function compressVideo(
|
||||||
asset: ImagePickerAsset,
|
asset: ImagePickerAsset,
|
||||||
opts?: {
|
_opts?: {
|
||||||
signal?: AbortSignal
|
signal?: AbortSignal
|
||||||
onProgress?: (progress: number) => void
|
onProgress?: (progress: number) => void
|
||||||
TEMP_enableLargeVideoUploads?: number
|
|
||||||
},
|
},
|
||||||
): Promise<CompressedVideo> {
|
): Promise<CompressedVideo> {
|
||||||
const {mimeType, base64} = parseDataUrl(asset.uri)
|
const {mimeType, base64} = parseDataUrl(asset.uri)
|
||||||
const blob = base64ToBlob(base64, mimeType)
|
const blob = base64ToBlob(base64, mimeType)
|
||||||
const uri = URL.createObjectURL(blob)
|
const uri = URL.createObjectURL(blob)
|
||||||
|
|
||||||
if (
|
if (blob.size > VIDEO_MAX_SIZE) {
|
||||||
blob.size >
|
|
||||||
(opts?.TEMP_enableLargeVideoUploads
|
|
||||||
? VIDEO_MAX_SIZE
|
|
||||||
: VIDEO_MAX_SIZE_REDUCED)
|
|
||||||
) {
|
|
||||||
throw new VideoTooLargeError()
|
throw new VideoTooLargeError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,10 +222,6 @@ export const ComposePost = ({
|
|||||||
const [publishingStage, setPublishingStage] = useState('')
|
const [publishingStage, setPublishingStage] = useState('')
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const enableLargeVideoUploads = ax.features.enabled(
|
|
||||||
ax.features.LargeVideoUploads,
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track when a draft was created so we can measure draft age in metrics.
|
* Track when a draft was created so we can measure draft age in metrics.
|
||||||
* Set when a draft is loaded via handleSelectDraft.
|
* Set when a draft is loaded via handleSelectDraft.
|
||||||
@@ -348,10 +344,9 @@ export const ComposePost = ({
|
|||||||
currentDid,
|
currentDid,
|
||||||
abortController.signal,
|
abortController.signal,
|
||||||
i18n,
|
i18n,
|
||||||
enableLargeVideoUploads,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
[i18n, agent, currentDid, composerDispatch, enableLargeVideoUploads],
|
[i18n, agent, currentDid, composerDispatch],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onInitVideo = useNonReactiveCallback(() => {
|
const onInitVideo = useNonReactiveCallback(() => {
|
||||||
@@ -496,7 +491,6 @@ export const ComposePost = ({
|
|||||||
currentDid,
|
currentDid,
|
||||||
abortController.signal,
|
abortController.signal,
|
||||||
i18n,
|
i18n,
|
||||||
enableLargeVideoUploads,
|
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('Failed to restore video from draft', {
|
logger.error('Failed to restore video from draft', {
|
||||||
@@ -505,7 +499,7 @@ export const ComposePost = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[i18n, agent, currentDid, composerDispatch, enableLargeVideoUploads],
|
[i18n, agent, currentDid, composerDispatch],
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSelectDraft = useCallback(
|
const handleSelectDraft = useCallback(
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import {type ImagePickerAsset} from 'expo-image-picker'
|
|||||||
import {msg, plural} from '@lingui/core/macro'
|
import {msg, plural} from '@lingui/core/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {VIDEO_MAX_DURATION_MS, VIDEO_MAX_SIZE} from '#/lib/constants'
|
import {
|
||||||
|
VIDEO_MAX_DURATION_MS,
|
||||||
|
VIDEO_MAX_SIZE,
|
||||||
|
VIDEO_MAX_SIZE_MB,
|
||||||
|
} from '#/lib/constants'
|
||||||
import {
|
import {
|
||||||
usePhotoLibraryPermission,
|
usePhotoLibraryPermission,
|
||||||
useVideoLibraryPermission,
|
useVideoLibraryPermission,
|
||||||
@@ -431,7 +435,7 @@ export function SelectMediaButton({
|
|||||||
msg`You can only select one GIF at a time.`,
|
msg`You can only select one GIF at a time.`,
|
||||||
),
|
),
|
||||||
[SelectedAssetError.FileTooBig]: _(
|
[SelectedAssetError.FileTooBig]: _(
|
||||||
msg`One or more of your selected files are too large. Maximum size is 100 MB.`,
|
msg`One or more of your selected files are too large. Maximum size is ${VIDEO_MAX_SIZE_MB} MB.`,
|
||||||
),
|
),
|
||||||
}[error]
|
}[error]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {type I18n} from '@lingui/core'
|
|||||||
import {msg} from '@lingui/core/macro'
|
import {msg} from '@lingui/core/macro'
|
||||||
|
|
||||||
import {AbortError} from '#/lib/async/cancelable'
|
import {AbortError} from '#/lib/async/cancelable'
|
||||||
|
import {VIDEO_MAX_SIZE_MB} from '#/lib/constants'
|
||||||
import {compressVideo} from '#/lib/media/video/compress'
|
import {compressVideo} from '#/lib/media/video/compress'
|
||||||
import {
|
import {
|
||||||
ServerError,
|
ServerError,
|
||||||
@@ -264,7 +265,6 @@ export async function processVideo(
|
|||||||
did: string,
|
did: string,
|
||||||
signal: AbortSignal,
|
signal: AbortSignal,
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
TEMP_enableLargeVideoUploads: boolean,
|
|
||||||
) {
|
) {
|
||||||
let video: CompressedVideo | undefined
|
let video: CompressedVideo | undefined
|
||||||
try {
|
try {
|
||||||
@@ -273,14 +273,9 @@ export async function processVideo(
|
|||||||
dispatch({type: 'update_progress', progress: trunc2dp(num), signal})
|
dispatch({type: 'update_progress', progress: trunc2dp(num), signal})
|
||||||
},
|
},
|
||||||
signal,
|
signal,
|
||||||
TEMP_enableLargeVideoUploads,
|
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getCompressErrorMessage(
|
const message = getCompressErrorMessage(e, i18n)
|
||||||
e,
|
|
||||||
i18n,
|
|
||||||
TEMP_enableLargeVideoUploads,
|
|
||||||
)
|
|
||||||
if (message !== null) {
|
if (message !== null) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'to_error',
|
type: 'to_error',
|
||||||
@@ -309,7 +304,7 @@ export async function processVideo(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getUploadErrorMessage(e, i18n, TEMP_enableLargeVideoUploads)
|
const message = getUploadErrorMessage(e, i18n)
|
||||||
if (message !== null) {
|
if (message !== null) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'to_error',
|
type: 'to_error',
|
||||||
@@ -393,30 +388,20 @@ export async function processVideo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCompressErrorMessage(
|
function getCompressErrorMessage(e: unknown, i18n: I18n): string | null {
|
||||||
e: unknown,
|
|
||||||
i18n: I18n,
|
|
||||||
TEMP_enableLargeVideoUploads: boolean,
|
|
||||||
): string | null {
|
|
||||||
const videoSize = TEMP_enableLargeVideoUploads ? 300 : 100
|
|
||||||
if (e instanceof AbortError) {
|
if (e instanceof AbortError) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (e instanceof VideoTooLargeError) {
|
if (e instanceof VideoTooLargeError) {
|
||||||
return i18n._(
|
return i18n._(
|
||||||
msg`The selected video is larger than ${videoSize} MB. Please try again with a smaller file.`,
|
msg`The selected video is larger than ${VIDEO_MAX_SIZE_MB} MB. Please try again with a smaller file.`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
logger.error('Error compressing video', {safeMessage: e})
|
logger.error('Error compressing video', {safeMessage: e})
|
||||||
return i18n._(msg`An error occurred while compressing the video.`)
|
return i18n._(msg`An error occurred while compressing the video.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUploadErrorMessage(
|
function getUploadErrorMessage(e: unknown, i18n: I18n): string | null {
|
||||||
e: unknown,
|
|
||||||
i18n: I18n,
|
|
||||||
TEMP_enableLargeVideoUploads: boolean,
|
|
||||||
): string | null {
|
|
||||||
const videoSize = TEMP_enableLargeVideoUploads ? 300 : 100
|
|
||||||
if (e instanceof AbortError) {
|
if (e instanceof AbortError) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -448,7 +433,7 @@ function getUploadErrorMessage(
|
|||||||
case 'file size (100000001 bytes) is larger than the maximum allowed size (100000000 bytes)':
|
case 'file size (100000001 bytes) is larger than the maximum allowed size (100000000 bytes)':
|
||||||
case 'file size (300000001 bytes) is larger than the maximum allowed size (300000000 bytes)':
|
case 'file size (300000001 bytes) is larger than the maximum allowed size (300000000 bytes)':
|
||||||
return i18n._(
|
return i18n._(
|
||||||
msg`The selected video is larger than ${videoSize} MB. Please try again with a smaller file.`,
|
msg`The selected video is larger than ${VIDEO_MAX_SIZE_MB} MB. Please try again with a smaller file.`,
|
||||||
)
|
)
|
||||||
case 'Confirm your email address to upload videos':
|
case 'Confirm your email address to upload videos':
|
||||||
return i18n._(msg`Please confirm your email address to upload videos.`)
|
return i18n._(msg`Please confirm your email address to upload videos.`)
|
||||||
|
|||||||
Reference in New Issue
Block a user