2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-01-29 17:38:46 +01:00
|
|
|
import type { Node } from 'react';
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2020-05-28 19:07:04 +02:00
|
|
|
import FreezeframeWrapper from './FreezeframeWrapper';
|
2019-03-05 05:46:57 +01:00
|
|
|
import Placeholder from './placeholder.png';
|
2017-07-14 01:18:28 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
thumbnail: ?string, // externally sourced image
|
2020-01-29 17:38:46 +01:00
|
|
|
children?: Node,
|
2020-05-29 19:26:06 +02:00
|
|
|
allowGifs: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2018-01-09 02:15:44 +01:00
|
|
|
|
2019-10-06 07:47:08 +02:00
|
|
|
const className = 'media__thumb';
|
|
|
|
|
2020-05-28 19:07:04 +02:00
|
|
|
class FileThumbnail extends React.PureComponent<Props> {
|
2017-07-14 01:18:28 +02:00
|
|
|
render() {
|
2020-06-08 15:16:56 +02:00
|
|
|
const { thumbnail: rawThumbnail, children, allowGifs = false } = this.props;
|
|
|
|
const thumbnail = rawThumbnail && rawThumbnail.trim().replace(/^http:\/\//i, 'https://');
|
2017-07-14 01:18:28 +02:00
|
|
|
|
2020-05-29 19:26:06 +02:00
|
|
|
if (!allowGifs && thumbnail && thumbnail.endsWith('gif')) {
|
2020-05-28 19:07:04 +02:00
|
|
|
return <FreezeframeWrapper src={thumbnail} className={className} />;
|
|
|
|
}
|
|
|
|
|
2019-11-13 18:50:45 +01:00
|
|
|
let url;
|
|
|
|
// @if TARGET='web'
|
|
|
|
// Pass image urls through a compression proxy
|
2020-01-15 00:03:49 +01:00
|
|
|
url = thumbnail || Placeholder;
|
|
|
|
// url = thumbnail
|
|
|
|
// ? 'https://ext.thumbnails.lbry.com/400x,q55/' +
|
|
|
|
// // The image server will redirect if we don't remove the double slashes after http(s)
|
|
|
|
// thumbnail.replace('https://', 'https:/').replace('http://', 'http:/')
|
|
|
|
// : Placeholder;
|
2019-11-13 18:50:45 +01:00
|
|
|
// @endif
|
|
|
|
// @if TARGET='app'
|
|
|
|
url = thumbnail || Placeholder;
|
|
|
|
// @endif
|
|
|
|
|
2020-01-29 17:38:46 +01:00
|
|
|
return (
|
|
|
|
<div style={{ backgroundImage: `url('${url.replace(/'/g, "\\'")}')` }} className={className}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
2017-07-14 01:18:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 19:07:04 +02:00
|
|
|
export default FileThumbnail;
|