DashX-API / plugins /qr-generator.js
HerzaJ's picture
Upload 36 files
7e9ddb1 verified
const handler = async (req, res) => {
try {
const { text, size = 200, format = 'png' } = req.query;
if (!text) {
return res.status(400).json({
success: false,
error: 'Missing required parameter: text'
});
}
const validSizes = [100, 150, 200, 250, 300, 400, 500];
const validFormats = ['png', 'svg'];
if (!validSizes.includes(parseInt(size))) {
return res.status(400).json({
success: false,
error: 'Invalid size. Valid sizes: ' + validSizes.join(', ')
});
}
if (!validFormats.includes(format.toLowerCase())) {
return res.status(400).json({
success: false,
error: 'Invalid format. Valid formats: ' + validFormats.join(', ')
});
}
const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(text)}&format=${format}`;
res.json({
success: true,
data: {
text,
size: parseInt(size),
format,
qr_url: qrApiUrl,
download_url: qrApiUrl + '&download=1'
}
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
};
module.exports = {
name: 'QR Code Generator',
description: 'Generate QR codes for text, URLs, and more with custom sizes',
type: 'GET',
routes: ['api/tools/qr/generate'],
tags: ['utility', 'qr', 'generator'],
parameters: ['text', 'size', 'format', 'key'],
enabled: true,
main: ['tools'],
handler
};