fix: prettier formating

This commit is contained in:
Domenik 2025-02-20 20:49:24 +01:00
parent 544ebaa7cf
commit 7b4ef9c70b
13 changed files with 172 additions and 154 deletions

View file

@ -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 });

View file

@ -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);

View file

@ -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!" });
}
},
);
}
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!" });
}
},
);
}

View file

@ -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