Refine image url utilities

This commit is contained in:
Sam Becker 2026-02-19 09:33:38 -06:00
parent 1994f3bfba
commit 3b099eef24

View File

@ -100,16 +100,16 @@ const getSuffixFromNextImageSize = (nextSize: NextImageSize) =>
export const getOptimizedPhotoUrl = ( export const getOptimizedPhotoUrl = (
args: Parameters<typeof getNextImageUrlForRequest>[0] & { args: Parameters<typeof getNextImageUrlForRequest>[0] & {
compatibilityMode?: boolean useNextImage?: boolean
}, },
) => { ) => {
const { compatibilityMode = true } = args; const { useNextImage = true } = args;
const suffix = getSuffixFromNextImageSize(args.size); const suffix = getSuffixFromNextImageSize(args.size);
const { const {
urlBase, urlBase,
fileNameBase, fileNameBase,
} = getFileNamePartsFromStorageUrl(args.imageUrl); } = getFileNamePartsFromStorageUrl(args.imageUrl);
return compatibilityMode return useNextImage
? getNextImageUrlForRequest(args) ? getNextImageUrlForRequest(args)
: getOptimizedUrl({ urlBase, fileNameBase, suffix }); : getOptimizedUrl({ urlBase, fileNameBase, suffix });
}; };
@ -117,16 +117,9 @@ export const getOptimizedPhotoUrl = (
// Generate small, low-bandwidth images for quick manipulations such as // Generate small, low-bandwidth images for quick manipulations such as
// generating blur data or image thumbnails for AI text generation // generating blur data or image thumbnails for AI text generation
export const getOptimizedPhotoUrlForManipulation = ( export const getOptimizedPhotoUrlForManipulation = (
imageUrl: string, args: Parameters<typeof getOptimizedPhotoUrl>[0],
addBypassSecret: boolean,
compatibilityMode?: boolean,
) => ) =>
getOptimizedPhotoUrl({ getOptimizedPhotoUrl({ ...args, size: 640 });
imageUrl,
size: 640,
addBypassSecret,
compatibilityMode,
});
export const getOptimizedPhotoUrlForSuffix = ( export const getOptimizedPhotoUrlForSuffix = (
url: string, url: string,
@ -163,11 +156,11 @@ export const getDataUrlsForPhotos = async (
optimizedSuffix: OptimizedSuffix, optimizedSuffix: OptimizedSuffix,
nextImageWidth: NextImageSize, nextImageWidth: NextImageSize,
addBypassSecret: boolean, addBypassSecret: boolean,
) => ): Promise<{ id: string, urlData: string }[]> =>
Promise.all(photos Promise.all(photos
.map(async({ id, url }) => { .map(async({ id, url }) => {
// Check for optimized image first // Check for optimized image first
const optimizedUrl =await getSignedUrlForUrl( const optimizedUrl = await getSignedUrlForUrl(
getOptimizedPhotoUrlForSuffix(url, optimizedSuffix), getOptimizedPhotoUrlForSuffix(url, optimizedSuffix),
'GET', 'GET',
); );
@ -186,7 +179,7 @@ export const getDataUrlsForPhotos = async (
return { id, urlData: nextImageUrlData }; return { id, urlData: nextImageUrlData };
} }
})) }))
.then(urls =>(urls.every(({ urlData }) => Boolean(urlData)) .then(urls => urls.every(({ urlData }) => Boolean(urlData))
? urls ? urls as { id: string, urlData: string }[]
// If any url is undefined, return an empty array // If any url is undefined, return an empty array
: []) as { id: string, urlData: string }[]); : []);