const express = require('express'); const axios = require('axios'); const app = express(); const PORT = process.env.PORT || 3000; app.get('/badge', async (req, res) => { const { icon = 'portainer', label = 'Portainer', bg = '#f0f0f0', color = '#000000', size = 24, labelpos = 'right', // lehet: 'right', 'left', 'above', 'below' fontweight = 'normal', // új paraméter, alapértelmezett: normal } = req.query; try { // Ikon letöltése const iconUrl = `https://cdn.simpleicons.org/${icon}?viewbox=auto&size=${size}`; const iconResponse = await axios.get(iconUrl, { responseType: 'text' }); if (iconResponse.status !== 200) { return res.status(404).send('Icon not found'); } const iconSVG = iconResponse.data; // Badge méretek const padding = 10; const iconSize = parseInt(size); const fontSize = Math.round(iconSize * 0.6); // Font size az ikon méret 60%-a const textPadding = Math.round(iconSize * 0.4); // Dinamikus: size 40%-a const radius = 8; const approxCharWidth = fontSize * 0.6; const textWidth = label.length * approxCharWidth; let width, height, iconGroup, textElem; // Szebb, élsimított font shields.io stílusban const fontFamily = "Verdana,Geneva,DejaVu Sans,sans-serif"; const fontWeight = fontweight; // paraméterből if (labelpos === 'above' || labelpos === 'below') { width = Math.max(iconSize, textWidth) + padding * 2; height = padding * 2 + iconSize + textPadding + fontSize; if (labelpos === 'above') { // Szöveg felül, ikon alul textElem = `${label}`; iconGroup = `${iconSVG}`; } else { // Szöveg alul, ikon felül iconGroup = `${iconSVG}`; textElem = `${label}`; } } else if (labelpos === 'left') { width = padding * 2 + iconSize + textPadding + textWidth; height = Math.max(iconSize + padding * 2, fontSize + padding * 2); // Szöveg balra, ikon jobbra (függőleges közép) textElem = `${label}`; iconGroup = `${iconSVG}`; } else { width = padding * 2 + iconSize + textPadding + textWidth; height = Math.max(iconSize + padding * 2, fontSize + padding * 2); // Alapértelmezett: ikon balra, szöveg jobbra (függőleges közép) iconGroup = `${iconSVG}`; textElem = `${label}`; } // SVG badge string összefűzéssel, szöveg árnyékkal const svg = ` ${iconGroup} ${textElem.replace(' `.trim(); res.setHeader('Content-Type', 'image/svg+xml'); res.send(svg); } catch (err) { console.error(err); res.status(500).send('Internal Server Error'); } }); app.listen(PORT, () => { console.log(`🚀 Badge API running at http://localhost:${PORT}/badge`); });