kyuurzy

Monkey QRCode

Dec 20th, 2025 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.36 KB | Source Code | 0 0
  1. // monkeyqr.js
  2. // bagian config bisa custom sendiri
  3. const fetch = require("node-fetch")
  4.  
  5. async function designqr(data) {
  6.     try {
  7.         const qrResponse = await fetch('https://api.qrcode-monkey.com/qr/custom', {
  8.             method: 'POST',
  9.             headers: {
  10.                 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36',
  11.                 'Referer': 'https://www.qrcode-monkey.com/#text'
  12.             },
  13.             body: JSON.stringify({
  14.                 data: data,
  15.                 config: {
  16.                     body: "circular",
  17.                     eye: "frame3",
  18.                     eyeBall: "ball3",
  19.                     erf1: ["fv"],
  20.                     erf2: ["fv", "fh"],
  21.                     erf3: [],
  22.                     brf1: ["fv"],
  23.                     brf2: ["fv", "fh"],
  24.                     brf3: [],
  25.                     bodyColor: "#000000",
  26.                     bgColor: "#FFFFFF",
  27.                     eye1Color: "#000000",
  28.                     eye2Color: "#000000",
  29.                     eye3Color: "#000000",
  30.                     eyeBall1Color: "#000000",
  31.                     eyeBall2Color: "#000000",
  32.                     eyeBall3Color: "#000000",
  33.                     gradientColor1: "",
  34.                     gradientColor2: "",
  35.                     gradientType: "linear",
  36.                     gradientOnEyes: "true",
  37.                     logo: "",
  38.                     logoMode: "default"
  39.                 },
  40.                 size: 925,
  41.                 download: "imageUrl",
  42.                 file: "svg"
  43.             })
  44.         });
  45.  
  46.         if (!qrResponse.ok) {
  47.             throw new Error(`QR Code generation failed: ${qrResponse.status}`);
  48.         }
  49.  
  50.         const qrResult = await qrResponse.json();
  51.         const svgUrl = `https:${qrResult.imageUrl}`;
  52.  
  53.         const convertResponse = await fetch('https://api.freeconvert.com/v1/process/jobs', {
  54.             method: 'POST',
  55.             headers: {
  56.                 'Accept': 'application/json, text/plain, */*',
  57.                 'Content-Type': 'application/json',
  58.                 'Authorization': 'Bearer null',
  59.                 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36',
  60.                 'Referer': 'https://www.freeconvert.com/svg-to-png/download'
  61.             },
  62.             body: JSON.stringify({
  63.                 tasks: {
  64.                     import: {
  65.                         operation: "import/url",
  66.                         url: svgUrl,
  67.                         filename: "qr_code.svg"
  68.                     },
  69.                     convert: {
  70.                         operation: "convert",
  71.                         input: "import",
  72.                         input_format: "svg",
  73.                         output_format: "png",
  74.                         options: {
  75.                             png_compression_level: "lossy",
  76.                             png_convert_quality: 100,
  77.                             pixel_density: 300,
  78.                             "auto-orient": true,
  79.                             strip: true
  80.                         }
  81.                     },
  82.                     "export-url": {
  83.                         operation: "export/url",
  84.                         input: "convert"
  85.                     }
  86.                 }
  87.             })
  88.         });
  89.  
  90.         if (!convertResponse.ok) {
  91.             throw new Error(`Conversion failed: ${convertResponse.status}`);
  92.         }
  93.  
  94.         const jobResult = await convertResponse.json();
  95.         const jobId = jobResult.id;
  96.         const jobUrl = `https://api.freeconvert.com/v1/process/jobs/${jobId}`;
  97.        
  98.         let attempts = 0;
  99.         const maxAttempts = 30;
  100.        
  101.         while (attempts < maxAttempts) {
  102.             await new Promise(resolve => setTimeout(resolve, 1000));
  103.            
  104.             const statusResponse = await fetch(jobUrl, {
  105.                 headers: {
  106.                     'Accept': 'application/json, text/plain, */*',
  107.                     'Authorization': 'Bearer null',
  108.                     'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36'
  109.                 }
  110.             });
  111.            
  112.             const finalResult = await statusResponse.json();
  113.            
  114.             if (finalResult.status === 'completed') {
  115.                 const exportTask = finalResult.tasks.find(task => task.name === 'export-url');
  116.                 if (exportTask && exportTask.result && exportTask.result.url) {
  117.                     return JSON.stringify({
  118.                         pngUrl: exportTask.result.url,
  119.                         jobId: jobId
  120.                     }, null, 2);
  121.                 }
  122.             }
  123.            
  124.             if (finalResult.status === 'failed') {
  125.                 return JSON.stringify({
  126.                     error: 'Conversion job failed',
  127.                     jobId: jobId
  128.                 }, null, 2);
  129.             }
  130.            
  131.             attempts++;
  132.         }
  133.        
  134.         return JSON.stringify({
  135.             error: 'Conversion timeout after 30 seconds',
  136.             jobId: jobId
  137.         }, null, 2);
  138.        
  139.     } catch (error) {
  140.         return JSON.stringify({
  141.             error: error.message
  142.         }, null, 2);
  143.     }
  144. }
  145.  
  146. module.exports = designqr;
Advertisement
Add Comment
Please, Sign In to add comment