25 lines
713 B
TypeScript
25 lines
713 B
TypeScript
|
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)
|
||
|
zip.file(`/files/${fileName}`, blob)
|
||
|
}
|
||
|
|
||
|
return zip
|
||
|
}
|
||
|
|
||
|
export { getZipWithFiles }
|