mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00

* Adjust editor config Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Erik Michelson <github@erik.michelson.eu>
33 lines
973 B
TypeScript
33 lines
973 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import React, { useEffect, useState } from 'react'
|
|
import { useSelector } from 'react-redux'
|
|
import { getProxiedUrl } from '../../../../api/media'
|
|
import { ApplicationState } from '../../../../redux'
|
|
|
|
export const ProxyImageFrame: React.FC<React.ImgHTMLAttributes<HTMLImageElement>> = (
|
|
{
|
|
src,
|
|
title,
|
|
alt,
|
|
...props
|
|
}) => {
|
|
const [imageUrl, setImageUrl] = useState('')
|
|
const imageProxyEnabled = useSelector((state: ApplicationState) => state.config.useImageProxy)
|
|
|
|
useEffect(() => {
|
|
if (!imageProxyEnabled || !src) {
|
|
return
|
|
}
|
|
getProxiedUrl(src)
|
|
.then(proxyResponse => setImageUrl(proxyResponse.src))
|
|
.catch(err => console.error(err))
|
|
}, [imageProxyEnabled, src])
|
|
|
|
return <img src={ imageProxyEnabled ? imageUrl : (src ?? '') } title={ title ?? alt ?? '' } alt={ alt } { ...props }/>
|
|
}
|
|
|