From 6b1008b52f626f2ded0d1792d8ac08cb500a8be9 Mon Sep 17 00:00:00 2001 From: Glenn de Haan Date: Thu, 13 Mar 2025 19:10:15 +0100 Subject: [PATCH] Fixed crash within QR generation for larger SSIDs and Passwords --- modules/print.js | 7 ++++++- modules/qr.js | 4 ++-- utils/size.js | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/print.js b/modules/print.js index a2e0af0..0784b81 100644 --- a/modules/print.js +++ b/modules/print.js @@ -141,13 +141,18 @@ module.exports = { .fontSize(10) .text(`${t('scan')}:`); - doc.image(await qr(), 75, variables.unifiSsidPassword !== '' ? 215 : 205, { + doc.image(await qr(), 75, variables.unifiSsidPassword !== '' ? 255 : 205, { fit: [75, 75], align: 'center', valign: 'center' }); doc.moveDown(6); + // Check if we need to move the text down extra or not depending on if large SSIDs or Passwords are used + if(variables.unifiSsidPassword !== '' && (variables.unifiSsidPassword.length < 16 || variables.unifiSsidPassword.length < 32)) { + doc.moveDown(2); + } + doc.moveDown(2); } diff --git a/modules/qr.js b/modules/qr.js index b3eda0e..849fdae 100644 --- a/modules/qr.js +++ b/modules/qr.js @@ -21,7 +21,7 @@ module.exports = (buffer = false) => { return new Promise((resolve) => { if(!buffer) { - QRCode.toDataURL(qrText, { version: 4, errorCorrectionLevel: 'Q' }, (err, url) => { + QRCode.toDataURL(qrText, { version: 6, errorCorrectionLevel: 'Q' }, (err, url) => { if(err) { log.error(`[Qr] Error while generating code!`); log.error(err); @@ -30,7 +30,7 @@ module.exports = (buffer = false) => { resolve(url); }); } else { - QRCode.toBuffer(qrText, { version: 4, errorCorrectionLevel: 'Q' }, (err, buffer) => { + QRCode.toBuffer(qrText, { version: 6, errorCorrectionLevel: 'Q' }, (err, buffer) => { if(err) { log.error(`[Qr] Error while generating code!`); log.error(err); diff --git a/utils/size.js b/utils/size.js index f42bfe9..aee54e7 100644 --- a/utils/size.js +++ b/utils/size.js @@ -7,7 +7,7 @@ const variables = require('../modules/variables'); * Util function to calculate paper size based on voucher data */ module.exports = (voucher) => { - let base = variables.unifiSsid !== '' ? variables.unifiSsidPassword !== '' ? 385 : 375 : 260; + let base = variables.unifiSsid !== '' ? variables.unifiSsidPassword !== '' ? 415 : 375 : 260; if(voucher.qos_usage_quota) { base += 10;