Update index.js
Browse files
index.js
CHANGED
|
@@ -1,11 +1,141 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const { Canvas, loadImage } = require('skia-canvas');
|
| 3 |
const app = express();
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
app.use(express.json({ limit: '50mb' }));
|
| 6 |
|
| 7 |
app.get('/', (req, res) => res.send("🚀 Cipher-MD ULTRA-SHARP ENGINE"));
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
// ============================================================
|
| 10 |
// 🛠️ HELPER: ROUNDED RECTANGLE
|
| 11 |
// ============================================================
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const { Canvas, loadImage } = require('skia-canvas');
|
| 3 |
const app = express();
|
| 4 |
+
const multer = require('multer'); // ෆයිල් ගන්න
|
| 5 |
+
const { Sticker, StickerTypes } = require('wa-sticker-formatter');
|
| 6 |
+
const upload = multer({ storage: multer.memoryStorage() });
|
| 7 |
app.use(express.json({ limit: '50mb' }));
|
| 8 |
|
| 9 |
app.get('/', (req, res) => res.send("🚀 Cipher-MD ULTRA-SHARP ENGINE"));
|
| 10 |
|
| 11 |
+
// ============================================================
|
| 12 |
+
// 🎨 1. WELCOME IMAGE GENERATOR (Original Design Preserved)
|
| 13 |
+
// ============================================================
|
| 14 |
+
app.post('/welcome', async (req, res) => {
|
| 15 |
+
try {
|
| 16 |
+
const { pp, title, count } = req.body;
|
| 17 |
+
|
| 18 |
+
const size = 1024;
|
| 19 |
+
const canvas = new Canvas(size, size);
|
| 20 |
+
const ctx = canvas.getContext('2d');
|
| 21 |
+
|
| 22 |
+
// 1. Image Load
|
| 23 |
+
let img;
|
| 24 |
+
try { img = await loadImage(pp); }
|
| 25 |
+
catch (e) { img = await loadImage("https://i.ibb.co/m53qpZg/default.jpg"); }
|
| 26 |
+
|
| 27 |
+
// 2. Background Blur
|
| 28 |
+
ctx.filter = 'blur(50px) brightness(0.5)';
|
| 29 |
+
ctx.drawImage(img, -50, -50, size + 100, size + 100);
|
| 30 |
+
ctx.filter = 'none';
|
| 31 |
+
|
| 32 |
+
// 3. Cyber Lines (Style 1 & 3 Only - As requested)
|
| 33 |
+
const styleId = Math.random() > 0.5 ? 1 : 3;
|
| 34 |
+
|
| 35 |
+
if (styleId === 1) {
|
| 36 |
+
ctx.strokeStyle = 'rgba(0, 242, 255, 0.1)';
|
| 37 |
+
for (let i = 0; i < size; i += 60) {
|
| 38 |
+
ctx.beginPath(); ctx.moveTo(i, 0); ctx.lineTo(i, size); ctx.stroke();
|
| 39 |
+
ctx.beginPath(); ctx.moveTo(0, i); ctx.lineTo(size, i); ctx.stroke();
|
| 40 |
+
}
|
| 41 |
+
} else {
|
| 42 |
+
// Style 3 Logic
|
| 43 |
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
|
| 44 |
+
ctx.lineWidth = 1;
|
| 45 |
+
for (let i = 0; i < 20; i++) {
|
| 46 |
+
ctx.beginPath(); ctx.moveTo(Math.random() * size, Math.random() * size);
|
| 47 |
+
ctx.lineTo(Math.random() * size, Math.random() * size); ctx.stroke();
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// 4. Center Circle
|
| 52 |
+
const centerX = size / 2;
|
| 53 |
+
const centerY = size / 2;
|
| 54 |
+
const radius = 250;
|
| 55 |
+
|
| 56 |
+
ctx.save();
|
| 57 |
+
ctx.strokeStyle = '#00f2ff'; ctx.lineWidth = 12; ctx.shadowBlur = 40; ctx.shadowColor = '#00f2ff';
|
| 58 |
+
ctx.beginPath(); ctx.arc(centerX, centerY, radius + 15, 0, Math.PI * 2); ctx.stroke(); ctx.restore();
|
| 59 |
+
|
| 60 |
+
ctx.save();
|
| 61 |
+
ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.clip();
|
| 62 |
+
ctx.drawImage(img, centerX - radius, centerY - radius, radius * 2, radius * 2); ctx.restore();
|
| 63 |
+
|
| 64 |
+
// 5. Texts
|
| 65 |
+
ctx.textAlign = 'center';
|
| 66 |
+
|
| 67 |
+
ctx.font = 'bold 60px sans-serif';
|
| 68 |
+
ctx.strokeStyle = 'rgba(0, 242, 255, 0.8)';
|
| 69 |
+
ctx.lineWidth = 3;
|
| 70 |
+
ctx.strokeText("W E L C O M E", centerX, centerY + radius + 120);
|
| 71 |
+
|
| 72 |
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
|
| 73 |
+
ctx.font = '35px sans-serif';
|
| 74 |
+
// Emoji Remove Regex
|
| 75 |
+
const safeTitle = title.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');
|
| 76 |
+
ctx.fillText(`${safeTitle} • MEMBER #${count}`, centerX, centerY + radius + 190);
|
| 77 |
+
|
| 78 |
+
// Watermark (Original Position)
|
| 79 |
+
ctx.globalAlpha = 0.3;
|
| 80 |
+
ctx.font = 'bold 25px sans-serif';
|
| 81 |
+
ctx.fillStyle = '#ffffff';
|
| 82 |
+
ctx.fillText("CIPHER-MD VISUAL ENGINE v2.0", centerX, size - 30);
|
| 83 |
+
|
| 84 |
+
const buffer = await canvas.toBuffer('png');
|
| 85 |
+
res.set('Content-Type', 'image/png');
|
| 86 |
+
res.send(buffer);
|
| 87 |
+
|
| 88 |
+
} catch (e) { res.status(500).send("Welcome Error"); }
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
// ============================================================
|
| 92 |
+
// 🖼️ 2. WATERMARK (Only for .img gen)
|
| 93 |
+
// ============================================================
|
| 94 |
+
app.post('/watermark', upload.single('image'), async (req, res) => {
|
| 95 |
+
try {
|
| 96 |
+
if (!req.file) return res.status(400).send("No image");
|
| 97 |
+
const img = await loadImage(req.file.buffer);
|
| 98 |
+
const canvas = new Canvas(img.width, img.height);
|
| 99 |
+
const ctx = canvas.getContext('2d');
|
| 100 |
+
|
| 101 |
+
ctx.drawImage(img, 0, 0);
|
| 102 |
+
|
| 103 |
+
// Add Watermark
|
| 104 |
+
const fontSize = Math.floor(img.width * 0.04);
|
| 105 |
+
ctx.font = `bold ${fontSize}px sans-serif`;
|
| 106 |
+
ctx.textAlign = 'right';
|
| 107 |
+
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
|
| 108 |
+
ctx.shadowBlur = 5; ctx.shadowOffsetX = 3; ctx.shadowOffsetY = 3;
|
| 109 |
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
| 110 |
+
ctx.fillText('CIPHER-MD GEN ENGINE', img.width - 20, img.height - 20);
|
| 111 |
+
|
| 112 |
+
res.set('Content-Type', 'image/png');
|
| 113 |
+
res.send(await canvas.toBuffer('png'));
|
| 114 |
+
} catch (e) { res.status(500).send("WM Error"); }
|
| 115 |
+
});
|
| 116 |
+
|
| 117 |
+
// ============================================================
|
| 118 |
+
// 🃏 3. STICKER MAKER
|
| 119 |
+
// ============================================================
|
| 120 |
+
app.post('/sticker', upload.single('media'), async (req, res) => {
|
| 121 |
+
try {
|
| 122 |
+
if (!req.file) return res.status(400).send("No media");
|
| 123 |
+
const { pack, author } = req.body;
|
| 124 |
+
|
| 125 |
+
const sticker = new Sticker(req.file.buffer, {
|
| 126 |
+
pack: pack || 'Cipher-MD',
|
| 127 |
+
author: author || 'Bot',
|
| 128 |
+
type: StickerTypes.FULL,
|
| 129 |
+
categories: ['🤩', '🎉'],
|
| 130 |
+
quality: 40,
|
| 131 |
+
background: 'transparent'
|
| 132 |
+
});
|
| 133 |
+
|
| 134 |
+
res.set('Content-Type', 'image/webp');
|
| 135 |
+
res.send(await sticker.toBuffer());
|
| 136 |
+
} catch (e) { res.status(500).send("Sticker Error"); }
|
| 137 |
+
});
|
| 138 |
+
|
| 139 |
// ============================================================
|
| 140 |
// 🛠️ HELPER: ROUNDED RECTANGLE
|
| 141 |
// ============================================================
|