@@ -416,15 +416,16 @@ const FEATURE_NAME = 'reports';
416416 if ( err2 ) {
417417 common . returnMessage ( params , 200 , err2 ) ;
418418 }
419- else {
420- if ( res ) {
421- var html = res . message ;
422- if ( result . report_type !== "core" ) {
423- html = ejs . render ( res . message . template , res . message . data ) ;
424- }
425-
426- common . returnRaw ( params , 200 , html , { 'Content-Type' : 'text/html; charset=utf-8' , 'Access-Control-Allow-Origin' : '*' } ) ;
419+ else if ( res ) {
420+ var html = res . message ;
421+ if ( result . report_type !== "core" ) {
422+ html = ejs . render ( res . message . template , res . message . data ) ;
427423 }
424+
425+ common . returnRaw ( params , 200 , html , { 'Content-Type' : 'text/html; charset=utf-8' , 'Access-Control-Allow-Origin' : '*' } ) ;
426+ }
427+ else {
428+ common . returnMessage ( params , 200 , 'No data to report' ) ;
428429 }
429430 } ) ;
430431 } ) ;
@@ -454,41 +455,42 @@ const FEATURE_NAME = 'reports';
454455 if ( err2 ) {
455456 common . returnMessage ( params , 200 , err2 ) ;
456457 }
457- else {
458- if ( res ) {
459- var html = res . message ;
460- if ( result . report_type !== "core" ) {
461- html = ejs . render ( res . message . template , res . message . data ) ;
462- }
463- const filePath = '/tmp/email_report_' + new Date ( ) . getTime ( ) + '.pdf' ;
464- const options = { "path" : filePath , "width" : "1028px" , height : "1000px" } ;
465-
466- pdf . renderPDF ( html , function ( ) {
467- //output created file to browser
468- fs . readFile ( filePath , function ( err3 , data ) {
469- if ( err3 ) {
470- console . log ( err3 ) ;
471- common . returnMessage ( params , 500 , 'Cannot read pdf file' ) ;
472- }
473- else {
474- common . returnRaw ( params , 200 , data , {
475- 'Content-Type' : 'application/pdf' ,
476- 'Content-Disposition' : 'inline; filename="report.pdf"' ,
477- 'Content-Length' : data . length ,
478- 'Access-Control-Allow-Origin' : '*'
479- } ) ;
480- }
481- fs . unlink ( filePath , function ( unlinkErr ) {
482- if ( unlinkErr ) {
483- console . log ( "Cannot remove temp pdf file" ) ;
484- console . log ( unlinkErr ) ;
485- }
458+ else if ( res ) {
459+ var html = res . message ;
460+ if ( result . report_type !== "core" ) {
461+ html = ejs . render ( res . message . template , res . message . data ) ;
462+ }
463+ const filePath = '/tmp/email_report_' + new Date ( ) . getTime ( ) + '.pdf' ;
464+ const options = { "path" : filePath , "width" : "1028px" , height : "1000px" } ;
465+
466+ pdf . renderPDF ( html , function ( ) {
467+ //output created file to browser
468+ fs . readFile ( filePath , function ( err3 , data ) {
469+ if ( err3 ) {
470+ console . log ( err3 ) ;
471+ common . returnMessage ( params , 500 , 'Cannot read pdf file' ) ;
472+ }
473+ else {
474+ common . returnRaw ( params , 200 , data , {
475+ 'Content-Type' : 'application/pdf' ,
476+ 'Content-Disposition' : 'inline; filename="report.pdf"' ,
477+ 'Content-Length' : data . length ,
478+ 'Access-Control-Allow-Origin' : '*'
486479 } ) ;
480+ }
481+ fs . unlink ( filePath , function ( unlinkErr ) {
482+ if ( unlinkErr ) {
483+ console . log ( "Cannot remove temp pdf file" ) ;
484+ console . log ( unlinkErr ) ;
485+ }
487486 } ) ;
488- } , options , {
489- args : [ '--no-sandbox' , '--disable-setuid-sandbox' , '--disable-web-security' ] ,
490- } , true ) ;
491- }
487+ } ) ;
488+ } , options , {
489+ args : [ '--no-sandbox' , '--disable-setuid-sandbox' , '--disable-web-security' ] ,
490+ } , true ) ;
491+ }
492+ else {
493+ common . returnMessage ( params , 200 , 'No data to report' ) ;
492494 }
493495 } ) ;
494496 } ) ;
0 commit comments