blob: f7f88c62b1c431f75410457d9e7b45198a5f2854 [file] [log] [blame]
import { default as express } from 'express';
const app = express();
interface SVGEditOptions {
left: string
right: string
size: number
};
const full = (options: SVGEditOptions) => `
<svg width="${options.size}" height="${options.size}" viewBox="0 0 2048 2048" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M416 384C416 171.923 587.923 0 800 0H992V320H944C917.49 320 896 341.49 896 368V784C896 810.51 917.49 832 944 832H992V2048C673.884 2048 416 1790.12 416 1472V384Z" fill="${options.left}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1632 384C1632 171.923 1460.08 0 1248 0H1056V320H1104C1130.51 320 1152 341.49 1152 368V784C1152 810.51 1130.51 832 1104 832H1056V2048C1374.12 2048 1632 1790.12 1632 1472V384Z" fill="${options.right}"/>
</svg>
`;
const rotated = (options: SVGEditOptions) => `
<svg width="${options.size}" height="${options.size}" viewBox="0 0 2048 2048" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M417.109 734.004C359.177 574.837 441.244 398.843 600.411 340.911L768.526 279.723L768.526 279.723L744.51 288.465L831.922 528.629L795.898 541.741C776.002 548.982 765.743 570.981 772.985 590.877L886.621 903.091C893.863 922.987 915.862 933.245 935.758 926.004L971.783 912.892L1303.95 1825.52C1065.2 1912.41 801.21 1789.31 714.312 1550.56L417.109 734.004Z" fill="${options.left}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M792.543 270.978L936.641 218.53C1095.81 160.598 1271.8 242.665 1329.73 401.832L1626.94 1218.39C1713.83 1457.14 1590.73 1721.13 1351.98 1808.03L1327.97 1816.77L1351.98 1808.03L1019.82 895.404L1055.84 882.292C1075.74 875.051 1085.99 853.052 1078.75 833.156L965.117 520.942C957.875 501.046 935.876 490.788 915.98 498.029L879.955 511.141L792.543 270.978Z" fill="${options.right}"/>
</svg>
`;
const colours: Record<string, string> = {
r: '#F27878',
g: '#65CC76',
b: '#6576CC',
c: '#71AFE5',
m: '#8D58B2',
y: '#EDC575',
k: '#000000',
w: '#FFFFFF',
gr: '#8D8D8D',
d: '#424242'
};
type s = string;
const stringToHex = (input: string) => {
if(!input.startsWith('#') && Object.keys(colours).includes(input)) input = colours[input];
let colour = input.startsWith("#") ? input.slice(1) : input;
const validChars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
const invalidChars = Array.from(colour).filter((i) => !validChars.includes(i));
if (invalidChars.length > 0) return colours.c;
if (colour.length === 1) return `#` + colour.repeat(6);
if (colour.length === 2) return `#` + colour.repeat(3);
if (colour.length === 3) return `#` + colour.repeat(2);
if (colour.length === 6) return `#` + colour;
return colours.c;
};
app.get('/', (req, res) => {
let left = colours.c, right = colours.c;
if (req.query["colour"]) {left = req.query["colour"] as s; right = req.query["colour"] as s;}
if (req.query["color"]) {left = req.query["color"] as s; right = req.query["color"] as s;}
if(req.query['l']) left = req.query['l'] as s;
if(req.query['left']) left = req.query['left'] as s;
if(req.query['r']) right = req.query['r'] as s;
if(req.query['right']) right = req.query['right'] as s;
left = stringToHex(left.toUpperCase());
right = stringToHex(right.toUpperCase());
const size = parseInt((req.query['s'] as s ?? req.query['size'] as s) ?? "2048")
const options: SVGEditOptions = {
left: left,
right: right,
size: size
};
const image = req.query['rotated'] === 'true' || req.query['ro'] === 'true' ?
rotated(options) :
full(options)
return res.send(image)
});
const PORT = 1024;
app.listen(PORT, "127.0.0.2", () => {
console.log(`hosted on ${PORT}`)
});