lbry-desktop/ui/util/thumbnail.js
infinite-persistence ed2b5ff1d7
Avoid extra redirect with spee.ch images
I'm not sure what's the history behind splitting the logic between speech and non-speech, but currently, doing

`${thumbnail}?quality=${quality}&height=${height}&width=${width}`

will result in a redirect to

`${THUMBNAIL_CDN_URL}s:${width}:${height}/quality:80/plain/${thumbnail}` (hardcoded to 80).

That's the same CDN url we use for non-speech, so might as do the same for all images to avoid the redirect.
2021-07-24 11:06:04 +08:00

25 lines
593 B
JavaScript

// @flow
import { THUMBNAIL_CDN_URL } from 'config';
const THUMBNAIL_HEIGHT = 220;
const THUMBNAIL_WIDTH = 390;
const THUMBNAIL_QUALITY = 85;
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) {
return `${THUMBNAIL_CDN_URL}s:${width}:${height}/quality:${quality}/plain/${thumbnail}`;
}
}