@@ -10,6 +10,8 @@ import { Application, Espace, UsersPermissionsUser } from '~typings/api'
1010import { format } from '~utils/date'
1111import { formatCampaignZipName , getBufferFromStream } from '~utils/pdf'
1212
13+ const MAX_ARTISTIC_FILES_THRESHOLD = 120
14+
1315const generateColor = ( ) => {
1416 const randomComponent = ( ) =>
1517 Math . floor ( Math . random ( ) * 128 + 128 )
@@ -405,6 +407,12 @@ const SelectedCampaignApplications = async (req, res) => {
405407 application . status === 'validated' ,
406408 )
407409
410+ const artisticFilesCount = filteredApplications . filter (
411+ ( application ) => application . creation_file ?. [ 0 ] ?. url ,
412+ ) . length
413+
414+ console . log ( 'Artistic files count:' , artisticFilesCount )
415+
408416 // Group by place
409417 const groupedApplications = filteredApplications . reduce (
410418 ( grouped , application ) => {
@@ -467,15 +475,32 @@ const SelectedCampaignApplications = async (req, res) => {
467475 )
468476
469477 if ( application ?. creation_file ?. [ 0 ] ?. url ) {
470- console . log ( application ?. creation_file ?. [ 0 ] ?. url )
471- const creationFile = await fetch ( application ?. creation_file ?. [ 0 ] ?. url )
472- // @ts -ignore
473- const creationFileArrayBuffer = await creationFile . buffer ( )
474-
475- await zip . addBuffer (
476- Buffer . from ( creationFileArrayBuffer ) ,
477- `${ name } /${ subFolder } /${ refLabel } - Dossier artistique.pdf` ,
478- )
478+ if ( artisticFilesCount > MAX_ARTISTIC_FILES_THRESHOLD ) {
479+ const htmlContent = `
480+ <!DOCTYPE html>
481+ <html>
482+ <head><title>${ application ?. creation_title } </title></head>
483+ <body style="margin:0;padding:0;overflow:hidden">
484+ <embed src="${ application ?. creation_file ?. [ 0 ] ?. url } " type="application/pdf" style="width:100%;height:100vh;">
485+ </body>
486+ </html>
487+ `
488+
489+ await zip . addBuffer (
490+ htmlContent ,
491+ `${ name } /${ subFolder } /${ refLabel } - Dossier artistique.html` ,
492+ )
493+ } else {
494+ const creationFile = await fetch (
495+ application ?. creation_file ?. [ 0 ] ?. url ,
496+ )
497+ // @ts -ignore
498+ const creationFileArrayBuffer = await creationFile . buffer ( )
499+ await zip . addBuffer (
500+ Buffer . from ( creationFileArrayBuffer ) ,
501+ `${ name } /${ subFolder } /${ refLabel } - Dossier artistique.pdf` ,
502+ )
503+ }
479504 }
480505 }
481506 }
0 commit comments