fix: unzip and use timeout util

This commit is contained in:
enes 2024-09-13 17:59:58 +02:00
parent 13254fbe06
commit 8b00ef538b

View File

@ -33,7 +33,8 @@ import {
sendNotification, sendNotification,
signEventForMetaFile, signEventForMetaFile,
updateUsersAppData, updateUsersAppData,
findOtherUserMarks findOtherUserMarks,
timeout
} from '../../utils' } from '../../utils'
import { Container } from '../../components/Container' import { Container } from '../../components/Container'
import { DisplayMeta } from './internal/displayMeta' import { DisplayMeta } from './internal/displayMeta'
@ -276,17 +277,10 @@ export const SignPage = () => {
setAuthUrl(url) setAuthUrl(url)
}) })
// Set up timeout promise to handle encryption timeout // decrypt the encryptionKey, with timeout (duration = 60 seconds)
const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => {
reject(new Error('Timeout occurred'))
}, 60000) // Timeout duration = 60 seconds
})
// decrypt the encryptionKey, with timeout
const encryptionKey = await Promise.race([ const encryptionKey = await Promise.race([
nostrController.nip04Decrypt(sender, key), nostrController.nip04Decrypt(sender, key),
timeoutPromise timeout(60000)
]) ])
.then((res) => { .then((res) => {
return res return res
@ -468,20 +462,20 @@ export const SignPage = () => {
const fileNames = Object.values(zip.files) const fileNames = Object.values(zip.files)
.filter((entry) => entry.name.startsWith('files/') && !entry.dir) .filter((entry) => entry.name.startsWith('files/') && !entry.dir)
.map((entry) => entry.name) .map((entry) => entry.name)
.map((entry) => entry.replace(/^files\//, ''))
// generate hashes for all entries in files folder of zipArchive for (const zipFilePath of fileNames) {
// these hashes can be used to verify the originality of files
for (const fileName of fileNames) {
const arrayBuffer = await readContentOfZipEntry( const arrayBuffer = await readContentOfZipEntry(
zip, zip,
fileName, zipFilePath,
'arraybuffer' 'arraybuffer'
) )
const fileName = zipFilePath.replace(/^files\//, '')
if (arrayBuffer) { if (arrayBuffer) {
files[fileName] = await convertToSigitFile(arrayBuffer, fileName) files[fileName] = await convertToSigitFile(arrayBuffer, fileName)
// generate hashes for all entries in files folder of zipArchive
// these hashes can be used to verify the originality of files
const hash = await getHash(arrayBuffer) const hash = await getHash(arrayBuffer)
if (hash) { if (hash) {
fileHashes[fileName] = hash fileHashes[fileName] = hash