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:
@@ -21,6 +21,7 @@ import {sha256} from 'js-sha256'
|
||||
import {CID} from 'multiformats/cid'
|
||||
import * as Hasher from 'multiformats/hashes/hasher'
|
||||
|
||||
import {POST_IMG_MAX_SIZE} from '#/lib/constants'
|
||||
import {isNetworkError} from '#/lib/strings/errors'
|
||||
import {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip'
|
||||
import {logger} from '#/logger'
|
||||
@@ -323,7 +324,10 @@ async function resolveMedia(
|
||||
const images: AppBskyEmbedImages.Image[] = await Promise.all(
|
||||
imagesDraft.map(async (image, i) => {
|
||||
logger.debug(`Compressing image #${i}`)
|
||||
const {path, width, height, mime} = await compressImage(image)
|
||||
const {path, width, height, mime} = await compressImage(
|
||||
image,
|
||||
POST_IMG_MAX_SIZE,
|
||||
)
|
||||
logger.debug(`Uploading image #${i}`)
|
||||
const res = await uploadBlob(agent, path, mime)
|
||||
return {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/api'
|
||||
|
||||
import {POST_IMG_MAX} from '#/lib/constants'
|
||||
import {PROFILE_IMAGES_MAX_SIZE} from '#/lib/constants'
|
||||
import {getLinkMeta, type LinkMeta} from '#/lib/link-meta/link-meta'
|
||||
import {resolveShortLink} from '#/lib/link-meta/resolve-short-link'
|
||||
import {downloadAndResize} from '#/lib/media/manip'
|
||||
@@ -257,8 +257,8 @@ export async function imageToThumb(
|
||||
try {
|
||||
const img = await downloadAndResize({
|
||||
uri: imageUri,
|
||||
maxDimension: POST_IMG_MAX.width,
|
||||
maxSize: POST_IMG_MAX.size,
|
||||
maxDimension: PROFILE_IMAGES_MAX_SIZE.width,
|
||||
maxSize: PROFILE_IMAGES_MAX_SIZE.size,
|
||||
timeout: 15e3,
|
||||
})
|
||||
if (img) {
|
||||
|
||||
Reference in New Issue
Block a user