diff --git a/src/pages/decrypt/index.tsx b/src/pages/decrypt/index.tsx deleted file mode 100644 index 6b20491..0000000 --- a/src/pages/decrypt/index.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import { Box, Button, TextField, Typography } from '@mui/material' -import saveAs from 'file-saver' -import { MuiFileInput } from 'mui-file-input' -import { useEffect, useState } from 'react' -import { LoadingSpinner } from '../../components/LoadingSpinner' -import { decryptArrayBuffer } from '../../utils' -import styles from './style.module.scss' -import { toast } from 'react-toastify' -import { useSearchParams } from 'react-router-dom' -import axios from 'axios' -import { DecryptionError } from '../../types/errors/DecryptionError' - -export const DecryptZip = () => { - const [searchParams] = useSearchParams() - - const [selectedFile, setSelectedFile] = useState(null) - const [encryptionKey, setEncryptionKey] = useState('') - - const [isLoading, setIsLoading] = useState(false) - const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('') - const [isDraggingOver, setIsDraggingOver] = useState(false) - - useEffect(() => { - const fileUrl = searchParams.get('file') - - if (fileUrl) { - setIsLoading(true) - setLoadingSpinnerDesc('Fetching zip file') - axios - .get(fileUrl, { - responseType: 'arraybuffer' - }) - .then((res) => { - const fileName = fileUrl.split('/').pop() - const file = new File([res.data], fileName!) - setSelectedFile(file) - }) - .catch((err) => { - console.error( - `error occurred in getting zip file from ${fileUrl}`, - err - ) - }) - .finally(() => { - setIsLoading(false) - }) - } - - const key = searchParams.get('key') - if (key) setEncryptionKey(key) - }, [searchParams]) - - const handleDecrypt = async () => { - if (!selectedFile || !encryptionKey) return - - setIsLoading(true) - setLoadingSpinnerDesc('Decrypting zip file') - - const encryptedArrayBuffer = await selectedFile.arrayBuffer() - - const arrayBuffer = await decryptArrayBuffer( - encryptedArrayBuffer, - encryptionKey - ).catch((err: DecryptionError) => { - console.log('err in decryption:>> ', err) - - toast.error(err.message) - setIsLoading(false) - return null - }) - - if (!arrayBuffer) return - - const blob = new Blob([arrayBuffer]) - saveAs(blob, 'decrypted.zip') - - setIsLoading(false) - } - - const handleDrop = (event: React.DragEvent) => { - event.preventDefault() - setIsDraggingOver(false) - const file = event.dataTransfer.files[0] - if (file.type === 'application/zip') setSelectedFile(file) - } - - const handleDragOver = (event: React.DragEvent) => { - event.preventDefault() - setIsDraggingOver(true) - } - - return ( - <> - {isLoading && } - - - Select encrypted zip file - - - - {isDraggingOver && ( - - Drop file here - - )} - setSelectedFile(value)} - InputProps={{ - inputProps: { - accept: '.zip' - } - }} - /> - - setEncryptionKey(e.target.value)} - /> - - - - - - - - ) -} diff --git a/src/pages/decrypt/style.module.scss b/src/pages/decrypt/style.module.scss deleted file mode 100644 index ae72e77..0000000 --- a/src/pages/decrypt/style.module.scss +++ /dev/null @@ -1,27 +0,0 @@ -@import '../../colors.scss'; - -.container { - display: flex; - flex-direction: column; - color: $text-color; - - .inputBlock { - position: relative; - display: flex; - flex-direction: column; - gap: 25px; - } - - .fileDragOver { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - background-color: rgba(255, 255, 255, 0.8); - z-index: 1; - display: flex; - justify-content: center; - align-items: center; - } -}