mirror of
https://github.com/vercel/commerce.git
synced 2025-06-17 20:51:21 +00:00
23 lines
567 B
TypeScript
23 lines
567 B
TypeScript
import { SpreeProductImage } from '../types';
|
|
import getImageUrl from './get-image-url';
|
|
|
|
const createGetAbsoluteImageUrl =
|
|
(host: string, useOriginalImageSize: boolean = true) =>
|
|
(image: SpreeProductImage, minWidth: number, minHeight: number): string | null => {
|
|
let url;
|
|
|
|
if (useOriginalImageSize) {
|
|
url = image.attributes.transformed_url || null;
|
|
} else {
|
|
url = getImageUrl(image, minWidth, minHeight);
|
|
}
|
|
|
|
if (url === null) {
|
|
return null;
|
|
}
|
|
|
|
return `${host}${url}`;
|
|
};
|
|
|
|
export default createGetAbsoluteImageUrl;
|