2024-08-13 12:48:52 +03:00
|
|
|
import { Meta } from '../types'
|
|
|
|
import { extractMarksFromSignedMeta } from './mark.ts'
|
2024-08-16 12:01:41 +02:00
|
|
|
import { addMarks, convertToPdfBlob, groupMarksByFileNamePage } from './pdf.ts'
|
2024-08-13 12:48:52 +03:00
|
|
|
import JSZip from 'jszip'
|
|
|
|
import { PdfFile } from '../types/drawing.ts'
|
|
|
|
|
|
|
|
const getZipWithFiles = async (
|
|
|
|
meta: Meta,
|
2024-08-21 17:07:29 +02:00
|
|
|
files: { [filename: string]: PdfFile | File }
|
2024-08-13 12:48:52 +03:00
|
|
|
): Promise<JSZip> => {
|
|
|
|
const zip = new JSZip()
|
|
|
|
const marks = extractMarksFromSignedMeta(meta)
|
2024-08-16 12:01:41 +02:00
|
|
|
const marksByFileNamePage = groupMarksByFileNamePage(marks)
|
2024-08-13 12:48:52 +03:00
|
|
|
|
2024-08-21 17:07:29 +02:00
|
|
|
for (const [fileName, file] of Object.entries(files)) {
|
|
|
|
let blob: Blob
|
|
|
|
if ('pages' in file) {
|
|
|
|
// Handle PDF Files
|
|
|
|
const pages = await addMarks(file.file, marksByFileNamePage[fileName])
|
|
|
|
blob = await convertToPdfBlob(pages)
|
|
|
|
} else {
|
|
|
|
// Handle other files
|
|
|
|
blob = new Blob([file], { type: file.type })
|
|
|
|
}
|
|
|
|
|
2024-08-15 16:44:53 +02:00
|
|
|
zip.file(`files/${fileName}`, blob)
|
2024-08-13 12:48:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return zip
|
|
|
|
}
|
|
|
|
|
|
|
|
export { getZipWithFiles }
|