import { Meta } from '../types' import { extractMarksFromSignedMeta } from './mark.ts' import { addMarks, convertToPdfBlob, groupMarksByFileNamePage } from './pdf.ts' import JSZip from 'jszip' import { PdfFile } from '../types/drawing.ts' const getZipWithFiles = async ( meta: Meta, files: { [filename: string]: PdfFile | File } ): Promise => { const zip = new JSZip() const marks = extractMarksFromSignedMeta(meta) const marksByFileNamePage = groupMarksByFileNamePage(marks) 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 }) } zip.file(`files/${fileName}`, blob) } return zip } export { getZipWithFiles }