Merge remote-tracking branch 'origin/main' into Jens
This commit is contained in:
@@ -10,6 +10,7 @@ import * as fs from "fs";
|
||||
import { transport } from "#lib/mail.js";
|
||||
import { BASE_URI } from "#lib/constants.js";
|
||||
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
input: z.object({
|
||||
@@ -99,7 +100,7 @@ export const GET = defineApiRoute({
|
||||
if (pdfAusweis) {
|
||||
const pdfAusweisPath = fileURLToPath(
|
||||
new URL(
|
||||
`../../../../persistent/generated/Ausweis-${ausweis.uid}.pdf`,
|
||||
`${PERSISTENT_DIR}/generated/Ausweis-${ausweis.uid}.pdf`,
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
@@ -109,7 +110,7 @@ export const GET = defineApiRoute({
|
||||
if (pdfDatenblatt) {
|
||||
const pdfDatenblattPath = fileURLToPath(
|
||||
new URL(
|
||||
`../../../../persistent/generated/Datenblatt-${ausweis.uid}.pdf`,
|
||||
`${PERSISTENT_DIR}/generated/Datenblatt-${ausweis.uid}.pdf`,
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { BildSchema, prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import isBase64 from "is-base64";
|
||||
import { fileURLToPath } from "url";
|
||||
import { writeFileSync } from "fs";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.array(UUidWithPrefix),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import moment from "moment";
|
||||
import { prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { encodeToken } from "../../../lib/auth/token.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { TokenType } from "#lib/auth/types.js";
|
||||
@@ -102,7 +102,7 @@ export const GET = defineApiRoute({
|
||||
data: {
|
||||
benutzer_id: user.id,
|
||||
expiry: refreshTokenExpiry.toDate(),
|
||||
ip: ctx.clientAddress ?? "",
|
||||
ip: "",
|
||||
token: refreshToken,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import moment from "moment";
|
||||
import { prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { encodeToken } from "../../../lib/auth/token.js";
|
||||
import { validatePassword } from "../../../lib/password.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -27,8 +27,6 @@ export const GET = defineApiRoute({
|
||||
exp: z.number(),
|
||||
}),
|
||||
async fetch(input, ctx) {
|
||||
console.log(input);
|
||||
|
||||
// Falls der Nutzer nicht existiert, wird eine Fehlermeldung zurückgegeben.
|
||||
const user = await prisma.benutzer.findUnique({
|
||||
where: {
|
||||
@@ -67,7 +65,7 @@ export const GET = defineApiRoute({
|
||||
data: {
|
||||
token: refreshToken,
|
||||
benutzer_id: user.id,
|
||||
ip: ctx.clientAddress ?? "",
|
||||
ip: "",
|
||||
expiry: refreshTokenExpiry.toDate(),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { authorizationMiddleware, maybeAuthorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { prisma, BildSchema } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { defineApiRoute, APIError } from "astro-typesafe-api/server";
|
||||
import { z } from "astro:content";
|
||||
import { fileURLToPath } from "url";
|
||||
import isBase64 from "is-base64";
|
||||
import { writeFileSync } from "fs"
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
import sharp from "sharp"
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: BildSchema.pick({
|
||||
@@ -41,14 +44,13 @@ export const PUT = defineApiRoute({
|
||||
},
|
||||
});
|
||||
|
||||
const filePath = fileURLToPath(new URL(`../../../persistent/images/${bild.uid}.webp`, import.meta.url));
|
||||
const filePath = fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bild.uid}.jpg`, import.meta.url));
|
||||
|
||||
try {
|
||||
// Wir optimieren das Bild und konvertieren es in WebP
|
||||
// TODO: Sharp scheint nicht zu funktionieren, wir müssen das nochmal testen
|
||||
// const optimizedBuffer = await sharp(buffer).webp({ quality: 80 }).toArray();
|
||||
// Wir optimieren das Bild und konvertieren es in JPEG
|
||||
const optimizedBuffer = await sharp(buffer).jpeg({ quality: 80 }).toBuffer();
|
||||
|
||||
writeFileSync(filePath, buffer)
|
||||
writeFileSync(filePath, optimizedBuffer)
|
||||
} catch(e) {
|
||||
// Bild wurde nicht gespeichert, wir löschen den Eintrag wieder
|
||||
await prisma.bild.delete({
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { BildSchema, prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import isBase64 from "is-base64";
|
||||
import { fileURLToPath } from "url";
|
||||
import { writeFileSync } from "fs";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import sharp from "sharp"
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
export const PATCH = defineApiRoute({
|
||||
input: BildSchema.pick({
|
||||
@@ -65,14 +68,14 @@ export const PATCH = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
const filePath = fileURLToPath(new URL(`../../../../../persistent/images/${image.uid}.webp`, import.meta.url));
|
||||
const filePath = fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${image.uid}.jpg`, import.meta.url));
|
||||
|
||||
try {
|
||||
// Wir optimieren das Bild und konvertieren es in WebP
|
||||
// TODO: Sharp scheint nicht zu funktionieren, wir müssen das nochmal testen
|
||||
// const optimizedBuffer = await sharp(buffer).webp({ quality: 80 }).toArray();
|
||||
const optimizedBuffer = await sharp(buffer).jpeg({ quality: 80 }).toBuffer();
|
||||
|
||||
writeFileSync(filePath, buffer)
|
||||
writeFileSync(filePath, optimizedBuffer)
|
||||
} catch(e) {
|
||||
// Und geben einen Fehler zurück
|
||||
throw new APIError({
|
||||
|
||||
@@ -4,6 +4,7 @@ import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import { fileURLToPath } from "url";
|
||||
import { writeFileSync } from "fs";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: UnterlageSchema.omit({
|
||||
@@ -37,7 +38,7 @@ export const PUT = defineApiRoute({
|
||||
},
|
||||
});
|
||||
|
||||
const filePath = fileURLToPath(new URL(`../../../persistent/unterlagen/${unterlage.uid}`, import.meta.url));
|
||||
const filePath = fileURLToPath(new URL(`${PERSISTENT_DIR}/unterlagen/${unterlage.uid}`, import.meta.url));
|
||||
|
||||
try {
|
||||
writeFileSync(filePath, buffer)
|
||||
|
||||
40
src/pages/bilder/[uid].jpg.ts
Normal file
40
src/pages/bilder/[uid].jpg.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIRoute } from "astro";
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
export const GET: APIRoute = async (Astro) => {
|
||||
const { uid } = Astro.params;
|
||||
|
||||
const image = await prisma.bild.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
});
|
||||
|
||||
if (!image) {
|
||||
return new Response(null, {
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
|
||||
const path = fileURLToPath(
|
||||
new URL(`${PERSISTENT_DIR}/images/${image.uid}.jpg`, import.meta.url)
|
||||
);
|
||||
|
||||
if (!fs.existsSync(path)) {
|
||||
return new Response(null, {
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
|
||||
const buffer = fs.readFileSync(path);
|
||||
|
||||
return new Response(buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "image/jpeg",
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
import { prisma } from "#lib/server/prisma";
|
||||
import { APIRoute } from "astro";
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export const GET: APIRoute = async (Astro) => {
|
||||
const { uid } = Astro.params
|
||||
|
||||
const image = await prisma.bild.findUnique({
|
||||
where: {
|
||||
uid
|
||||
}
|
||||
})
|
||||
|
||||
if (!image) {
|
||||
return new Response(null, {
|
||||
status: 404
|
||||
})
|
||||
}
|
||||
|
||||
const path = fileURLToPath(new URL(`../../../persistent/images/${image.uid}.webp`, import.meta.url))
|
||||
|
||||
if (!fs.existsSync(path)) {
|
||||
return new Response(null, {
|
||||
status: 404
|
||||
})
|
||||
}
|
||||
|
||||
const buffer = fs.readFileSync(path)
|
||||
|
||||
return new Response(buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "image/webp"
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import ProduktUebersichtBedarfsausweisGewerbe from "#components/design/content/P
|
||||
import ProduktUebersichtVerbrauchsausweisWohnen from "#components/design/content/ProduktUebersichtVerbrauchsausweisWohnen.svelte";
|
||||
import ProduktUebersichtVerbrauchsausweisGewerbe from "#components/design/content/ProduktUebersichtVerbrauchsausweisGewerbe.svelte";
|
||||
import { PRICES } from "#lib/constants.js";
|
||||
import { Enums } from "@ibcornelsen/database/client";
|
||||
import { Enums } from "#lib/server/prisma";
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AufnahmeClient, BenutzerClient, getAusweisartFromUUID, ObjektClient, Up
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { pdfVerbrauchsausweisGewerbe } from "#lib/pdf/pdfVerbrauchsausweisGewerbe.js";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen.js";
|
||||
import { Enums } from "#lib/client/prisma";
|
||||
import { Enums } from "#lib/client/prisma.js";
|
||||
import { APIRoute } from "astro";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pdfDatenblattVerbrauchsausweisGewerbe } from "#lib/pdf/pdfDatenblattVer
|
||||
import { pdfDatenblattVerbrauchsausweisWohnen } from "#lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.js";
|
||||
import { pdfVerbrauchsausweisGewerbe } from "#lib/pdf/pdfVerbrauchsausweisGewerbe.js";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen.js";
|
||||
import { Enums } from "#lib/client/prisma";
|
||||
import { Enums } from "#lib/client/prisma.js";
|
||||
import { APIRoute } from "astro";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user