diff --git a/README.md b/README.md index ba24a02..78ddaf7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ files, generate content, or using other handy digital utilities. This page is ma To install and run the project locally, follow these steps: 1. **Clone the repository**: + ```bash git clone https://github.com/theoleuthardt/werkzeugkiste.git cd werkzeugkiste diff --git a/backend/server.ts b/backend/server.ts index 608a095..bbbf6ba 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -3,7 +3,7 @@ import cors from "@fastify/cors"; import multipart from "@fastify/multipart"; import { libreConvert } from "./src/routes/libreconvert.route"; import { colorConvert } from "./src/routes/colorconvert.route"; -import {passwordGenerate} from "./src/routes/passwordgenerate.route"; +import { passwordGenerate } from "./src/routes/passwordgenerate.route"; import { regexTest } from "./src/routes/regextest.route"; const app = Fastify({ logger: true }); diff --git a/backend/src/routes/colorconvert.route.ts b/backend/src/routes/colorconvert.route.ts index 11ca8c8..a506d0a 100644 --- a/backend/src/routes/colorconvert.route.ts +++ b/backend/src/routes/colorconvert.route.ts @@ -18,7 +18,8 @@ export async function colorConvert(app: FastifyInstance) { 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(); + 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", "text/plain").status(200).send(hex); } catch (error) { console.error("Convert error:", error); diff --git a/backend/src/routes/passwordgenerate.route.ts b/backend/src/routes/passwordgenerate.route.ts index 7b1345d..b539341 100644 --- a/backend/src/routes/passwordgenerate.route.ts +++ b/backend/src/routes/passwordgenerate.route.ts @@ -1,60 +1,62 @@ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; interface RequestBody { - length: string; - numb: boolean; - lower: boolean; - upper: boolean; - special: boolean; + length: string; + numb: boolean; + lower: boolean; + upper: boolean; + special: boolean; } export async function passwordGenerate(app: FastifyInstance) { - app.post( - "/api/password-generate", - async ( - request: FastifyRequest<{ Body: RequestBody }>, - reply: FastifyReply, - ) => { - try { - const data = request.body; - if (!data) { - return reply.status(400).send({ error: "No length or type declared!" }); - } - let numArray: string[] = "0123456789".split(""); - let lowerArray: string[] = "abcdefghijklmnopqrstuvwxyz".split(""); - let upperArray: string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); - let specialArray: string[] = "!@#$%^&*()_+[]{}|;:,.<>?".split(""); - let passwordArray: string[] = []; + app.post( + "/api/password-generate", + async ( + request: FastifyRequest<{ Body: RequestBody }>, + reply: FastifyReply, + ) => { + try { + const data = request.body; + if (!data) { + return reply + .status(400) + .send({ error: "No length or type declared!" }); + } + let numArray: string[] = "0123456789".split(""); + let lowerArray: string[] = "abcdefghijklmnopqrstuvwxyz".split(""); + let upperArray: string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); + let specialArray: string[] = "!@#$%^&*()_+[]{}|;:,.<>?".split(""); + let passwordArray: string[] = []; - if(data.numb){ - passwordArray = passwordArray.concat(numArray); - } + if (data.numb) { + passwordArray = passwordArray.concat(numArray); + } - if(data.lower){ - passwordArray = passwordArray.concat(lowerArray); - } + if (data.lower) { + passwordArray = passwordArray.concat(lowerArray); + } - if(data.upper){ - passwordArray = passwordArray.concat(upperArray); - } + if (data.upper) { + passwordArray = passwordArray.concat(upperArray); + } - if(data.special){ - passwordArray = passwordArray.concat(specialArray); - } + if (data.special) { + passwordArray = passwordArray.concat(specialArray); + } - let password = ""; + let password = ""; - for (let i = 0; i < +data.length; i++) { - const ind: number = Math.floor(Math.random() * passwordArray.length); - const randomElement: string = passwordArray[ind]; - password = password.concat(randomElement); - } + for (let i = 0; i < +data.length; i++) { + const ind: number = Math.floor(Math.random() * passwordArray.length); + const randomElement: string = passwordArray[ind]; + password = password.concat(randomElement); + } - reply.header("Content-Type", "text/plain").status(200).send(password); - } catch (error) { - console.error("Convert error:", error); - reply.status(500).send({ error: "Error while converting!" }); - } - }, - ); -} \ No newline at end of file + reply.header("Content-Type", "text/plain").status(200).send(password); + } catch (error) { + console.error("Convert error:", error); + reply.status(500).send({ error: "Error while converting!" }); + } + }, + ); +} diff --git a/backend/src/routes/regextest.route.ts b/backend/src/routes/regextest.route.ts index ef2f9a5..ff903e4 100644 --- a/backend/src/routes/regextest.route.ts +++ b/backend/src/routes/regextest.route.ts @@ -20,7 +20,9 @@ export async function regexTest(app: FastifyInstance) { // Überprüfe, ob die Felder regex und test vorhanden sind if (!data.regex || !data.test) { - return reply.status(400).send({ error: "Regex or test string missing!" }); + return reply + .status(400) + .send({ error: "Regex or test string missing!" }); } // Versuche, den regulären Ausdruck zu erstellen @@ -28,7 +30,9 @@ export async function regexTest(app: FastifyInstance) { try { regexPattern = new RegExp(data.regex); } catch (e) { - return reply.status(400).send({ error: "Invalid regular expression!" }); + return reply + .status(400) + .send({ error: "Invalid regular expression!" }); } // Teste den Eingabestring gegen das Regex diff --git a/docker-compose.yaml b/docker-compose.yaml index f3e968d..86cf1d9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -29,4 +29,4 @@ services: networks: default: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/frontend/src/app/password-generator/layout.tsx b/frontend/src/app/password-generator/layout.tsx index 629d241..e144fbb 100644 --- a/frontend/src/app/password-generator/layout.tsx +++ b/frontend/src/app/password-generator/layout.tsx @@ -8,13 +8,13 @@ export const metadata: Metadata = { }; export default function RootLayout({ - children, - }: Readonly<{ + children, +}: Readonly<{ children: React.ReactNode; }>) { return ( -
{children} + {children} ); } diff --git a/frontend/src/app/password-generator/page.tsx b/frontend/src/app/password-generator/page.tsx index 4329f70..eda0f9e 100644 --- a/frontend/src/app/password-generator/page.tsx +++ b/frontend/src/app/password-generator/page.tsx @@ -6,19 +6,21 @@ import Footer from "../../components/Footer"; import Button from "../../components/Button"; export default function RgbToHex() { - const [loading, setLoading] = useState(false); const [password, setPassword] = useState(""); const generatePassword = async () => { - setLoading(true); - const length = (document.getElementById("length") as HTMLInputElement).value; + const length = (document.getElementById("length") as HTMLInputElement) + .value; const numb = (document.getElementById("numb") as HTMLInputElement).checked; - const lower = (document.getElementById("lower") as HTMLInputElement).checked; - const upper = (document.getElementById("upper") as HTMLInputElement).checked; - const special = (document.getElementById("special") as HTMLInputElement).checked; + const lower = (document.getElementById("lower") as HTMLInputElement) + .checked; + const upper = (document.getElementById("upper") as HTMLInputElement) + .checked; + const special = (document.getElementById("special") as HTMLInputElement) + .checked; try { const response = await fetch( @@ -28,7 +30,13 @@ export default function RgbToHex() { headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ length: length, numb: numb, lower: lower, upper: upper, special: special }), + body: JSON.stringify({ + length: length, + numb: numb, + lower: lower, + upper: upper, + special: special, + }), }, ); if (!response.ok) { @@ -37,7 +45,6 @@ export default function RgbToHex() { const password: string = await response.text(); console.log(password); setPassword(password); - } catch (error) { console.error("Error while converting:", error); alert("Error while converting"); @@ -61,10 +68,10 @@ export default function RgbToHex() { }; const checkInput = (event: React.ChangeEvent