2020-12-15 19:54:35 +01:00
|
|
|
// @flow
|
2022-03-21 17:20:33 +01:00
|
|
|
import { IMAGE_PROXY_URL, THUMBNAIL_CDN_URL, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH, THUMBNAIL_QUALITY } from 'config';
|
2020-12-15 19:54:35 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
thumbnail: ?string,
|
|
|
|
height?: number,
|
|
|
|
width?: number,
|
|
|
|
quality?: number,
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getThumbnailCdnUrl(props: Props) {
|
|
|
|
const { thumbnail, height = THUMBNAIL_HEIGHT, width = THUMBNAIL_WIDTH, quality = THUMBNAIL_QUALITY } = props;
|
|
|
|
|
|
|
|
if (!THUMBNAIL_CDN_URL || !thumbnail) {
|
|
|
|
return thumbnail;
|
|
|
|
}
|
|
|
|
|
2022-03-19 21:04:51 +01:00
|
|
|
if (thumbnail.includes(THUMBNAIL_CDN_URL)) {
|
|
|
|
return thumbnail;
|
2020-12-15 19:54:35 +01:00
|
|
|
}
|
2021-10-07 22:38:56 +02:00
|
|
|
|
2022-03-19 21:04:51 +01:00
|
|
|
if (thumbnail) {
|
|
|
|
return `${THUMBNAIL_CDN_URL}s:${width}:${height}/quality:${quality}/plain/${thumbnail}`;
|
2021-10-07 22:38:56 +02:00
|
|
|
}
|
2020-12-15 19:54:35 +01:00
|
|
|
}
|
2022-03-21 17:20:33 +01:00
|
|
|
|
|
|
|
export function getImageProxyUrl(thumbnail: ?string) {
|
|
|
|
if (thumbnail && !thumbnail.startsWith(THUMBNAIL_CDN_URL) && !thumbnail.startsWith(IMAGE_PROXY_URL)) {
|
|
|
|
return `${IMAGE_PROXY_URL}?${thumbnail}`;
|
|
|
|
}
|
|
|
|
return thumbnail;
|
|
|
|
}
|