mirror of
https://github.com/theoleuthardt/werkzeugkiste.git
synced 2026-06-13 09:37:53 +00:00
feat: new separate frontend and backend folders with fastify as nodejs framework, libreconvert is configured in fastify as route
This commit is contained in:
parent
7b584d2fff
commit
9733de9a39
26 changed files with 1171 additions and 61 deletions
|
|
@ -1,92 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import React, { useEffect, 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("/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);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (file) {
|
||||
console.log(file);
|
||||
}
|
||||
}, [file]);
|
||||
|
||||
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>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue