tango-app-api-trax 3.7.60 → 3.7.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -29,11 +29,8 @@ import * as cameraService from '../services/camera.service.js';
|
|
|
29
29
|
dayjs.extend( isSameOrBefore );
|
|
30
30
|
import * as pdf from 'html-pdf';
|
|
31
31
|
import handlebars from './handlebar-helper.js';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// import path from 'path';
|
|
35
|
-
// const __filename = fileURLToPath( import.meta.url );
|
|
36
|
-
// const __dirname = path.dirname( __filename );
|
|
32
|
+
import fs from 'fs';
|
|
33
|
+
import path from 'path';
|
|
37
34
|
|
|
38
35
|
export async function storeList( req, res ) {
|
|
39
36
|
try {
|
|
@@ -4592,67 +4589,34 @@ export async function downloadChecklist( req, res ) {
|
|
|
4592
4589
|
question.userAnswer.forEach( ( answer ) => {
|
|
4593
4590
|
if ( answer?.referenceImage?.trim() ) {
|
|
4594
4591
|
answer.referenceImage = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.referenceImage;
|
|
4595
|
-
// const base64Image = await convertUrltoBase64( url );
|
|
4596
|
-
// if ( base64Image ) {
|
|
4597
|
-
// answer.referenceImage = base64Image;
|
|
4598
|
-
// }
|
|
4599
4592
|
}
|
|
4600
4593
|
if ( answer.validationType == 'Capture Image' && answer?.validationAnswer?.trim() ) {
|
|
4601
4594
|
answer.validationAnswer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.validationAnswer;
|
|
4602
|
-
// const base64Image = await convertUrltoBase64( url );
|
|
4603
|
-
// if ( base64Image ) {
|
|
4604
|
-
// answer.validationAnswer = base64Image;
|
|
4605
|
-
// }
|
|
4606
4595
|
}
|
|
4607
4596
|
if ( answer?.answer?.trim() && [ 'image', 'descriptiveImage', 'multipleImage', 'image/video' ].includes( question.answerType ) ) {
|
|
4608
4597
|
answer.answer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.answer;
|
|
4609
4598
|
if ( question.answerType == 'multipleImage' ) {
|
|
4610
|
-
console.log( answer.answer );
|
|
4611
4599
|
}
|
|
4612
|
-
// const base64Image = await convertUrltoBase64( url );
|
|
4613
|
-
// if ( base64Image ) {
|
|
4614
|
-
// answer.answer = base64Image;
|
|
4615
|
-
// }
|
|
4616
4600
|
}
|
|
4617
4601
|
} );
|
|
4618
4602
|
} );
|
|
4619
4603
|
} );
|
|
4620
|
-
|
|
4604
|
+
|
|
4605
|
+
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/template.hbs', 'utf8' );
|
|
4621
4606
|
const template = handlebars.compile( templateHtml );
|
|
4622
4607
|
const html = template( { data: checklistDetails } );
|
|
4623
|
-
pdf.create( html ).
|
|
4608
|
+
pdf.create( html ).toStream( ( err, stream ) => {
|
|
4624
4609
|
if ( err ) {
|
|
4625
|
-
res.status( 500 ).send( 'Error
|
|
4626
|
-
} else {
|
|
4627
|
-
res.setHeader( 'Content-Disposition', 'attachment; filename=checkListDetails.pdf' );
|
|
4628
|
-
res.contentType( 'application/pdf' );
|
|
4629
|
-
res.send( buffer );
|
|
4610
|
+
return res.status( 500 ).send( 'Error generating PDF' );
|
|
4630
4611
|
}
|
|
4612
|
+
|
|
4613
|
+
res.setHeader( 'Content-Type', 'application/pdf' );
|
|
4614
|
+
res.setHeader( 'Content-Disposition', 'attachment; filename=checkListDetails.pdf' );
|
|
4615
|
+
|
|
4616
|
+
stream.pipe( res );
|
|
4631
4617
|
} );
|
|
4632
4618
|
} catch ( e ) {
|
|
4633
4619
|
console.log( 'getChecklistQuestionAnswers =>', e );
|
|
4634
4620
|
return false;
|
|
4635
4621
|
}
|
|
4636
4622
|
}
|
|
4637
|
-
|
|
4638
|
-
// async function convertUrltoBase64( url ) {
|
|
4639
|
-
// try {
|
|
4640
|
-
// const response = await fetch( url );
|
|
4641
|
-
|
|
4642
|
-
// if ( !response.ok ) {
|
|
4643
|
-
// throw new Error( 'Failed to fetch image' );
|
|
4644
|
-
// }
|
|
4645
|
-
|
|
4646
|
-
// const contentType = response.headers.get( 'content-type' );
|
|
4647
|
-
// const arrayBuffer = await response.arrayBuffer();
|
|
4648
|
-
|
|
4649
|
-
// const base64Image =
|
|
4650
|
-
// `data:${contentType};base64,` +
|
|
4651
|
-
// Buffer.from( arrayBuffer ).toString( 'base64' );
|
|
4652
|
-
|
|
4653
|
-
// return base64Image;
|
|
4654
|
-
// } catch ( error ) {
|
|
4655
|
-
// // console.error( 'Error fetching image:', error.message );
|
|
4656
|
-
// return false;
|
|
4657
|
-
// }
|
|
4658
|
-
// }
|