import { decryptFile, downloadEncryptedMedia, mxcUrlToHttp } from '../../../utils/matrix';
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
import { ModalWide } from '../../../styles/Modal.css';
+import { validBlurHash } from '../../../utils/blurHash';
type RenderViewerProps = {
src: string;
) => {
const mx = useMatrixClient();
const useAuthentication = useMediaAuthentication();
- const blurHash = info?.[MATRIX_BLUR_HASH_PROPERTY_NAME];
+ const blurHash = validBlurHash(info?.[MATRIX_BLUR_HASH_PROPERTY_NAME]);
const [load, setLoad] = useState(false);
const [error, setError] = useState(false);
mxcUrlToHttp,
} from '../../../utils/matrix';
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
+import { validBlurHash } from '../../../utils/blurHash';
type RenderVideoProps = {
title: string;
) => {
const mx = useMatrixClient();
const useAuthentication = useMediaAuthentication();
- const blurHash = info.thumbnail_info?.[MATRIX_BLUR_HASH_PROPERTY_NAME];
+ const blurHash = validBlurHash(info.thumbnail_info?.[MATRIX_BLUR_HASH_PROPERTY_NAME]);
const [load, setLoad] = useState(false);
const [error, setError] = useState(false);
-import { encode } from 'blurhash';
+import { encode, isBlurhashValid } from 'blurhash';
export const encodeBlurHash = (
img: HTMLImageElement | HTMLVideoElement,
const data = context.getImageData(0, 0, canvas.width, canvas.height);
return encode(data.data, data.width, data.height, 4, 4);
};
+
+export const validBlurHash = (hash?: string): string | undefined => {
+ if (typeof hash === 'string') {
+ const validity = isBlurhashValid(hash);
+
+ return validity.result ? hash : undefined;
+ }
+
+ return undefined;
+};