lbry-desktop/ui/util/thumbnail.js
Thomas Zarebczan b5630f0ed6 Load gifs through proxy
Continuation of 1009 (2eae20f0)

It can probably be handled inside the existing getThumbnailCdnUrl to reduce 1 function, but since the functionality is somewhat different (the proxy doesn't compress), it's probably clearer to separate it.
2022-03-21 13:13:25 -04:00

32 lines
881 B
JavaScript

// @flow
import { IMAGE_PROXY_URL, THUMBNAIL_CDN_URL, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH, THUMBNAIL_QUALITY } from 'config';
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;
}
if (thumbnail.includes(THUMBNAIL_CDN_URL)) {
return thumbnail;
}
if (thumbnail) {
return `${THUMBNAIL_CDN_URL}s:${width}:${height}/quality:${quality}/plain/${thumbnail}`;
}
}
export function getImageProxyUrl(thumbnail: ?string) {
if (thumbnail && !thumbnail.startsWith(THUMBNAIL_CDN_URL) && !thumbnail.startsWith(IMAGE_PROXY_URL)) {
return `${IMAGE_PROXY_URL}?${thumbnail}`;
}
return thumbnail;
}