2024-08-13 09:48:52 +00:00
|
|
|
import { Meta } from '../types'
|
|
|
|
import { extractMarksFromSignedMeta } from './mark.ts'
|
|
|
|
import { addMarks, convertToPdfBlob, groupMarksByPage } from './pdf.ts'
|
|
|
|
import JSZip from 'jszip'
|
|
|
|
import { PdfFile } from '../types/drawing.ts'
|
|
|
|
|
|
|
|
const getZipWithFiles = async (
|
|
|
|
meta: Meta,
|
|
|
|
files: { [filename: string]: PdfFile }
|
|
|
|
): Promise<JSZip> => {
|
|
|
|
const zip = new JSZip()
|
|
|
|
const marks = extractMarksFromSignedMeta(meta)
|
|
|
|
const marksByPage = groupMarksByPage(marks)
|
|
|
|
|
|
|
|
for (const [fileName, pdf] of Object.entries(files)) {
|
|
|
|
const pages = await addMarks(pdf.file, marksByPage)
|
|
|
|
const blob = await convertToPdfBlob(pages)
|
2024-08-15 14:44:53 +00:00
|
|
|
zip.file(`files/${fileName}`, blob)
|
2024-08-13 09:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return zip
|
|
|
|
}
|
|
|
|
|
|
|
|
export { getZipWithFiles }
|