Skip to content

Commit

Permalink
refactor: don't re-create voucher image in Ql-mode if it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
swplange committed Dec 30, 2023
1 parent 8b4ed8b commit f081a3a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/print_voucher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ module.exports.printVoucher = async (voucher) => {

async function createVoucherImage(voucher) {
const fs = require('fs');
const fileName = `${voucher._id}.png`;

if (fs.existsSync(fileName)) {
return;
}

const {createCanvas} = require('canvas');

const width = 991;
Expand Down Expand Up @@ -66,7 +72,7 @@ async function createVoucherImage(voucher) {
context.fillText(`Quota: ${voucher.usage_quota} | Download: ${voucher.download_limit} | Upload: ${voucher.upload_limit}`, midWidth, paddingTop + titleHeight + spacingAfterTitle + voucherCodeHeight + spacingAfterVoucherCode + spacingBetweenDescriptionLines);

const buffer = canvas.toBuffer('image/png');
fs.writeFileSync(`${voucher._id}.png`, buffer);
fs.writeFileSync(fileName, buffer);
}

async function printUsingBrotherQlLibrary(voucher) {
Expand Down

0 comments on commit f081a3a

Please sign in to comment.