Rename image size constants and require them as params

POST_IMG_MAX no longer described post images, so rename it to the
semantically accurate pair: POST_IMG_MAX_SIZE (4000px/2MB, post images
and pasted URLs) and PROFILE_IMAGES_MAX_SIZE (2000px/1MB, avatars,
banners, onboarding, link thumbnails).

Drop the constant defaults from compressImage, compressIfNeeded, and
getResizedDimensions; callers now pass the appropriate max config object
directly so the size policy lives at the call site. Web avatar/banner
edits now use PROFILE_IMAGES_MAX_SIZE, matching the native profile path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Eric Bailey
2026-06-02 11:44:52 -05:00
parent e14d559a13
commit 736acb8a61
14 changed files with 72 additions and 51 deletions
@@ -3,7 +3,7 @@ import * as MediaLibrary from 'expo-media-library'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {POST_IMG_MAX} from '#/lib/constants'
import {POST_IMG_MAX_SIZE} from '#/lib/constants'
import {useCameraPermission} from '#/lib/hooks/usePermissions'
import {openCamera} from '#/lib/media/picker'
import {logger} from '#/logger'
@@ -35,7 +35,7 @@ export function OpenCameraBtn({disabled, onAdd}: Props) {
}
const img = await openCamera({
aspect: [POST_IMG_MAX.width, POST_IMG_MAX.height],
aspect: [POST_IMG_MAX_SIZE.width, POST_IMG_MAX_SIZE.height],
})
// If we don't have permissions it's fine, we just wont save it. The post itself will still have access to
@@ -16,7 +16,7 @@ import {type PasteEventPayload, TextInputWrapper} from 'expo-paste-input'
import {AppBskyRichtextFacet, RichText} from '@atproto/api'
import {useLingui} from '@lingui/react/macro'
import {POST_IMG_MAX_HIGH_RES} from '#/lib/constants'
import {POST_IMG_MAX_SIZE} from '#/lib/constants'
import {downloadAndResize} from '#/lib/media/manip'
import {isUriImage} from '#/lib/media/util'
import {getMentionAt, insertMentionAt} from '#/lib/strings/mention-manip'
@@ -93,8 +93,8 @@ export function TextInput({
if (isUriImage(feature.uri)) {
const res = await downloadAndResize({
uri: feature.uri,
maxDimension: POST_IMG_MAX_HIGH_RES.width,
maxSize: POST_IMG_MAX_HIGH_RES.size,
maxDimension: POST_IMG_MAX_SIZE.width,
maxSize: POST_IMG_MAX_SIZE.size,
timeout: 15e3,
})
+4 -1
View File
@@ -17,6 +17,7 @@ import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import {useQueryClient} from '@tanstack/react-query'
import {PROFILE_IMAGES_MAX_SIZE} from '#/lib/constants'
import {useHaptics} from '#/lib/haptics'
import {
useCameraPermission,
@@ -394,6 +395,7 @@ let EditableUserAvatar = ({
await openCamera({
aspect: [1, 1],
}),
PROFILE_IMAGES_MAX_SIZE,
),
)
}, [onSelectNewAvatar, requestCameraAccessIfNeeded])
@@ -422,6 +424,7 @@ let EditableUserAvatar = ({
shape: circular ? 'circle' : 'rectangle',
aspectRatio: 1,
}),
PROFILE_IMAGES_MAX_SIZE,
),
)
} else {
@@ -448,7 +451,7 @@ let EditableUserAvatar = ({
const onChangeEditImage = useCallback(
async (image: ComposerImage) => {
const compressed = await compressImage(image)
const compressed = await compressImage(image, PROFILE_IMAGES_MAX_SIZE)
onSelectNewAvatar(compressed)
},
[onSelectNewAvatar],
+4 -1
View File
@@ -6,6 +6,7 @@ import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import {PROFILE_IMAGES_MAX_SIZE} from '#/lib/constants'
import {
useCameraPermission,
usePhotoLibraryPermission,
@@ -62,6 +63,7 @@ export function UserBanner({
await openCamera({
aspect: [3, 1],
}),
PROFILE_IMAGES_MAX_SIZE,
),
)
}, [onSelectNewBanner, requestCameraAccessIfNeeded])
@@ -83,6 +85,7 @@ export function UserBanner({
imageUri: items[0].path,
aspectRatio: 3 / 1,
}),
PROFILE_IMAGES_MAX_SIZE,
),
)
} else {
@@ -108,7 +111,7 @@ export function UserBanner({
const onChangeEditImage = useCallback(
async (image: ComposerImage) => {
const compressed = await compressImage(image)
const compressed = await compressImage(image, PROFILE_IMAGES_MAX_SIZE)
onSelectNewBanner?.(compressed)
},
[onSelectNewBanner],