Neue Datenbank eingebunden

This commit is contained in:
Moritz Utcke
2023-05-10 19:40:22 +04:00
parent 724f3ff546
commit 33c8a1d447
26 changed files with 483 additions and 631 deletions

View File

@@ -1,8 +1,13 @@
<script lang="ts">
import { Bedarfsausweis } from "src/lib/Ausweis/Bedarfsausweis";
import { Verbrauchsausweis } from "src/lib/Ausweis/Verbrauchsausweis";
import { VerbrauchsausweisGewerbe } from "src/lib/Ausweis/VerbrauchsausweisGewerbe";
export let max: number = 2;
// Array of base64 encoded images read into the input.
export let images: (File & { data: string })[] = [];
export let ausweis: Verbrauchsausweis | VerbrauchsausweisGewerbe | Bedarfsausweis;
function getAllImages(this: HTMLInputElement) {
const files = this.files || [];
@@ -15,9 +20,6 @@
for (let i = 0; i < files.length; i++) {
const file = files[i];
console.log(file.type);
if ((file.type !== "image/jpeg") && (file.type !== "image/png")) {
i--;
continue;
@@ -55,17 +57,28 @@
ctx.drawImage(image, 0, 0, image.naturalWidth, image.naturalHeight);
// Get the scaled-down data from the canvas in the desired output format and quality
const dataURL = canvas.toDataURL("image/jpeg", 0.75);
const dataURL = canvas.toDataURL("image/jpeg", 0.8);
images.push({ ...file, data: dataURL as string } as (File & { data: string }));
fetch("/api/image", {
method: "PUT",
body: JSON.stringify({
data: dataURL,
name: file.name
data: dataURL.split(';base64,')[1],
name: file.name,
kategorie: "",
gebaeude_uid: ausweis.gebaeude_uid
})
}).then(response => response.json()).then(json => {
if (json.success === false) {
return
}
images.push({ ...file, data: dataURL as string } as (File & { data: string }));
images = images;
ausweis.uid = json.data.gebaeude_uid;
})
images = images;
if (i == (Math.min(files.length, max) - 1)) {
this.value = "";