Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ RELAYS='ws://localhost:7000,ws://localhost:8000,ws://localhost:9000'
# Seconds to wait to allow disputes to be started
DISPUTE_START_WINDOW=600

#The relative size of the random image when compared to the qr (as a ratio of imageWidth/qrWidth)
IMAGE_TO_QR_RATIO=0.2

# Probability of golden honey badger appearance (1 in X orders)
GOLDEN_HONEY_BADGER_PROBABILITY=100

# Number of notification messages sent to the admin, informing them of lack of solvers before disabling the community. The admin receives `MAX_ADMIN_WARNINGS_BEFORE_DEACTIVATION - 1` notification messages.
MAX_ADMIN_WARNINGS_BEFORE_DEACTIVATION=10

18 changes: 14 additions & 4 deletions util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import fiatJson from './fiat.json';
import languagesJson from './languages.json';
import { Order, Community } from "../models";
import { logger } from "../logger";
import QRCode from "qrcode";
import { Image, createCanvas } from 'canvas';

const fs = require('fs').promises;
const path = require('path');
const { I18n } = require('@grammyjs/i18n');

const QRCode = require('qrcode');
const { Image, createCanvas } = require('canvas');
// ISO 639-1 language codes

const languages: ILanguages = languagesJson;
Expand Down Expand Up @@ -619,7 +620,16 @@ const generateQRWithImage = async (request, randomImage) => {
const centerImage = new Image();
centerImage.src = `data:image/png;base64,${randomImage}`;

const imageSize = canvas.width * 0.3;
const rawRatio = process.env.IMAGE_TO_QR_RATIO ?? '0.2';
let imageToQrRatio = parseFloat(rawRatio);

// Validate ratio is a valid number between 0.1 and 0.5
if (isNaN(imageToQrRatio) || imageToQrRatio < 0.1 || imageToQrRatio > 0.5) {
logger.warning(`Invalid IMAGE_TO_QR_RATIO value: ${rawRatio}, using default 0.2`);
imageToQrRatio = 0.2;
}

const imageSize = canvas.width * imageToQrRatio;
const imagePos = (canvas.width - imageSize) / 2;

ctx.drawImage(centerImage, imagePos, imagePos, imageSize, imageSize);
Expand Down Expand Up @@ -660,4 +670,4 @@ export {
isOrderCreator,
generateRandomImage,
generateQRWithImage,
};
};
Loading