Skip to content

Commit e7e71a1

Browse files
committed
feat: improvements
1 parent dbc5a75 commit e7e71a1

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

web/components/Account/Application/Place/DetailDrawer/ApplicationPreselectButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const ApplicationPreselectButton = ({
113113
<Text pl={1}>{t('place.detail.preselect')}</Text>
114114
</Button>
115115

116-
{(!canPreselect || selectedCampaign?.mode === 'closed') && (
116+
{!canPreselect && selectedCampaign?.mode !== 'closed' && (
117117
<Text pl={1} color="gray.500">
118118
{t('place.preselected_limit_reached')}
119119
</Text>

web/pages/api/pdfs/all/[id].tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import { renderToStream } from '@react-pdf/renderer'
3-
import AdmZip from 'adm-zip'
43
import { getSession } from 'next-auth/client'
4+
import yazl from 'yazl'
55
import { client } from '~api/client-api'
66
import ApplicationDocument from '~components/pdfs/ApplicationDocument'
77
import { formatDisponibilityZipName, getBufferFromStream } from '~utils/pdf'
@@ -29,38 +29,48 @@ const MultipleApplication = async (req, res) => {
2929
)
3030

3131
const disponibility = applications?.[0]?.disponibility
32-
const zip = new AdmZip()
32+
const zip = new yazl.ZipFile()
3333

3434
for (const application of applications) {
3535
const refLabel = `Ref. ${application.id}`
3636
const name = `${refLabel} - ${application.company?.structureName}`
3737
const stream = await renderToStream(
3838
<ApplicationDocument application={application} />,
3939
)
40+
4041
const streamBuffer = await getBufferFromStream(stream)
41-
await zip.addFile(`${name}/${refLabel} - Candidature.pdf`, streamBuffer)
42+
await zip.addBuffer(
43+
Buffer.from(streamBuffer),
44+
`${name}/${refLabel} - Candidature.pdf`,
45+
)
4246

4347
if (application?.creation_file?.[0]?.url) {
4448
const creationFile = await fetch(application?.creation_file?.[0]?.url)
4549

4650
// @ts-ignore
4751
const creationFileArrayBuffer = await creationFile.buffer()
48-
await zip.addFile(
52+
await zip.addBuffer(
53+
Buffer.from(creationFileArrayBuffer),
4954
`${name}/${refLabel} - Dossier artistique.pdf`,
50-
creationFileArrayBuffer,
5155
)
5256
}
5357
}
5458

55-
const zipBuffer = zip.toBuffer()
56-
5759
res.setHeader('Content-Type', 'application/zip')
5860
res.setHeader(
5961
'Content-Disposition',
6062
// @ts-expect-error
6163
'attachment; filename=' + formatDisponibilityZipName(disponibility),
6264
)
63-
res.send(zipBuffer)
65+
66+
zip.end()
67+
68+
const zipStream = zip.outputStream
69+
zipStream.pipe(res)
70+
71+
return new Promise((resolve) => {
72+
zipStream.on('end', resolve)
73+
})
6474
}
6575

6676
export default MultipleApplication

0 commit comments

Comments
 (0)