fix: update the url in DM to contain fileUrl and encryption key
All checks were successful
Release / build_and_release (push) Successful in 56s

This commit is contained in:
SwiftHawk 2024-04-19 15:57:44 +05:00
parent 89850f881d
commit 9fa3df3850
3 changed files with 46 additions and 4 deletions

View File

@ -1,13 +1,17 @@
import { Box, Button, TextField, Typography } from '@mui/material'
import saveAs from 'file-saver'
import { MuiFileInput } from 'mui-file-input'
import { useState } from 'react'
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'
export const DecryptZip = () => {
const [searchParams] = useSearchParams()
const [selectedFile, setSelectedFile] = useState<File | null>(null)
const [encryptionKey, setEncryptionKey] = useState('')
@ -15,6 +19,36 @@ export const DecryptZip = () => {
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
@ -91,7 +125,11 @@ export const DecryptZip = () => {
</Box>
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleDecrypt} variant='contained'>
<Button
onClick={handleDecrypt}
variant='contained'
disabled={!selectedFile || !encryptionKey}
>
Decrypt
</Button>
</Box>

View File

@ -8,7 +8,7 @@ import { SignDocument } from '../pages/sign'
export const appPrivateRoutes = {
homePage: '/',
decryptZip: '/decrypt-zip',
decryptZip: '/decrypt',
sign: '/sign'
}

View File

@ -2,6 +2,7 @@ import axios from 'axios'
import { EventTemplate } from 'nostr-tools'
import { MetadataController, NostrController } from '../controllers'
import { toast } from 'react-toastify'
import { appPrivateRoutes } from '../routes'
/**
* Uploads a file to a file storage service.
@ -73,7 +74,10 @@ export const sendDM = async (
const initialLine = isSigner
? 'You have been requested for a signature.'
: 'You have received a signed document.'
const content = `${initialLine}\nHere is the URL for the zip file that you can download.\n${fileUrl}\nHowever, this zip file is encrypted and you need to decrypt it using https://app.sigit.io \nEncryption key: ${encryptionKey}`
const decryptionUrl = `http://app.sigit.io${appPrivateRoutes.decryptZip}?file=${fileUrl}&key=${encryptionKey}`
const content = `${initialLine}\nHere is the URL for the zip file that you can download.\n${fileUrl}\nHowever, this zip file is encrypted and you need to decrypt it using ${decryptionUrl}`
// Set up event listener for authentication event
nostrController.on('nsecbunker-auth', (url) => {