try all qr ecc levels (#2288)

try ecc levels
This commit is contained in:
Bernd Storath
2025-11-18 09:25:57 +01:00
committed by GitHub
parent cba7a160ea
commit 5c97a8ba73
+18 -5
View File
@@ -166,11 +166,24 @@ class WireGuard {
async getClientQRCodeSVG({ clientId }: { clientId: ID }) { async getClientQRCodeSVG({ clientId }: { clientId: ID }) {
const config = await this.getClientConfiguration({ clientId }); const config = await this.getClientConfiguration({ clientId });
return encodeQR(config, 'svg', { const ECMode = ['high', 'quartile', 'medium', 'low'] as const;
ecc: 'high', for (const ecc of ECMode) {
scale: 2, try {
encoding: 'byte', return encodeQR(config, 'svg', {
}); ecc,
scale: 2,
encoding: 'byte',
});
} catch (err) {
if (!(err instanceof Error && err.message === 'Capacity overflow')) {
throw err;
}
// retry with lower ecc
}
}
throw new Error(
'Failed to generate QR code: Capacity overflow at all ECC levels'
);
} }
cleanClientFilename(name: string): string { cleanClientFilename(name: string): string {