Added simple-icons role draft

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-06 12:08:37 +02:00
parent c537a1f5b6
commit eed72368c1
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
4 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# ---- Builder Stage ----
FROM node:latest AS builder
WORKDIR /app
# Nur package.json und package-lock.json kopieren für schnellere Caching-Layers
COPY package*.json ./
# simple-icons installieren
RUN npm install
# ---- Runtime Stage ----
FROM node:latest
WORKDIR /app
# Nur node_modules aus dem Builder übernehmen
COPY --from=builder /app/node_modules ./node_modules
# Kopiere den Server-Code
COPY server.js .
# Port, auf dem der Server lauscht
ENV PORT=3000
EXPOSE 3000
# Startbefehl
CMD ["node", "server.js"]

View File

@ -0,0 +1,14 @@
version: '3.8'
services:
icons:
build:
context: .
dockerfile: Dockerfile
image: simpleicons-server:latest
container_name: simpleicons-server
ports:
- "3000:3000"
environment:
- PORT=3000
restart: unless-stopped

View File

@ -0,0 +1,9 @@
{
"name": "simpleicons-server",
"type": "module",
"dependencies": {
"express": "^4.18.2",
"simple-icons": "^9.0.0",
"sharp": "^0.32.0"
}
}

View File

@ -0,0 +1,55 @@
import express from 'express';
import * as icons from 'simple-icons';
import sharp from 'sharp';
const app = express();
const port = process.env.PORT || 3000;
// Helper: turn 'nextcloud' → 'siNextcloud'
function getExportName(slug) {
return 'si' + slug
.split('-')
.map(part => part[0].toUpperCase() + part.slice(1))
.join('');
}
// GET /icons/:slug.svg
app.get('/icons/:slug.svg', (req, res) => {
const slug = req.params.slug.toLowerCase();
const exportName = getExportName(slug);
const icon = icons[exportName];
if (!icon) {
return res.status(404).send('Icon not found');
}
res.type('image/svg+xml').send(icon.svg);
});
// GET /icons/:slug.png?size=...
app.get('/icons/:slug.png', async (req, res) => {
const slug = req.params.slug.toLowerCase();
const size = parseInt(req.query.size, 10) || 128;
const exportName = getExportName(slug);
const icon = icons[exportName];
if (!icon) {
return res.status(404).send('Icon not found');
}
try {
const png = await sharp(Buffer.from(icon.svg))
.resize(size, size)
.png()
.toBuffer();
res.type('image/png').send(png);
} catch (err) {
console.error('PNG generation error:', err);
res.status(500).send('PNG generation error');
}
});
app.listen(port, () => {
console.log(`Simple-Icons server listening at http://0.0.0.0:${port}`);
});