Merge branch 'main' into feat/doc-converter

This commit is contained in:
Theo Leuthardt 2025-02-18 10:18:09 +01:00 committed by GitHub
commit 8fe6657200
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 315 additions and 27 deletions

View file

@ -0,0 +1,29 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
interface RequestBody {
red: string;
green: string;
blue: string;
}
export async function colorConvert(app: FastifyInstance) {
app.post(
"/api/color-convert",
async (
request: FastifyRequest<{ Body: RequestBody }>,
reply: FastifyReply,
) => {
try {
const data = request.body;
if (!data) {
return reply.status(400).send({ error: "No RGB declared!" });
}
const hex = (`#${(+data.red).toString(16).padStart(2, "0")}${(+data.green).toString(16).padStart(2, "0")}${(+data.blue).toString(16).padStart(2, "0")}`).toUpperCase();
reply.header("Content-Type", "application/json").send({ hex: hex });
} catch (error) {
console.error("Convert error:", error);
reply.status(500).send({ error: "Error while converting!" });
}
},
);
}

View file

@ -62,4 +62,4 @@ export async function libreConvert(app: FastifyInstance) {
reply.status(500).send({ error: "Error while converting!" });
}
});
}
}