"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.qrRouter = void 0;
const express_1 = require("express");
const qrcode_1 = __importDefault(require("qrcode"));
const router = (0, express_1.Router)();
router.get('/', async (req, res, next) => {
    try {
        const text = req.query.text;
        if (!text) {
            res.status(400).json({ error: { message: 'text parameter is required' } });
            return;
        }
        if (text.length > 2000) {
            res.status(400).json({ error: { message: 'text parameter must be 2000 characters or fewer' } });
            return;
        }
        const rawSize = parseInt(req.query.size, 10);
        const size = Math.min(500, Math.max(50, isNaN(rawSize) ? 200 : rawSize));
        const buffer = await qrcode_1.default.toBuffer(text, {
            type: 'png',
            width: size,
            margin: 1,
            errorCorrectionLevel: 'M',
        });
        res.set('Content-Type', 'image/png');
        res.set('Cache-Control', 'public, max-age=3600');
        res.set('Cross-Origin-Resource-Policy', 'cross-origin');
        res.send(buffer);
    }
    catch (err) {
        next(err);
    }
});
exports.qrRouter = router;
//# sourceMappingURL=qr.routes.js.map