(
scoreinfo: ScoreInfo,
sheet: SheetInfo,
scoreUrl = "",
setText: (str: string) => void
)
| 45 | }; |
| 46 | |
| 47 | export const exportPDF = async ( |
| 48 | scoreinfo: ScoreInfo, |
| 49 | sheet: SheetInfo, |
| 50 | scoreUrl = "", |
| 51 | setText: (str: string) => void |
| 52 | ): Promise<ArrayBuffer> => { |
| 53 | const imgType = sheet.imgType; |
| 54 | const pageCount = sheet.pageCount; |
| 55 | |
| 56 | const rs = Array.from({ length: pageCount }).map(async (_, i) => { |
| 57 | let url; |
| 58 | if (i === 0) { |
| 59 | // The url to the first page is static. We don't need to use API to obtain it. |
| 60 | url = sheet.thumbnailUrl; |
| 61 | if (setText) { |
| 62 | setText(`${Math.round((1 / pageCount) * 83)}%`); |
| 63 | } |
| 64 | } else { |
| 65 | // obtain image urls using the API |
| 66 | url = await getFileUrl( |
| 67 | scoreinfo.id, |
| 68 | "img", |
| 69 | scoreUrl, |
| 70 | i, |
| 71 | undefined, |
| 72 | setText, |
| 73 | pageCount |
| 74 | ); |
| 75 | } |
| 76 | return url; |
| 77 | }); |
| 78 | const sheetImgURLs = await Promise.all(rs); |
| 79 | const args = [sheetImgURLs, imgType, sheet.dimensions] as const; |
| 80 | if (!isNodeJs) { |
| 81 | return _exportPDFBrowser(...args, setText); |
| 82 | } else { |
| 83 | return _exportPDFNode(...args); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | let pdfBlob: Blob; |
| 88 | export const downloadPDF = async ( |
no test coverage detected