import styles from './text.module.css' import { Fragment, useState, useEffect, useMemo, useCallback, forwardRef, useRef, memo } from 'react' import { IMGPROXY_URL_REGEXP, MEDIA_DOMAIN_REGEXP } from '@/lib/url' import { useShowModal } from './modal' import { useMe } from './me' import { Dropdown } from 'react-bootstrap' import { UNKNOWN_LINK_REL, UPLOAD_TYPES_ALLOW, MEDIA_URL } from '@/lib/constants' import { useToast } from './toast' import gql from 'graphql-tag' import { useMutation } from '@apollo/client' import piexif from 'piexifjs' export function decodeOriginalUrl (imgproxyUrl) { const parts = imgproxyUrl.split('/') // base64url is not a known encoding in browsers // so we need to replace the invalid chars const b64Url = parts[parts.length - 1].replace(/-/g, '+').replace(/_/, '/') const originalUrl = Buffer.from(b64Url, 'base64').toString('utf-8') return originalUrl } function LinkRaw ({ href, children, src, rel, onClick, ...props }) { const isRawURL = /^https?:\/\//.test(children?.[0]) return ( // eslint-disable-next-line {isRawURL || !children ? src : children} ) } function ImageOriginal ({ src, topLevel, tab, onClick, ...props }) { const me = useMe() const [showImage, setShowImage] = useState(false) const [showVideo, setShowVideo] = useState(false) useEffect(() => { // make sure it's not a false negative by trying to load URL as const img = new window.Image() img.onload = () => setShowImage(true) img.src = src const video = document.createElement('video') video.onloadeddata = () => setShowVideo(true) video.src = src return () => { img.onload = null img.src = '' video.onloadeddata = null video.src = '' } }, [src, showImage]) const showMedia = (tab === 'preview' || (me?.privates?.showImagesAndVideos !== false && !me?.privates?.imgproxyOnly)) if (showImage && showMedia) { return ( onClick(src)} onError={() => setShowImage(false)} /> ) } else if (showVideo && showMedia) { return