feat: new separate frontend and backend folders with fastify as nodejs framework, libreconvert is configured in fastify as route

This commit is contained in:
theoleuthardt 2025-02-14 14:40:35 +01:00
parent 7b584d2fff
commit 9733de9a39
26 changed files with 1171 additions and 61 deletions

View file

@ -0,0 +1,18 @@
import type { Metadata } from "next";
export const metadata: Metadata = {
title: "doc-to-pdf",
description: "Converter for documents to pdf format!",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`antialiased`}>{children}</body>
</html>
);
}

View file

@ -0,0 +1,111 @@
"use client";
import React, { useState } from "react";
import Navbar from "../../components/Navbar";
import Footer from "../../components/Footer";
import Button from "../../components/Button";
import Link from "next/link";
export default function Home() {
const [file, setFile] = useState<File | null>(null);
const [downloadUrl, setDownloadUrl] = useState<string>("");
const [loading, setLoading] = useState(false);
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files && event.target.files.length > 0) {
setFile(event.target.files[0]);
setDownloadUrl("");
}
};
const convertToPdf = async () => {
if (!file) {
alert("No file selected");
return;
}
const formData = new FormData();
formData.append("file", file);
setLoading(true);
try {
const response = await fetch(
process.env.backend_url + "/api/libre-convert",
{
method: "POST",
body: formData,
},
);
if (!response.ok) {
return new Error(`Error: ${response.statusText}`);
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
setDownloadUrl(url);
} catch (error) {
console.error("Error while converting:", error);
alert("Error while converting");
} finally {
setLoading(false);
}
};
return (
<div className="h-screen w-screen bg-black text-white font-noto flex flex-col items-center">
<Navbar renderHomeLink={true} />
<div className="w-screen h-screen flex flex-col items-center justify-center">
<h2 className="text-5xl font-bold text-white mb-16">doc-to-pdf</h2>
<table className="border-2 border-white text-xl rounded-xl mb-16">
<thead>
<tr>
<th>Input Format</th>
<th>Output Format</th>
</tr>
</thead>
<tbody>
<tr>
<td>docx</td>
<td>pdf</td>
</tr>
<tr>
<td>doc</td>
<td>pdf</td>
</tr>
<tr>
<td>odt</td>
<td>pdf</td>
</tr>
</tbody>
</table>
<input
type="file"
className="border-2 border-white p-3 rounded-xl text-center text-white"
id="documentUpload"
onChange={handleFileChange}
/>
<div className={"flex flex-row items-center gap-4 mt-4"}>
{downloadUrl ? (
<Link id="downloadPDF" href={downloadUrl}>
<Button content="download" />
</Link>
) : (
<Button
content={
loading ? (
<div className="h-10 w-10 border-8 border-blue-100 border-t-blue-500 rounded-full animate-spin" />
) : (
"convert"
)
}
onClick={convertToPdf}
/>
)}
</div>
</div>
<Footer />
</div>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

View file

@ -0,0 +1,5 @@
@import url("https://fonts.googleapis.com/css2?family=Noto+Serif:ital,wght@0,100..900;1,100..900&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;

View file

@ -0,0 +1,25 @@
import type { Metadata } from "next";
import "./globals.css";
export const metadata: Metadata = {
title: "Werkzeugkiste",
description: "Collection of useful digital utilities",
icons: [
{
rel: "icon",
url: "/favicon.ico",
},
],
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`antialiased`}>{children}</body>
</html>
);
}

27
frontend/src/app/page.tsx Normal file
View file

@ -0,0 +1,27 @@
import Navbar from "../components/Navbar";
import Footer from "../components/Footer";
import { toolLinks } from "@/constants";
export default function Home() {
return (
<div className="h-screen w-screen bg-black text-white font-noto flex flex-col items-center">
<Navbar renderHomeLink={false} />
<div className="w-screen h-screen flex flex-col items-center justify-center">
<div className="grid grid-cols-3 gap-6">
{toolLinks.map((tool) => (
<a
key={tool.title}
href={tool.link}
className="text-2xl border-2 border-white p-6 flex justify-center rounded-2xl shadow-md
shadow-white hover:scale-110 hover:transition-scale hover:duration-200
hover:text-blue-400 hover:border-blue-400 hover:shadow-blue-400"
>
{tool.title}
</a>
))}
</div>
</div>
<Footer />
</div>
);
}

View file

@ -0,0 +1 @@
<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128px" height="128px"> <path d="M 43.800781 24.800781 C 40.200781 24.800781 36.799219 26.6 34.699219 29.5 L 13 60.300781 C 12.6 60.800781 12.5 61.4 12.5 62 L 12.5 92.099609 C 12.5 98.199609 17.499609 103.19922 23.599609 103.19922 L 64 103.19922 L 64.5 103.19922 L 64.800781 103.19922 L 104.40039 103.19922 C 110.50039 103.19922 115.5 98.299219 115.5 92.199219 L 115.5 62 C 115.5 61.8 115.50039 61.6 115.40039 61.5 L 115.40039 61.300781 C 115.40039 61.200781 115.30078 61.1 115.30078 61 C 115.30078 60.9 115.29922 60.900781 115.19922 60.800781 C 115.09922 60.700781 115.1 60.6 115 60.5 C 115 60.5 115.00039 60.400391 114.90039 60.400391 L 93.300781 29.5 C 91.200781 26.6 87.799219 24.800781 84.199219 24.800781 C 80.599219 24.800781 77.199609 26.6 75.099609 29.5 L 73.400391 31.900391 L 63.599609 31.900391 C 61.899609 31.900391 60.599609 33.200391 60.599609 34.900391 C 60.599609 36.600391 61.899609 37.900391 63.599609 37.900391 L 80 37.900391 C 81.2 37.900391 82.199219 38.800391 82.199219 39.900391 C 82.199219 41.000391 81.2 41.900391 80 41.900391 L 68 41.900391 C 67 41.900391 66.1 42.399219 65.5 43.199219 L 64 45.300781 L 52.900391 29.5 C 50.800391 26.6 47.400781 24.800781 43.800781 24.800781 z M 43.800781 30.800781 C 45.500781 30.800781 47 31.6 48 33 L 69.099609 63 L 69.099609 92.199219 C 69.099609 94.999219 66.8 97.199219 64 97.199219 L 23.599609 97.199219 C 20.799609 97.199219 18.5 94.899219 18.5 92.199219 L 18.5 63 L 39.599609 33 C 40.599609 31.6 42.100781 30.800781 43.800781 30.800781 z M 84.199219 30.900391 C 85.899219 30.900391 87.400391 31.699609 88.400391 33.099609 L 106.69922 59.099609 L 83.599609 59.099609 L 77.599609 50.599609 L 79.5 47.900391 L 80 47.900391 C 84.5 47.900391 88.199219 44.300391 88.199219 39.900391 C 88.199219 35.800391 85.1 32.5 81 32 C 81.9 31.3 82.999219 30.900391 84.199219 30.900391 z M 43.800781 34.900391 A 5 5 0 0 0 38.800781 39.900391 A 5 5 0 0 0 43.800781 44.900391 A 5 5 0 0 0 48.800781 39.900391 A 5 5 0 0 0 43.800781 34.900391 z M 75.099609 65 L 109.5 65 L 109.5 92.099609 C 109.5 94.899609 107.20039 97.099609 104.40039 97.099609 L 73.900391 97.099609 C 74.600391 95.699609 75.099609 93.899609 75.099609 92.099609 L 75.099609 65 z"/></svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,30 @@
import React, { JSX } from "react";
interface ButtonProps {
className?: string;
content: string | JSX.Element;
onClick?: () => void;
visible?: boolean;
}
const Button = ({
className,
content,
onClick,
visible = true,
}: ButtonProps) => {
return (
<button
className={
`p-3 border-2 border-white rounded-xl text-2xl hover:scale-110 hover:transition-scale hover:duration-200
hover:text-blue-400 hover:border-blue-400 ` + className
}
onClick={() => onClick && onClick()}
style={{ display: visible ? "block" : "none" }}
>
{content}
</button>
);
};
export default Button;

View file

@ -0,0 +1,30 @@
import React from "react";
interface FooterProps {
className?: string;
}
const Footer = (props: FooterProps) => {
return (
<div className={`h-18 w-full p-3 ` + props.className}>
<div className="text-md text-white font-bold flex flex-row items-center justify-center">
<p>made by</p>
<a
className="mx-2 hover:underline hover:text-blue-400"
href="https://github.com/AuriomTex"
>
Domi
</a>
<p>and</p>
<a
className="mx-2 hover:underline hover:text-blue-400"
href="https://github.com/theoleuthardt"
>
Theo.
</a>
</div>
</div>
);
};
export default Footer;

View file

@ -0,0 +1,42 @@
import React from "react";
import Image from "next/image";
import LOGO from "../assets/werkzeugkasten.svg";
import Link from "next/link";
interface NavProps {
className?: string;
renderHomeLink: boolean;
}
const Navbar = (props: NavProps) => {
return (
<div className={`h-18 w-full p-3 ` + props.className}>
<nav className="h-14 bg-black text-white font-bold flex flex-row items-center justify-between">
<div className="justify-items-start flex flex-1 flex-row items-center">
<Image src={LOGO} alt="" width={70} height={70} className="invert" />
<div className="text-white text-2xl ml-5">werkzeugkiste.</div>
</div>
<div className="flex flex-auto justify-center">
{props.renderHomeLink ? (
<Link
href="/"
className="justify-center text-2xl hover:underline hover:transition-underline hover:duration-300 hover:text-blue-400"
>
home
</Link>
) : null}
</div>
<div className="flex flex-1 justify-end">
<Link
href="https://github.com/theoleuthardt/werkzeugkiste"
className="items-end mr-3 text-2xl hover:underline hover:transition-underline hover:duration-300 hover:text-blue-400"
>
github
</Link>
</div>
</nav>
</div>
);
};
export default Navbar;

View file

@ -0,0 +1,38 @@
export const toolLinks = [
{
title: "doc-to-pdf",
link: "/doc-to-pdf",
},
{
title: "img-to-png",
link: "/img-to-png",
},
{
title: "rgb-to-hex",
link: "/rgb-to-hex",
},
{
title: "video-to-gif",
link: "/video-to-gif",
},
{
title: "qr-code-generator",
link: "/qr-code-generator",
},
{
title: "password-generator",
link: "/password-generator",
},
{
title: "bg-remover",
link: "/bg-remover",
},
{
title: "word-counter",
link: "/word-counter",
},
{
title: "pomodoro-timer",
link: "/pomodoro-timer",
},
];