File size: 1,655 Bytes
7e9ddb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
};