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.
This commit is contained in:
Thomas Zarebczan 2022-03-21 12:20:33 -04:00 committed by Thomas Zarebczan
parent 6fa3638c1b
commit b5630f0ed6
7 changed files with 28 additions and 9 deletions

View file

@ -17,6 +17,7 @@ SEARCH_SERVER_API=https://lighthouse.odysee.tv/search
SOCKETY_SERVER_API=wss://sockety.odysee.com/ws SOCKETY_SERVER_API=wss://sockety.odysee.com/ws
RECSYS_ENDPOINT=https://recsys.odysee.tv/v1/lvv RECSYS_ENDPOINT=https://recsys.odysee.tv/v1/lvv
RECSYS_FYP_ENDPOINT=https://recsys.odysee.tv/v1/u RECSYS_FYP_ENDPOINT=https://recsys.odysee.tv/v1/u
IMAGE_PROXY_URL=https://boost.vanwanet.com/index.php
THUMBNAIL_CDN_URL=https://thumbnails.odycdn.com/optimize/ THUMBNAIL_CDN_URL=https://thumbnails.odycdn.com/optimize/
THUMBNAIL_CARDS_CDN_URL=https://cards.odycdn.com/ THUMBNAIL_CARDS_CDN_URL=https://cards.odycdn.com/
LOCALE_API=https://api.odysee.com/legal/requirements LOCALE_API=https://api.odysee.com/legal/requirements
@ -59,7 +60,7 @@ LOGO_WHITE_TEXT=https://thumbnails.odycdn.com/optimize/s:1000:300/quality:85/pla
LOGO_DARK_TEXT=https://thumbnails.odycdn.com/optimize/s:1000:300/quality:85/plain/https://spee.ch/odysee-png:2.png LOGO_DARK_TEXT=https://thumbnails.odycdn.com/optimize/s:1000:300/quality:85/plain/https://spee.ch/odysee-png:2.png
AVATAR_DEFAULT=https://thumbnails.odycdn.com/optimize/s:160:160/quality:85/plain/https://spee.ch/spaceman-png:2.png AVATAR_DEFAULT=https://thumbnails.odycdn.com/optimize/s:160:160/quality:85/plain/https://spee.ch/spaceman-png:2.png
MISSING_THUMB_DEFAULT=https://thumbnails.odycdn.com/optimize/s:390:220/quality:85/plain/https://spee.ch/missing-thumb-png MISSING_THUMB_DEFAULT=https://thumbnails.odycdn.com/optimize/s:390:220/quality:85/plain/https://spee.ch/missing-thumb-png
FAVICON=https://thumbnails.odycdn.com/optimize/s:100:100/quality:85/plain/https://spee.ch/favicon-png:c.png FAVICON=https://odysee.com/public/favicon-spaceman.png
# LOCALE # LOCALE
DEFAULT_LANGUAGE=en DEFAULT_LANGUAGE=en

View file

@ -23,6 +23,7 @@ const config = {
URL: process.env.URL, URL: process.env.URL,
RECSYS_ENDPOINT: process.env.RECSYS_ENDPOINT, RECSYS_ENDPOINT: process.env.RECSYS_ENDPOINT,
RECSYS_FYP_ENDPOINT: process.env.RECSYS_FYP_ENDPOINT, RECSYS_FYP_ENDPOINT: process.env.RECSYS_FYP_ENDPOINT,
IMAGE_PROXY_URL: process.env.IMAGE_PROXY_URL,
THUMBNAIL_CDN_URL: process.env.THUMBNAIL_CDN_URL, THUMBNAIL_CDN_URL: process.env.THUMBNAIL_CDN_URL,
THUMBNAIL_CARDS_CDN_URL: process.env.THUMBNAIL_CARDS_CDN_URL, THUMBNAIL_CARDS_CDN_URL: process.env.THUMBNAIL_CARDS_CDN_URL,
THUMBNAIL_HEIGHT: process.env.THUMBNAIL_HEIGHT, THUMBNAIL_HEIGHT: process.env.THUMBNAIL_HEIGHT,

View file

@ -1,6 +1,7 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { parseURI } from 'util/lbryURI'; import { parseURI } from 'util/lbryURI';
import { getImageProxyUrl } from 'util/thumbnail';
import classnames from 'classnames'; import classnames from 'classnames';
import Gerbil from './gerbil.png'; import Gerbil from './gerbil.png';
import FreezeframeWrapper from 'component/fileThumbnail/FreezeframeWrapper'; import FreezeframeWrapper from 'component/fileThumbnail/FreezeframeWrapper';
@ -95,8 +96,9 @@ function ChannelThumbnail(props: Props) {
}, [doResolveUri, shouldResolve, uri]); }, [doResolveUri, shouldResolve, uri]);
if (isGif && !allowGifs) { if (isGif && !allowGifs) {
const url = getImageProxyUrl(channelThumbnail);
return ( return (
<FreezeframeWrapper src={channelThumbnail} className={classnames('channel-thumbnail', className)}> <FreezeframeWrapper src={url} className={classnames('channel-thumbnail', className)}>
{showMemberBadge && <PremiumBadge {...badgeProps} />} {showMemberBadge && <PremiumBadge {...badgeProps} />}
</FreezeframeWrapper> </FreezeframeWrapper>
); );

View file

@ -198,6 +198,7 @@ export default React.memo<MarkdownProps>(function MarkdownPreview(props: Markdow
// Workaraund of remarkOptions.Fragment // Workaraund of remarkOptions.Fragment
div: React.Fragment, div: React.Fragment,
img: (imgProps) => { img: (imgProps) => {
// getImageProxyUrl() can also be used if we just want to proxy without compression.
const imageCdnUrl = const imageCdnUrl =
getThumbnailCdnUrl({ thumbnail: imgProps.src, width: 0, height: 0, quality: 85 }) || MISSING_THUMB_DEFAULT; getThumbnailCdnUrl({ thumbnail: imgProps.src, width: 0, height: 0, quality: 85 }) || MISSING_THUMB_DEFAULT;
if ((isStakeEnoughForPreview(stakedLevel) || hasMembership) && !isEmote(imgProps.title, imgProps.src)) { if ((isStakeEnoughForPreview(stakedLevel) || hasMembership) && !isEmote(imgProps.title, imgProps.src)) {

View file

@ -1,6 +1,6 @@
// @flow // @flow
import type { Node } from 'react'; import type { Node } from 'react';
import { getThumbnailCdnUrl } from 'util/thumbnail'; import { getImageProxyUrl, getThumbnailCdnUrl } from 'util/thumbnail';
import React from 'react'; import React from 'react';
import FreezeframeWrapper from './FreezeframeWrapper'; import FreezeframeWrapper from './FreezeframeWrapper';
import Placeholder from './placeholder.png'; import Placeholder from './placeholder.png';
@ -36,8 +36,9 @@ function FileThumbnail(props: Props) {
}, [hasResolvedClaim, uri, doResolveUri, passedThumbnail]); }, [hasResolvedClaim, uri, doResolveUri, passedThumbnail]);
if (!allowGifs && isGif) { if (!allowGifs && isGif) {
const url = getImageProxyUrl(thumbnail);
return ( return (
<FreezeframeWrapper src={thumbnail} className={classnames('media__thumb', className)}> <FreezeframeWrapper src={url} className={classnames('media__thumb', className)}>
{children} {children}
</FreezeframeWrapper> </FreezeframeWrapper>
); );
@ -48,8 +49,12 @@ function FileThumbnail(props: Props) {
let url = thumbnail || (hasResolvedClaim ? Placeholder : ''); let url = thumbnail || (hasResolvedClaim ? Placeholder : '');
// @if TARGET='web' // @if TARGET='web'
// Pass image urls through a compression proxy // Pass image urls through a compression proxy
if (thumbnail && !(isGif && allowGifs)) { if (thumbnail) {
url = getThumbnailCdnUrl({ thumbnail }); if (isGif) {
url = getImageProxyUrl(thumbnail); // Note: the '!allowGifs' case is handled in Freezeframe above.
} else {
url = getThumbnailCdnUrl({ thumbnail });
}
} }
// @endif // @endif

View file

@ -1,6 +1,6 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { getThumbnailCdnUrl } from 'util/thumbnail'; import { getImageProxyUrl, getThumbnailCdnUrl } from 'util/thumbnail';
function scaleToDevicePixelRatio(value: number) { function scaleToDevicePixelRatio(value: number) {
const devicePixelRatio = window.devicePixelRatio || 1.0; const devicePixelRatio = window.devicePixelRatio || 1.0;
@ -12,7 +12,9 @@ function getOptimizedImgUrl(url, width, height, quality) {
if (url && !url.startsWith('/public/')) { if (url && !url.startsWith('/public/')) {
optimizedUrl = url.trim().replace(/^http:\/\//i, 'https://'); optimizedUrl = url.trim().replace(/^http:\/\//i, 'https://');
if (!optimizedUrl.endsWith('.gif')) { if (optimizedUrl.endsWith('.gif')) {
optimizedUrl = getImageProxyUrl(optimizedUrl);
} else {
optimizedUrl = getThumbnailCdnUrl({ thumbnail: optimizedUrl, width, height, quality }); optimizedUrl = getThumbnailCdnUrl({ thumbnail: optimizedUrl, width, height, quality });
} }
} }

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { THUMBNAIL_CDN_URL, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH, THUMBNAIL_QUALITY } from 'config'; import { IMAGE_PROXY_URL, THUMBNAIL_CDN_URL, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH, THUMBNAIL_QUALITY } from 'config';
type Props = { type Props = {
thumbnail: ?string, thumbnail: ?string,
@ -23,3 +23,10 @@ export function getThumbnailCdnUrl(props: Props) {
return `${THUMBNAIL_CDN_URL}s:${width}:${height}/quality:${quality}/plain/${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;
}