Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // monkeyqr.js
- // bagian config bisa custom sendiri
- const fetch = require("node-fetch")
- async function designqr(data) {
- try {
- const qrResponse = await fetch('https://api.qrcode-monkey.com/qr/custom', {
- method: 'POST',
- headers: {
- 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36',
- 'Referer': 'https://www.qrcode-monkey.com/#text'
- },
- body: JSON.stringify({
- data: data,
- config: {
- body: "circular",
- eye: "frame3",
- eyeBall: "ball3",
- erf1: ["fv"],
- erf2: ["fv", "fh"],
- erf3: [],
- brf1: ["fv"],
- brf2: ["fv", "fh"],
- brf3: [],
- bodyColor: "#000000",
- bgColor: "#FFFFFF",
- eye1Color: "#000000",
- eye2Color: "#000000",
- eye3Color: "#000000",
- eyeBall1Color: "#000000",
- eyeBall2Color: "#000000",
- eyeBall3Color: "#000000",
- gradientColor1: "",
- gradientColor2: "",
- gradientType: "linear",
- gradientOnEyes: "true",
- logo: "",
- logoMode: "default"
- },
- size: 925,
- download: "imageUrl",
- file: "svg"
- })
- });
- if (!qrResponse.ok) {
- throw new Error(`QR Code generation failed: ${qrResponse.status}`);
- }
- const qrResult = await qrResponse.json();
- const svgUrl = `https:${qrResult.imageUrl}`;
- const convertResponse = await fetch('https://api.freeconvert.com/v1/process/jobs', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json, text/plain, */*',
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer null',
- 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36',
- 'Referer': 'https://www.freeconvert.com/svg-to-png/download'
- },
- body: JSON.stringify({
- tasks: {
- import: {
- operation: "import/url",
- url: svgUrl,
- filename: "qr_code.svg"
- },
- convert: {
- operation: "convert",
- input: "import",
- input_format: "svg",
- output_format: "png",
- options: {
- png_compression_level: "lossy",
- png_convert_quality: 100,
- pixel_density: 300,
- "auto-orient": true,
- strip: true
- }
- },
- "export-url": {
- operation: "export/url",
- input: "convert"
- }
- }
- })
- });
- if (!convertResponse.ok) {
- throw new Error(`Conversion failed: ${convertResponse.status}`);
- }
- const jobResult = await convertResponse.json();
- const jobId = jobResult.id;
- const jobUrl = `https://api.freeconvert.com/v1/process/jobs/${jobId}`;
- let attempts = 0;
- const maxAttempts = 30;
- while (attempts < maxAttempts) {
- await new Promise(resolve => setTimeout(resolve, 1000));
- const statusResponse = await fetch(jobUrl, {
- headers: {
- 'Accept': 'application/json, text/plain, */*',
- 'Authorization': 'Bearer null',
- 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36'
- }
- });
- const finalResult = await statusResponse.json();
- if (finalResult.status === 'completed') {
- const exportTask = finalResult.tasks.find(task => task.name === 'export-url');
- if (exportTask && exportTask.result && exportTask.result.url) {
- return JSON.stringify({
- pngUrl: exportTask.result.url,
- jobId: jobId
- }, null, 2);
- }
- }
- if (finalResult.status === 'failed') {
- return JSON.stringify({
- error: 'Conversion job failed',
- jobId: jobId
- }, null, 2);
- }
- attempts++;
- }
- return JSON.stringify({
- error: 'Conversion timeout after 30 seconds',
- jobId: jobId
- }, null, 2);
- } catch (error) {
- return JSON.stringify({
- error: error.message
- }, null, 2);
- }
- }
- module.exports = designqr;
Advertisement
Add Comment
Please, Sign In to add comment