Revert "chore: prettier"

This reverts commit 7e420ef583.
This commit is contained in:
eugene 2024-08-07 17:54:45 +03:00
parent 7e420ef583
commit 8d683de88c
22 changed files with 387 additions and 549 deletions

View File

@ -1,43 +1,15 @@
import {
AccessTime,
CalendarMonth,
ExpandMore,
Gesture,
PictureAsPdf,
Badge,
Work,
Close
} from '@mui/icons-material'
import {
Box,
Typography,
Accordion,
AccordionDetails,
AccordionSummary,
CircularProgress,
FormControl,
InputLabel,
MenuItem,
Select
} from '@mui/material'
import { AccessTime, CalendarMonth, ExpandMore, Gesture, PictureAsPdf, Badge, Work, Close } from '@mui/icons-material'
import { Box, Typography, Accordion, AccordionDetails, AccordionSummary, CircularProgress, FormControl, InputLabel, MenuItem, Select } from '@mui/material'
import styles from './style.module.scss'
import { useEffect, useState } from 'react'
import * as PDFJS from 'pdfjs-dist'
import { ProfileMetadata, User } from '../../types'
import {
PdfFile,
DrawTool,
MouseState,
PdfPage,
DrawnField,
MarkType
} from '../../types/drawing'
import { truncate } from 'lodash'
import { hexToNpub } from '../../utils'
import * as PDFJS from "pdfjs-dist";
import { ProfileMetadata, User } from '../../types';
import { PdfFile, DrawTool, MouseState, PdfPage, DrawnField, MarkType } from '../../types/drawing';
import { truncate } from 'lodash';
import { hexToNpub } from '../../utils';
import { toPdfFiles } from '../../utils/pdf.ts'
PDFJS.GlobalWorkerOptions.workerSrc =
'node_modules/pdfjs-dist/build/pdf.worker.mjs'
PDFJS.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.mjs';
interface Props {
selectedFiles: File[]
@ -60,6 +32,7 @@ export const DrawPDFFields = (props: Props) => {
icon: <Gesture/>,
label: 'Signature',
active: false
},
{
identifier: MarkType.FULLNAME,
@ -84,7 +57,7 @@ export const DrawPDFFields = (props: Props) => {
icon: <AccessTime/>,
label: 'Datetime',
active: false
}
},
])
const [mouseState, setMouseState] = useState<MouseState>({
@ -110,11 +83,11 @@ export const DrawPDFFields = (props: Props) => {
*/
useEffect(() => {
// window.addEventListener('mousedown', onMouseDown);
window.addEventListener('mouseup', onMouseUp)
window.addEventListener('mouseup', onMouseUp);
return () => {
// window.removeEventListener('mousedown', onMouseDown);
window.removeEventListener('mouseup', onMouseUp)
window.removeEventListener('mouseup', onMouseUp);
}
}, [])
@ -239,10 +212,7 @@ export const DrawPDFFields = (props: Props) => {
*/
const onDranwFieldMouseMove = (event: any, drawnField: DrawnField) => {
if (mouseState.dragging) {
const { mouseX, mouseY, rect } = getMouseCoordinates(
event,
event.target.parentNode
)
const { mouseX, mouseY, rect } = getMouseCoordinates(event, event.target.parentNode)
const coordsOffset = mouseState.coordsInWrapper
if (coordsOffset) {
@ -288,10 +258,7 @@ export const DrawPDFFields = (props: Props) => {
*/
const onResizeHandleMouseMove = (event: any, drawnField: DrawnField) => {
if (mouseState.resizing) {
const { mouseX, mouseY } = getMouseCoordinates(
event,
event.target.parentNode.parentNode
)
const { mouseX, mouseY } = getMouseCoordinates(event, event.target.parentNode.parentNode)
const width = mouseX - drawnField.left
const height = mouseY - drawnField.top
@ -310,18 +277,10 @@ export const DrawPDFFields = (props: Props) => {
* @param pdfPageIndex pdf page index
* @param drawnFileIndex drawn file index
*/
const onRemoveHandleMouseDown = (
event: any,
pdfFileIndex: number,
pdfPageIndex: number,
drawnFileIndex: number
) => {
const onRemoveHandleMouseDown = (event: any, pdfFileIndex: number, pdfPageIndex: number, drawnFileIndex: number) => {
event.stopPropagation()
pdfFiles[pdfFileIndex].pages[pdfPageIndex].drawnFields.splice(
drawnFileIndex,
1
)
pdfFiles[pdfFileIndex].pages[pdfPageIndex].drawnFields.splice(drawnFileIndex, 1)
}
/**
@ -341,9 +300,9 @@ export const DrawPDFFields = (props: Props) => {
*/
const getMouseCoordinates = (event: any, customTarget?: any) => {
const target = customTarget ? customTarget : event.target
const rect = target.getBoundingClientRect()
const mouseX = event.clientX - rect.left //x position within the element.
const mouseY = event.clientY - rect.top //y position within the element.
const rect = target.getBoundingClientRect();
const mouseX = event.clientX - rect.left; //x position within the element.
const mouseY = event.clientY - rect.top; //y position within the element.
return {
mouseX,
@ -357,7 +316,7 @@ export const DrawPDFFields = (props: Props) => {
* creates the pdfFiles object and sets to a state
*/
const parsePdfPages = async () => {
const pdfFiles: PdfFile[] = await toPdfFiles(selectedFiles)
const pdfFiles: PdfFile[] = await toPdfFiles(selectedFiles);
setPdfFiles(pdfFiles)
}
@ -367,7 +326,7 @@ export const DrawPDFFields = (props: Props) => {
* @returns if expanded pdf accordion is present
*/
const hasExpandedPdf = () => {
return !!pdfFiles.filter((pdfFile) => !!pdfFile.expanded).length
return !!pdfFiles.filter(pdfFile => !!pdfFile.expanded).length
}
const handleAccordionExpandChange = (expanded: boolean, pdfFile: PdfFile) => {
@ -396,11 +355,9 @@ export const DrawPDFFields = (props: Props) => {
*/
const getPdfPages = (pdfFile: PdfFile, pdfFileIndex: number) => {
return (
<Box
sx={{
<Box sx={{
width: '100%'
}}
>
}}>
{pdfFile.pages.map((page, pdfPageIndex: number) => {
return (
<div
@ -410,27 +367,17 @@ export const DrawPDFFields = (props: Props) => {
marginBottom: '10px'
}}
className={`${styles.pdfImageWrapper} ${selectedTool ? styles.drawing : ''}`}
onMouseMove={(event) => {
onMouseMove(event, page)
}}
onMouseDown={(event) => {
onMouseDown(event, page)
}}
onMouseMove={(event) => {onMouseMove(event, page)}}
onMouseDown={(event) => {onMouseDown(event, page)}}
>
<img
draggable="false"
style={{ width: '100%' }}
src={page.image}
/>
<img draggable="false" style={{ width: '100%' }} src={page.image}/>
{page.drawnFields.map((drawnField, drawnFieldIndex: number) => {
return (
<div
key={drawnFieldIndex}
onMouseDown={onDrawnFieldMouseDown}
onMouseMove={(event) => {
onDranwFieldMouseMove(event, drawnField)
}}
onMouseMove={(event) => { onDranwFieldMouseMove(event, drawnField)}}
className={styles.drawingRectangle}
style={{
left: `${drawnField.left}px`,
@ -442,68 +389,41 @@ export const DrawPDFFields = (props: Props) => {
>
<span
onMouseDown={onResizeHandleMouseDown}
onMouseMove={(event) => {
onResizeHandleMouseMove(event, drawnField)
}}
onMouseMove={(event) => {onResizeHandleMouseMove(event, drawnField)}}
className={styles.resizeHandle}
></span>
<span
onMouseDown={(event) => {
onRemoveHandleMouseDown(
event,
pdfFileIndex,
pdfPageIndex,
drawnFieldIndex
)
}}
onMouseDown={(event) => {onRemoveHandleMouseDown(event, pdfFileIndex, pdfPageIndex, drawnFieldIndex)}}
className={styles.removeHandle}
>
<Close fontSize="small" />
<Close fontSize='small'/>
</span>
<div
onMouseDown={onUserSelectHandleMouseDown}
className={styles.userSelect}
>
<FormControl fullWidth size="small">
<FormControl fullWidth size='small'>
<InputLabel id="counterparts">Counterpart</InputLabel>
<Select
value={drawnField.counterpart}
onChange={(event) => {
drawnField.counterpart = event.target.value
refreshPdfFiles()
}}
onChange={(event) => { drawnField.counterpart = event.target.value; refreshPdfFiles() }}
labelId="counterparts"
label="Counterparts"
>
{props.users.map((user, index) => {
let displayValue = truncate(
hexToNpub(user.pubkey),
{
let displayValue = truncate(hexToNpub(user.pubkey), {
length: 16
}
)
})
const metadata = props.metadata[user.pubkey]
if (metadata) {
displayValue = truncate(
metadata.name ||
metadata.display_name ||
metadata.username,
{
displayValue = truncate(metadata.name || metadata.display_name || metadata.username, {
length: 16
}
)
})
}
return (
<MenuItem
key={index}
value={hexToNpub(user.pubkey)}
>
{displayValue}
</MenuItem>
)
return <MenuItem key={index} value={hexToNpub(user.pubkey)}>{displayValue}</MenuItem>
})}
</Select>
</FormControl>
@ -537,13 +457,7 @@ export const DrawPDFFields = (props: Props) => {
{pdfFiles.map((pdfFile, pdfFileIndex: number) => {
return (
<Accordion
key={pdfFileIndex}
expanded={pdfFile.expanded}
onChange={(_event, expanded) => {
handleAccordionExpandChange(expanded, pdfFile)
}}
>
<Accordion key={pdfFileIndex} expanded={pdfFile.expanded} onChange={(_event, expanded) => {handleAccordionExpandChange(expanded, pdfFile)}}>
<AccordionSummary
expandIcon={<ExpandMore />}
aria-controls={`panel${pdfFileIndex}-content`}
@ -563,17 +477,11 @@ export const DrawPDFFields = (props: Props) => {
{showDrawToolBox && (
<Box className={styles.drawToolBoxContainer}>
<Box className={styles.drawToolBox}>
{toolbox
.filter((drawTool) => drawTool.active)
.map((drawTool: DrawTool, index: number) => {
{toolbox.filter(drawTool => drawTool.active).map((drawTool: DrawTool, index: number) => {
return (
<Box
key={index}
onClick={() => {
handleToolSelect(drawTool)
}}
className={`${styles.toolItem} ${selectedTool?.identifier === drawTool.identifier ? styles.selected : ''}`}
>
onClick={() => {handleToolSelect(drawTool)}} className={`${styles.toolItem} ${selectedTool?.identifier === drawTool.identifier ? styles.selected : ''}`}>
{ drawTool.icon }
{ drawTool.label }
</Box>

View File

@ -1,6 +1,6 @@
import { PdfFile } from '../../types/drawing.ts'
import { CurrentUserMark } from '../../types/mark.ts'
import PdfPageItem from './PdfPageItem.tsx'
import PdfPageItem from './PdfPageItem.tsx';
interface PdfItemProps {
pdfFile: PdfFile
@ -13,20 +13,12 @@ interface PdfItemProps {
/**
* Responsible for displaying pages of a single Pdf File.
*/
const PdfItem = ({
pdfFile,
currentUserMarks,
handleMarkClick,
selectedMarkValue,
selectedMark
}: PdfItemProps) => {
const filterByPage = (
marks: CurrentUserMark[],
page: number
): CurrentUserMark[] => {
return marks.filter((m) => m.mark.location.page === page)
const PdfItem = ({ pdfFile, currentUserMarks, handleMarkClick, selectedMarkValue, selectedMark }: PdfItemProps) => {
const filterByPage = (marks: CurrentUserMark[], page: number): CurrentUserMark[] => {
return marks.filter((m) => m.mark.location.page === page);
}
return pdfFile.pages.map((page, i) => {
return (
pdfFile.pages.map((page, i) => {
return (
<PdfPageItem
page={page}
@ -37,7 +29,7 @@ const PdfItem = ({
selectedMark={selectedMark}
/>
)
})
}))
}
export default PdfItem

View File

@ -12,18 +12,14 @@ interface PdfMarkItemProps {
/**
* Responsible for display an individual Pdf Mark.
*/
const PdfMarkItem = ({
selectedMark,
handleMarkClick,
selectedMarkValue,
userMark
}: PdfMarkItemProps) => {
const { location } = userMark.mark
const handleClick = () => handleMarkClick(userMark.mark.id)
const getMarkValue = () =>
const PdfMarkItem = ({ selectedMark, handleMarkClick, selectedMarkValue, userMark }: PdfMarkItemProps) => {
const { location } = userMark.mark;
const handleClick = () => handleMarkClick(userMark.mark.id);
const getMarkValue = () => (
selectedMark?.mark.id === userMark.mark.id
? selectedMarkValue
: userMark.mark.value
)
return (
<div
onClick={handleClick}
@ -34,9 +30,7 @@ const PdfMarkItem = ({
width: inPx(location.width),
height: inPx(location.height)
}}
>
{getMarkValue()}
</div>
>{getMarkValue()}</div>
)
}

View File

@ -6,17 +6,17 @@ import React, { useState, useEffect } from 'react'
import {
findNextCurrentUserMark,
isCurrentUserMarksComplete,
updateCurrentUserMarks
updateCurrentUserMarks,
} from '../../utils'
import { EMPTY } from '../../utils/const.ts'
import { Container } from '../Container'
import styles from '../../pages/sign/style.module.scss'
interface PdfMarkingProps {
files: { pdfFile: PdfFile; filename: string; hash: string | null }[]
currentUserMarks: CurrentUserMark[]
setIsReadyToSign: (isReadyToSign: boolean) => void
setCurrentUserMarks: (currentUserMarks: CurrentUserMark[]) => void
files: { pdfFile: PdfFile, filename: string, hash: string | null }[],
currentUserMarks: CurrentUserMark[],
setIsReadyToSign: (isReadyToSign: boolean) => void,
setCurrentUserMarks: (currentUserMarks: CurrentUserMark[]) => void,
setUpdatedMarks: (markToUpdate: Mark) => void
}
@ -35,21 +35,21 @@ const PdfMarking = (props: PdfMarkingProps) => {
setUpdatedMarks
} = props
const [selectedMark, setSelectedMark] = useState<CurrentUserMark | null>(null)
const [selectedMarkValue, setSelectedMarkValue] = useState<string>('')
const [selectedMarkValue, setSelectedMarkValue] = useState<string>("")
useEffect(() => {
setSelectedMark(findNextCurrentUserMark(currentUserMarks) || null)
}, [currentUserMarks])
const handleMarkClick = (id: number) => {
const nextMark = currentUserMarks.find((mark) => mark.mark.id === id)
setSelectedMark(nextMark!)
setSelectedMarkValue(nextMark?.mark.value ?? EMPTY)
const nextMark = currentUserMarks.find((mark) => mark.mark.id === id);
setSelectedMark(nextMark!);
setSelectedMarkValue(nextMark?.mark.value ?? EMPTY);
}
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
if (!selectedMarkValue || !selectedMark) return
event.preventDefault();
if (!selectedMarkValue || !selectedMark) return;
const updatedMark: CurrentUserMark = {
...selectedMark,
@ -61,10 +61,7 @@ const PdfMarking = (props: PdfMarkingProps) => {
}
setSelectedMarkValue(EMPTY)
const updatedCurrentUserMarks = updateCurrentUserMarks(
currentUserMarks,
updatedMark
)
const updatedCurrentUserMarks = updateCurrentUserMarks(currentUserMarks, updatedMark);
setCurrentUserMarks(updatedCurrentUserMarks)
setSelectedMark(findNextCurrentUserMark(updatedCurrentUserMarks) || null)
console.log(isCurrentUserMarksComplete(updatedCurrentUserMarks))
@ -72,22 +69,22 @@ const PdfMarking = (props: PdfMarkingProps) => {
setUpdatedMarks(updatedMark.mark)
}
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) =>
setSelectedMarkValue(event.target.value)
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => setSelectedMarkValue(event.target.value)
return (
<>
<Container className={styles.container}>
{currentUserMarks?.length > 0 && (
{
currentUserMarks?.length > 0 && (
<PdfView
files={files}
handleMarkClick={handleMarkClick}
selectedMarkValue={selectedMarkValue}
selectedMark={selectedMark}
currentUserMarks={currentUserMarks}
/>
)}
{selectedMark !== null && (
/>)}
{
selectedMark !== null && (
<MarkFormField
handleSubmit={handleSubmit}
handleChange={handleChange}

View File

@ -13,13 +13,7 @@ interface PdfPageProps {
/**
* Responsible for rendering a single Pdf Page and its Marks
*/
const PdfPageItem = ({
page,
currentUserMarks,
handleMarkClick,
selectedMarkValue,
selectedMark
}: PdfPageProps) => {
const PdfPageItem = ({ page, currentUserMarks, handleMarkClick, selectedMarkValue, selectedMark }: PdfPageProps) => {
return (
<div
className={styles.pdfImageWrapper}
@ -29,8 +23,14 @@ const PdfPageItem = ({
marginTop: '10px'
}}
>
<img draggable="false" src={page.image} style={{ width: '100%' }} />
{currentUserMarks.map((m, i) => (
<img
draggable="false"
src={page.image}
style={{ width: '100%'}}
/>
{
currentUserMarks.map((m, i) => (
<PdfMarkItem
key={i}
handleMarkClick={handleMarkClick}

View File

@ -4,7 +4,7 @@ import PdfItem from './PdfItem.tsx'
import { CurrentUserMark } from '../../types/mark.ts'
interface PdfViewProps {
files: { pdfFile: PdfFile; filename: string; hash: string | null }[]
files: { pdfFile: PdfFile, filename: string, hash: string | null }[]
currentUserMarks: CurrentUserMark[]
handleMarkClick: (id: number) => void
selectedMarkValue: string
@ -14,24 +14,14 @@ interface PdfViewProps {
/**
* Responsible for rendering Pdf files.
*/
const PdfView = ({
files,
currentUserMarks,
handleMarkClick,
selectedMarkValue,
selectedMark
}: PdfViewProps) => {
const filterByFile = (
currentUserMarks: CurrentUserMark[],
hash: string
): CurrentUserMark[] => {
return currentUserMarks.filter(
(currentUserMark) => currentUserMark.mark.pdfFileHash === hash
)
const PdfView = ({ files, currentUserMarks, handleMarkClick, selectedMarkValue, selectedMark }: PdfViewProps) => {
const filterByFile = (currentUserMarks: CurrentUserMark[], hash: string): CurrentUserMark[] => {
return currentUserMarks.filter((currentUserMark) => currentUserMark.mark.pdfFileHash === hash)
}
return (
<Box sx={{ width: '100%' }}>
{files.map(({ pdfFile, hash }, i) => {
{
files.map(({ pdfFile, hash }, i) => {
if (!hash) return
return (
<PdfItem
@ -43,9 +33,10 @@ const PdfView = ({
selectedMarkValue={selectedMarkValue}
/>
)
})}
})
}
</Box>
)
}
export default PdfView
export default PdfView;

View File

@ -164,18 +164,13 @@ export class MetadataController extends EventEmitter {
* or a fallback RelaySet with Sigit's Relay
*/
public findRelayListMetadata = async (hexKey: string): Promise<RelaySet> => {
const relayEvent =
(await findRelayListInCache(hexKey)) ||
(await findRelayListAndUpdateCache(
[this.specialMetadataRelay],
hexKey
)) ||
(await findRelayListAndUpdateCache(
await this.nostrController.getMostPopularRelays(),
hexKey
))
const relayEvent = await findRelayListInCache(hexKey)
|| await findRelayListAndUpdateCache([this.specialMetadataRelay], hexKey)
|| await findRelayListAndUpdateCache(await this.nostrController.getMostPopularRelays(), hexKey)
return relayEvent ? getUserRelaySet(relayEvent.tags) : getDefaultRelaySet()
return relayEvent
? getUserRelaySet(relayEvent.tags)
: getDefaultRelaySet()
}
public extractProfileMetadataContent = (event: Event) => {

View File

@ -111,9 +111,7 @@ button:disabled {
/* Fonts */
@font-face {
font-family: 'Roboto';
src:
local('Roboto Medium'),
local('Roboto-Medium'),
src: local('Roboto Medium'), local('Roboto-Medium'),
url('assets/fonts/roboto-medium.woff2') format('woff2'),
url('assets/fonts/roboto-medium.woff') format('woff');
font-weight: 500;
@ -123,9 +121,7 @@ button:disabled {
@font-face {
font-family: 'Roboto';
src:
local('Roboto Light'),
local('Roboto-Light'),
src: local('Roboto Light'), local('Roboto-Light'),
url('assets/fonts/roboto-light.woff2') format('woff2'),
url('assets/fonts/roboto-light.woff') format('woff');
font-weight: 300;
@ -135,9 +131,7 @@ button:disabled {
@font-face {
font-family: 'Roboto';
src:
local('Roboto Bold'),
local('Roboto-Bold'),
src: local('Roboto Bold'), local('Roboto-Bold'),
url('assets/fonts/roboto-bold.woff2') format('woff2'),
url('assets/fonts/roboto-bold.woff') format('woff');
font-weight: bold;
@ -147,9 +141,7 @@ button:disabled {
@font-face {
font-family: 'Roboto';
src:
local('Roboto'),
local('Roboto-Regular'),
src: local('Roboto'), local('Roboto-Regular'),
url('assets/fonts/roboto-regular.woff2') format('woff2'),
url('assets/fonts/roboto-regular.woff') format('woff');
font-weight: normal;

View File

@ -342,9 +342,8 @@ export const CreatePage = () => {
}
const createMarks = (fileHashes: { [key: string]: string }) : Mark[] => {
return drawnPdfs
.flatMap((drawnPdf) => {
const fileHash = fileHashes[drawnPdf.file.name]
return drawnPdfs.flatMap((drawnPdf) => {
const fileHash = fileHashes[drawnPdf.file.name];
return drawnPdf.pages.flatMap((page, index) => {
return page.drawnFields.map((drawnField) => {
return {
@ -354,7 +353,7 @@ export const CreatePage = () => {
top: drawnField.top,
left: drawnField.left,
height: drawnField.height,
width: drawnField.width
width: drawnField.width,
},
npub: drawnField.counterpart,
pdfFileHash: fileHash
@ -364,7 +363,7 @@ export const CreatePage = () => {
})
.map((mark, index) => {
return {...mark, id: index }
})
});
}
// Handle errors during zip file generation
@ -432,9 +431,13 @@ export const CreatePage = () => {
if (!arraybuffer) return null
return new File([new Blob([arraybuffer])], `${unixNow}.sigit.zip`, {
return new File(
[new Blob([arraybuffer])],
`${unixNow}.sigit.zip`,
{
type: 'application/zip'
})
}
)
}
// Handle errors during file upload
@ -542,7 +545,9 @@ export const CreatePage = () => {
: viewers.map((viewer) => viewer.pubkey)
).filter((receiver) => receiver !== usersPubkey)
return receivers.map((receiver) => sendNotification(receiver, meta))
return receivers.map((receiver) =>
sendNotification(receiver, meta)
)
}
const handleCreate = async () => {

View File

@ -91,8 +91,7 @@ export const RelaysPage = () => {
if (isMounted) {
if (
!relaysState?.mapUpdated ||
(newRelayMap?.mapUpdated !== undefined &&
newRelayMap?.mapUpdated > relaysState?.mapUpdated)
newRelayMap?.mapUpdated !== undefined && (newRelayMap?.mapUpdated > relaysState?.mapUpdated)
) {
if (
!relaysState?.map ||

View File

@ -15,8 +15,8 @@ interface MarkFormFieldProps {
* Responsible for rendering a form field connected to a mark and keeping track of its value.
*/
const MarkFormField = (props: MarkFormFieldProps) => {
const { handleSubmit, handleChange, selectedMark, selectedMarkValue } = props
const getSubmitButton = () => (selectedMark.isLast ? 'Complete' : 'Next')
const { handleSubmit, handleChange, selectedMark, selectedMarkValue } = props;
const getSubmitButton = () => selectedMark.isLast ? 'Complete' : 'Next';
return (
<div className={styles.fixedBottomForm}>
<Box component="form" onSubmit={handleSubmit}>
@ -34,4 +34,4 @@ const MarkFormField = (props: MarkFormFieldProps) => {
)
}
export default MarkFormField
export default MarkFormField;

View File

@ -16,16 +16,13 @@ import { State } from '../../store/rootReducer'
import { CreateSignatureEventContent, Meta, SignedEvent } from '../../types'
import {
decryptArrayBuffer,
encryptArrayBuffer,
extractMarksFromSignedMeta,
encryptArrayBuffer, extractMarksFromSignedMeta,
extractZipUrlAndEncryptionKey,
generateEncryptionKey,
generateKeysFile,
getFilesWithHashes,
generateKeysFile, getFilesWithHashes,
getHash,
hexToNpub,
isOnline,
loadZip,
isOnline, loadZip,
now,
npubToHex,
parseJson,
@ -44,8 +41,7 @@ import { getLastSignersSig } from '../../utils/sign.ts'
import {
filterMarksByPubkey,
getCurrentUserMarks,
isCurrentUserMarksComplete,
updateMarks
isCurrentUserMarksComplete, updateMarks
} from '../../utils'
import PdfMarking from '../../components/PDFView/PdfMarking.tsx'
enum SignedStatus {
@ -104,10 +100,8 @@ export const SignPage = () => {
const [authUrl, setAuthUrl] = useState<string>()
const nostrController = NostrController.getInstance()
const [currentUserMarks, setCurrentUserMarks] = useState<CurrentUserMark[]>(
[]
)
const [isReadyToSign, setIsReadyToSign] = useState(false)
const [currentUserMarks, setCurrentUserMarks] = useState<CurrentUserMark[]>([]);
const [isReadyToSign, setIsReadyToSign] = useState(false);
useEffect(() => {
if (signers.length > 0) {
@ -198,16 +192,13 @@ export const SignPage = () => {
setViewers(createSignatureContent.viewers)
setCreatorFileHashes(createSignatureContent.fileHashes)
setSubmittedBy(createSignatureEvent.pubkey)
setMarks(createSignatureContent.markConfig)
setMarks(createSignatureContent.markConfig);
if (usersPubkey) {
const metaMarks = filterMarksByPubkey(
createSignatureContent.markConfig,
usersPubkey!
)
const metaMarks = filterMarksByPubkey(createSignatureContent.markConfig, usersPubkey!)
const signedMarks = extractMarksFromSignedMeta(meta)
const currentUserMarks = getCurrentUserMarks(metaMarks, signedMarks)
setCurrentUserMarks(currentUserMarks)
const currentUserMarks = getCurrentUserMarks(metaMarks, signedMarks);
setCurrentUserMarks(currentUserMarks);
// setCurrentUserMark(findNextCurrentUserMark(currentUserMarks) || null)
setIsReadyToSign(isCurrentUserMarksComplete(currentUserMarks))
}
@ -316,7 +307,7 @@ export const SignPage = () => {
)
if (arrayBuffer) {
files[fileName] = await convertToPdfFile(arrayBuffer, fileName)
files[fileName] = await convertToPdfFile(arrayBuffer, fileName);
const hash = await getHash(arrayBuffer)
if (hash) {
@ -357,7 +348,7 @@ export const SignPage = () => {
const decrypt = async (file: File) => {
setLoadingSpinnerDesc('Decrypting file')
const zip = await loadZip(file)
const zip = await loadZip(file);
if (!zip) return
const parsedKeysJson = await parseKeysJson(zip)
@ -448,7 +439,7 @@ export const SignPage = () => {
)
if (arrayBuffer) {
files[fileName] = await convertToPdfFile(arrayBuffer, fileName)
files[fileName] = await convertToPdfFile(arrayBuffer, fileName);
const hash = await getHash(arrayBuffer)
if (hash) {
@ -529,10 +520,7 @@ export const SignPage = () => {
}
// Sign the event for the meta file
const signEventForMeta = async (signerContent: {
prevSig: string
marks: Mark[]
}) => {
const signEventForMeta = async (signerContent: { prevSig: string, marks: Mark[] }) => {
return await signEventForMetaFile(
JSON.stringify(signerContent),
nostrController,
@ -541,8 +529,8 @@ export const SignPage = () => {
}
const getSignerMarksForMeta = (): Mark[] | undefined => {
if (currentUserMarks.length === 0) return
return currentUserMarks.map(({ mark }: CurrentUserMark) => mark)
if (currentUserMarks.length === 0) return;
return currentUserMarks.map(( { mark }: CurrentUserMark) => mark);
}
// Update the meta signatures
@ -612,9 +600,13 @@ export const SignPage = () => {
if (!arraybuffer) return null
return new File([new Blob([arraybuffer])], `${unixNow}.sigit.zip`, {
return new File(
[new Blob([arraybuffer])],
`${unixNow}.sigit.zip`,
{
type: 'application/zip'
})
}
)
}
// Handle errors during zip file generation
@ -702,7 +694,7 @@ export const SignPage = () => {
setIsLoading(true)
setLoadingSpinnerDesc('Signing nostr event')
if (!meta) return
if (!meta) return;
const prevSig = getLastSignersSig(meta, signers)
if (!prevSig) return
@ -926,13 +918,11 @@ export const SignPage = () => {
)
}
return (
<PdfMarking
return <PdfMarking
files={getFilesWithHashes(files, currentFileHashes)}
currentUserMarks={currentUserMarks}
setIsReadyToSign={setIsReadyToSign}
setCurrentUserMarks={setCurrentUserMarks}
setUpdatedMarks={setUpdatedMarks}
/>
)
}

View File

@ -23,17 +23,14 @@ import {
SignedEventContent
} from '../../types'
import {
decryptArrayBuffer,
extractMarksFromSignedMeta,
decryptArrayBuffer, extractMarksFromSignedMeta,
extractZipUrlAndEncryptionKey,
getHash,
hexToNpub,
now,
hexToNpub, now,
npubToHex,
parseJson,
readContentOfZipEntry,
shorten,
signEventForMetaFile
shorten, signEventForMetaFile
} from '../../utils'
import styles from './style.module.scss'
import { Cancel, CheckCircle } from '@mui/icons-material'
@ -44,7 +41,7 @@ import {
addMarks,
convertToPdfBlob,
convertToPdfFile,
groupMarksByPage
groupMarksByPage,
} from '../../utils/pdf.ts'
import { State } from '../../store/rootReducer.ts'
import { useSelector } from 'react-redux'
@ -158,10 +155,7 @@ export const VerifyPage = () => {
)
if (arrayBuffer) {
files[fileName] = await convertToPdfFile(
arrayBuffer,
fileName!
)
files[fileName] = await convertToPdfFile(arrayBuffer, fileName!)
const hash = await getHash(arrayBuffer)
if (hash) {
@ -175,6 +169,7 @@ export const VerifyPage = () => {
setCurrentFileHashes(fileHashes)
setFiles(files)
setSigners(createSignatureContent.signers)
setViewers(createSignatureContent.viewers)
setCreatorFileHashes(createSignatureContent.fileHashes)
@ -182,6 +177,8 @@ export const VerifyPage = () => {
setMeta(metaInNavState)
setIsLoading(false)
}
})
.catch((err) => {
@ -384,7 +381,7 @@ export const VerifyPage = () => {
}
const handleExport = async () => {
if (Object.entries(files).length === 0 || !meta || !usersPubkey) return
if (Object.entries(files).length === 0 ||!meta ||!usersPubkey) return;
const usersNpub = hexToNpub(usersPubkey)
if (
@ -398,10 +395,10 @@ export const VerifyPage = () => {
setIsLoading(true)
setLoadingSpinnerDesc('Signing nostr event')
if (!meta) return
if (!meta) return;
const prevSig = getLastSignersSig(meta, signers)
if (!prevSig) return
if (!prevSig) return;
const signedEvent = await signEventForMetaFile(
JSON.stringify({ prevSig }),
@ -409,7 +406,7 @@ export const VerifyPage = () => {
setIsLoading
)
if (!signedEvent) return
if (!signedEvent) return;
const exportSignature = JSON.stringify(signedEvent, null, 2)
const updatedMeta = {...meta, exportSignature }

View File

@ -9,7 +9,7 @@ export interface MouseState {
}
export interface PdfFile {
file: File
file: File,
pages: PdfPage[]
expanded?: boolean
}
@ -34,7 +34,7 @@ export interface DrawnField {
export interface DrawTool {
identifier: MarkType
label: string
icon: JSX.Element
icon: JSX.Element,
defaultValue?: string
selected?: boolean
active?: boolean

View File

@ -1,4 +1,4 @@
import { MarkType } from './drawing'
import { MarkType } from "./drawing";
export interface CurrentUserMark {
mark: Mark
@ -7,18 +7,18 @@ export interface CurrentUserMark {
}
export interface Mark {
id: number
npub: string
pdfFileHash: string
type: MarkType
location: MarkLocation
value?: string
id: number;
npub: string;
pdfFileHash: string;
type: MarkType;
location: MarkLocation;
value?: string;
}
export interface MarkLocation {
top: number
left: number
height: number
width: number
page: number
top: number;
left: number;
height: number;
width: number;
page: number;
}

View File

@ -11,18 +11,16 @@ export interface OutputByType {
}
interface InputByType {
base64: string
string: string
text: string
binarystring: string
array: number[]
uint8array: Uint8Array
arraybuffer: ArrayBuffer
blob: Blob
stream: NodeJS.ReadableStream
base64: string;
string: string;
text: string;
binarystring: string;
array: number[];
uint8array: Uint8Array;
arraybuffer: ArrayBuffer;
blob: Blob;
stream: NodeJS.ReadableStream;
}
export type OutputType = keyof OutputByType
export type InputFileFormat =
| InputByType[keyof InputByType]
| Promise<InputByType[keyof InputByType]>
export type InputFileFormat = InputByType[keyof InputByType] | Promise<InputByType[keyof InputByType]>;

View File

@ -9,12 +9,9 @@ import { Event } from 'nostr-tools'
* @param marks - default Marks extracted from Meta
* @param signedMetaMarks - signed user Marks extracted from DocSignatures
*/
const getCurrentUserMarks = (
marks: Mark[],
signedMetaMarks: Mark[]
): CurrentUserMark[] => {
const getCurrentUserMarks = (marks: Mark[], signedMetaMarks: Mark[]): CurrentUserMark[] => {
return marks.map((mark, index, arr) => {
const signedMark = signedMetaMarks.find((m) => m.id === mark.id)
const signedMark = signedMetaMarks.find((m) => m.id === mark.id);
if (signedMark && !!signedMark.value) {
mark.value = signedMark.value
}
@ -30,10 +27,8 @@ const getCurrentUserMarks = (
* Returns next incomplete CurrentUserMark if there is one
* @param usersMarks
*/
const findNextCurrentUserMark = (
usersMarks: CurrentUserMark[]
): CurrentUserMark | undefined => {
return usersMarks.find((mark) => !mark.isCompleted)
const findNextCurrentUserMark = (usersMarks: CurrentUserMark[]): CurrentUserMark | undefined => {
return usersMarks.find((mark) => !mark.isCompleted);
}
/**
@ -42,7 +37,7 @@ const findNextCurrentUserMark = (
* @param pubkey
*/
const filterMarksByPubkey = (marks: Mark[], pubkey: string): Mark[] => {
return marks.filter((mark) => mark.npub === hexToNpub(pubkey))
return marks.filter(mark => mark.npub === hexToNpub(pubkey))
}
/**
@ -62,9 +57,7 @@ const extractMarksFromSignedMeta = (meta: Meta): Mark[] => {
* marked as complete.
* @param currentUserMarks
*/
const isCurrentUserMarksComplete = (
currentUserMarks: CurrentUserMark[]
): boolean => {
const isCurrentUserMarksComplete = (currentUserMarks: CurrentUserMark[]): boolean => {
return currentUserMarks.every((mark) => mark.isCompleted)
}
@ -75,7 +68,7 @@ const isCurrentUserMarksComplete = (
* @param markToUpdate
*/
const updateMarks = (marks: Mark[], markToUpdate: Mark): Mark[] => {
const indexToUpdate = marks.findIndex((mark) => mark.id === markToUpdate.id)
const indexToUpdate = marks.findIndex(mark => mark.id === markToUpdate.id);
return [
...marks.slice(0, indexToUpdate),
markToUpdate,
@ -83,13 +76,8 @@ const updateMarks = (marks: Mark[], markToUpdate: Mark): Mark[] => {
]
}
const updateCurrentUserMarks = (
currentUserMarks: CurrentUserMark[],
markToUpdate: CurrentUserMark
): CurrentUserMark[] => {
const indexToUpdate = currentUserMarks.findIndex(
(m) => m.mark.id === markToUpdate.mark.id
)
const updateCurrentUserMarks = (currentUserMarks: CurrentUserMark[], markToUpdate: CurrentUserMark): CurrentUserMark[] => {
const indexToUpdate = currentUserMarks.findIndex((m) => m.mark.id === markToUpdate.mark.id)
return [
...currentUserMarks.slice(0, indexToUpdate),
markToUpdate,
@ -97,7 +85,7 @@ const updateCurrentUserMarks = (
]
}
const isLast = <T>(index: number, arr: T[]) => index === arr.length - 1
const isLast = <T>(index: number, arr: T[]) => (index === (arr.length -1))
export {
getCurrentUserMarks,
@ -106,5 +94,5 @@ export {
isCurrentUserMarksComplete,
findNextCurrentUserMark,
updateMarks,
updateCurrentUserMarks
updateCurrentUserMarks,
}

View File

@ -3,14 +3,13 @@ import * as PDFJS from 'pdfjs-dist'
import { PDFDocument } from 'pdf-lib'
import { Mark } from '../types/mark.ts'
PDFJS.GlobalWorkerOptions.workerSrc =
'node_modules/pdfjs-dist/build/pdf.worker.mjs'
PDFJS.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.mjs';
/**
* Scale between the PDF page's natural size and rendered size
* @constant {number}
*/
const SCALE: number = 3
const SCALE: number = 3;
/**
* Defined font size used when generating a PDF. Currently it is difficult to fully
* correlate font size used at the time of filling in / drawing on the PDF
@ -18,11 +17,11 @@ const SCALE: number = 3
* This should be fixed going forward.
* Switching to PDF-Lib will most likely make this problem redundant.
*/
const FONT_SIZE: number = 40
const FONT_SIZE: number = 40;
/**
* Current font type used when generating a PDF.
*/
const FONT_TYPE: string = 'Arial'
const FONT_TYPE: string = 'Arial';
/**
* Converts a PDF ArrayBuffer to a generic PDF File
@ -30,8 +29,8 @@ const FONT_TYPE: string = 'Arial'
* @param fileName identifier of the pdf file
*/
const toFile = (arrayBuffer: ArrayBuffer, fileName: string) : File => {
const blob = new Blob([arrayBuffer], { type: 'application/pdf' })
return new File([blob], fileName, { type: 'application/pdf' })
const blob = new Blob([arrayBuffer], { type: "application/pdf" });
return new File([blob], fileName, { type: "application/pdf" });
}
/**
@ -51,40 +50,42 @@ const toPdfFile = async (file: File): Promise<PdfFile> => {
* @return PdfFile[] - an array of Sigit's internal Pdf File type
*/
const toPdfFiles = async (selectedFiles: File[]): Promise<PdfFile[]> => {
return Promise.all(selectedFiles.filter(isPdf).map(toPdfFile))
return Promise.all(selectedFiles
.filter(isPdf)
.map(toPdfFile));
}
/**
* A utility that transforms a drawing coordinate number into a CSS-compatible string
* @param coordinate
*/
const inPx = (coordinate: number): string => `${coordinate}px`
const inPx = (coordinate: number): string => `${coordinate}px`;
/**
* A utility that checks if a given file is of the pdf type
* @param file
*/
const isPdf = (file: File) => file.type.toLowerCase().includes('pdf')
const isPdf = (file: File) => file.type.toLowerCase().includes('pdf');
/**
* Reads the pdf file binaries
*/
const readPdf = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader()
const reader = new FileReader();
reader.onload = (e: any) => {
const data = e.target.result
resolve(data)
}
};
reader.onerror = (err) => {
console.error('err', err)
reject(err)
}
};
reader.readAsDataURL(file)
reader.readAsDataURL(file);
})
}
@ -93,28 +94,26 @@ const readPdf = (file: File): Promise<string> => {
* @param data pdf file bytes
*/
const pdfToImages = async (data: any): Promise<PdfPage[]> => {
const images: string[] = []
const pdf = await PDFJS.getDocument(data).promise
const canvas = document.createElement('canvas')
const images: string[] = [];
const pdf = await PDFJS.getDocument(data).promise;
const canvas = document.createElement("canvas");
for (let i = 0; i < pdf.numPages; i++) {
const page = await pdf.getPage(i + 1)
const viewport = page.getViewport({ scale: SCALE })
const context = canvas.getContext('2d')
canvas.height = viewport.height
canvas.width = viewport.width
await page.render({ canvasContext: context!, viewport: viewport }).promise
images.push(canvas.toDataURL())
const page = await pdf.getPage(i + 1);
const viewport = page.getViewport({ scale: SCALE });
const context = canvas.getContext("2d");
canvas.height = viewport.height;
canvas.width = viewport.width;
await page.render({ canvasContext: context!, viewport: viewport }).promise;
images.push(canvas.toDataURL());
}
return Promise.resolve(
images.map((image) => {
return Promise.resolve(images.map((image) => {
return {
image,
drawnFields: []
}
})
)
}))
}
/**
@ -122,37 +121,34 @@ const pdfToImages = async (data: any): Promise<PdfPage[]> => {
* Returns an array of encoded images where each image is a representation
* of a PDF page with completed and signed marks from all users
*/
const addMarks = async (
file: File,
marksPerPage: { [key: string]: Mark[] }
) => {
const p = await readPdf(file)
const pdf = await PDFJS.getDocument(p).promise
const canvas = document.createElement('canvas')
const addMarks = async (file: File, marksPerPage: {[key: string]: Mark[]}) => {
const p = await readPdf(file);
const pdf = await PDFJS.getDocument(p).promise;
const canvas = document.createElement("canvas");
const images: string[] = []
const images: string[] = [];
for (let i = 0; i< pdf.numPages; i++) {
const page = await pdf.getPage(i+1)
const viewport = page.getViewport({ scale: SCALE })
const context = canvas.getContext('2d')
canvas.height = viewport.height
canvas.width = viewport.width
await page.render({ canvasContext: context!, viewport: viewport }).promise
const viewport = page.getViewport({ scale: SCALE });
const context = canvas.getContext("2d");
canvas.height = viewport.height;
canvas.width = viewport.width;
await page.render({ canvasContext: context!, viewport: viewport }).promise;
marksPerPage[i].forEach((mark) => draw(mark, context!))
marksPerPage[i].forEach(mark => draw(mark, context!))
images.push(canvas.toDataURL())
images.push(canvas.toDataURL());
}
return Promise.resolve(images)
return Promise.resolve(images);
}
/**
* Utility to scale mark in line with the PDF-to-PNG scale
*/
const scaleMark = (mark: Mark): Mark => {
const { location } = mark
const { location } = mark;
return {
...mark,
location: {
@ -169,7 +165,7 @@ const scaleMark = (mark: Mark): Mark => {
* Utility to check if a Mark has value
* @param mark
*/
const hasValue = (mark: Mark): boolean => !!mark.value
const hasValue = (mark: Mark): boolean => !!mark.value;
/**
* Draws a Mark on a Canvas representation of a PDF Page
@ -177,14 +173,14 @@ const hasValue = (mark: Mark): boolean => !!mark.value
* @param ctx a Canvas representation of a specific PDF Page
*/
const draw = (mark: Mark, ctx: CanvasRenderingContext2D) => {
const { location } = mark
const { location } = mark;
ctx!.font = FONT_SIZE + 'px ' + FONT_TYPE
ctx!.fillStyle = 'black'
const textMetrics = ctx!.measureText(mark.value!)
const textX = location.left + (location.width - textMetrics.width) / 2
const textY = location.top + (location.height + parseInt(ctx!.font)) / 2
ctx!.fillText(mark.value!, textX, textY)
ctx!.font = FONT_SIZE + 'px ' + FONT_TYPE;
ctx!.fillStyle = 'black';
const textMetrics = ctx!.measureText(mark.value!);
const textX = location.left + (location.width - textMetrics.width) / 2;
const textY = location.top + (location.height + parseInt(ctx!.font)) / 2;
ctx!.fillText(mark.value!, textX, textY);
}
/**
@ -192,7 +188,7 @@ const draw = (mark: Mark, ctx: CanvasRenderingContext2D) => {
* @param markedPdfPages
*/
const convertToPdfBlob = async (markedPdfPages: string[]): Promise<Blob> => {
const pdfDoc = await PDFDocument.create()
const pdfDoc = await PDFDocument.create();
for (const page of markedPdfPages) {
const pngImage = await pdfDoc.embedPng(page)
@ -207,6 +203,7 @@ const convertToPdfBlob = async (markedPdfPages: string[]): Promise<Blob> => {
const pdfBytes = await pdfDoc.save()
return new Blob([pdfBytes], { type: 'application/pdf' })
}
/**
@ -214,12 +211,9 @@ const convertToPdfBlob = async (markedPdfPages: string[]): Promise<Blob> => {
* @param arrayBuffer
* @param fileName
*/
const convertToPdfFile = async (
arrayBuffer: ArrayBuffer,
fileName: string
): Promise<PdfFile> => {
const file = toFile(arrayBuffer, fileName)
return toPdfFile(file)
const convertToPdfFile = async (arrayBuffer: ArrayBuffer, fileName: string): Promise<PdfFile> => {
const file = toFile(arrayBuffer, fileName);
return toPdfFile(file);
}
/**
@ -244,9 +238,10 @@ const groupMarksByPage = (marks: Mark[]) => {
* @param mark - current value, i.e. Mark being examined
*/
const byPage = (obj: { [key: number]: Mark[]}, mark: Mark) => {
const key = mark.location.page
const curGroup = obj[key] ?? []
return { ...obj, [key]: [...curGroup, mark] }
const key = mark.location.page;
const curGroup = obj[key] ?? [];
return { ...obj, [key]: [...curGroup, mark]
}
}
export {
@ -257,5 +252,5 @@ export {
convertToPdfFile,
addMarks,
convertToPdfBlob,
groupMarksByPage
groupMarksByPage,
}

View File

@ -5,8 +5,8 @@ import { localCache } from '../services'
import { ONE_WEEK_IN_MS, SIGIT_RELAY } from './const.ts'
import { RelayMap, RelaySet } from '../types'
const READ_MARKER = 'read'
const WRITE_MARKET = 'write'
const READ_MARKER = "read"
const WRITE_MARKET = "write"
/**
* Attempts to find a relay list from the provided lookUpRelays.
@ -15,10 +15,7 @@ const WRITE_MARKET = 'write'
* @param hexKey
* @return found relay list or null
*/
const findRelayListAndUpdateCache = async (
lookUpRelays: string[],
hexKey: string
): Promise<Event | null> => {
const findRelayListAndUpdateCache = async (lookUpRelays: string[], hexKey: string): Promise<Event | null> => {
try {
const eventFilter: Filter = {
kinds: [RelayList],
@ -45,14 +42,10 @@ const findRelayListAndUpdateCache = async (
const findRelayListInCache = async (hexKey: string): Promise<Event | null> => {
try {
// Attempt to retrieve the metadata event from the local cache
const cachedRelayListMetadataEvent =
await localCache.getUserRelayListMetadata(hexKey)
const cachedRelayListMetadataEvent = await localCache.getUserRelayListMetadata(hexKey)
// Check if the cached event is not older than one week
if (
cachedRelayListMetadataEvent &&
isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt)
) {
if (cachedRelayListMetadataEvent && isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt)) {
return cachedRelayListMetadataEvent.event
}
@ -111,5 +104,5 @@ export {
findRelayListInCache,
getUserRelaySet,
getDefaultRelaySet,
getDefaultRelayMap
getDefaultRelayMap,
}

View File

@ -5,10 +5,7 @@ import { Meta } from '../types'
* This function returns the signature of last signer
* It will be used in the content of export signature's signedEvent
*/
const getLastSignersSig = (
meta: Meta,
signers: `npub1${string}`[]
): string | null => {
const getLastSignersSig = (meta: Meta, signers: `npub1${string}`[]): string | null => {
// if there're no signers then use creator's signature
if (signers.length === 0) {
try {
@ -24,7 +21,9 @@ const getLastSignersSig = (
// get the signature of last signer
try {
const lastSignatureEvent: Event = JSON.parse(meta.docSignatures[lastSigner])
const lastSignatureEvent: Event = JSON.parse(
meta.docSignatures[lastSigner]
)
return lastSignatureEvent.sig
} catch (error) {
return null

View File

@ -36,12 +36,17 @@ const readContentOfZipEntry = async <T extends OutputType>(
const loadZip = async (data: InputFileFormat): Promise<JSZip | null> => {
try {
return await JSZip.loadAsync(data)
return await JSZip.loadAsync(data);
} catch (err: any) {
console.log('err in loading zip file :>> ', err)
toast.error(err.message || 'An error occurred in loading zip file.')
return null
return null;
}
}
export { readContentOfZipEntry, loadZip }
export {
readContentOfZipEntry,
loadZip
}