Skip to content

Commit

Permalink
feat: support absolute path images when converting image to base64 (#170
Browse files Browse the repository at this point in the history
)

* check the imgPath before readFileSync

* code review comment update

* code review comment update, add back main part of the function

* code review comment update part 2

* format

---------

Co-authored-by: kpascal <kpascal@billtrust.com>
  • Loading branch information
kdp88 and keithp116 committed Dec 16, 2023
1 parent d3f22a5 commit 9fcb92d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/enhanceReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,16 @@ function createVideoContext(video, baseFolder) {
}

function convertImageToBase64(screenshotsDir, imagePath) {
const imgPath = path.join(screenshotsDir, imagePath);
const contents = 'data:image/png;base64, ' + fse.readFileSync(imgPath, { encoding: 'base64' });
return contents;
if (fse.pathExistsSync(imagePath)) {
return convertImg(imagePath);
} else {
const imgPath = path.join(screenshotsDir, imagePath);
return convertImg(imgPath);
}

function convertImg(pathToFile) {
return 'data:image/png;base64, ' + fse.readFileSync(pathToFile, { encoding: 'base64' });
}
}

function encodeMediaPath(p) {
Expand Down

0 comments on commit 9fcb92d

Please sign in to comment.