From ab6b7ca69076993cc42f84c7b78777991276a9a3 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Fri, 13 Dec 2024 07:51:54 -0500 Subject: [PATCH] detect if file is encrypted --- .../components/Storage/Files/FilePreview.tsx | 17 ++++++++- explorer/src/utils/file.ts | 36 ++++++++++++------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/explorer/src/components/Storage/Files/FilePreview.tsx b/explorer/src/components/Storage/Files/FilePreview.tsx index 7b678bb9..0855e606 100644 --- a/explorer/src/components/Storage/Files/FilePreview.tsx +++ b/explorer/src/components/Storage/Files/FilePreview.tsx @@ -1,3 +1,4 @@ +import { LockClosedIcon } from '@heroicons/react/24/outline' import { Arguments } from 'components/common/Arguments' import { Spinner } from 'components/common/Spinner' import { GetCidQuery, GetCidQueryVariables } from 'gql/graphql' @@ -16,6 +17,9 @@ type Props = { type PreviewData = { type: string data: ArrayBuffer + isEncrypted: boolean + // eslint-disable-next-line @typescript-eslint/no-explicit-any + uploadOptions: any } export const FilePreview: FC = ({ cid }) => { @@ -31,11 +35,13 @@ export const FilePreview: FC = ({ cid }) => { const fetchData = useCallback(async () => { if (data) { - const { dataArrayBuffer } = extractFileData(data) + const { dataArrayBuffer, isEncrypted, uploadOptions } = extractFileData(data) const fileType = await detectFileType(dataArrayBuffer) setRawData({ type: fileType, data: dataArrayBuffer, + isEncrypted, + uploadOptions, }) } }, [data]) @@ -60,6 +66,15 @@ export const FilePreview: FC = ({ cid }) => { if (!imageSrc) return <> switch (true) { + case rawData?.isEncrypted: + return ( +
+ +

+ No preview available for encrypted files +

+
+ ) case rawData?.type.startsWith('image'): return (