Persistent Directory
This commit is contained in:
@@ -13,7 +13,7 @@ export default defineConfig({
|
||||
outDir: "./dist",
|
||||
output: "server",
|
||||
adapter: node({
|
||||
mode: "middleware"
|
||||
mode: "middleware",
|
||||
}),
|
||||
vite: {
|
||||
ssr: {
|
||||
|
||||
BIN
persistent/images/img-741ae0ba-9f33-4eb5-adfc-391e29dcdbdc.jpg
Normal file
BIN
persistent/images/img-741ae0ba-9f33-4eb5-adfc-391e29dcdbdc.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
@@ -5,7 +5,6 @@ export const createCaller = createCallerFactory({
|
||||
"klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"),
|
||||
"postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"),
|
||||
"unterlage": await import("../src/pages/api/unterlage.ts"),
|
||||
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
|
||||
"admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"),
|
||||
"admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"),
|
||||
"admin/erinnern": await import("../src/pages/api/admin/erinnern.ts"),
|
||||
@@ -14,25 +13,26 @@ export const createCaller = createCallerFactory({
|
||||
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
|
||||
"admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"),
|
||||
"ausweise": await import("../src/pages/api/ausweise/index.ts"),
|
||||
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
|
||||
"auth/access-token": await import("../src/pages/api/auth/access-token.ts"),
|
||||
"auth/forgot-password": await import("../src/pages/api/auth/forgot-password.ts"),
|
||||
"auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"),
|
||||
"bedarfsausweis-wohnen/[uid]": await import("../src/pages/api/bedarfsausweis-wohnen/[uid].ts"),
|
||||
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
|
||||
"bilder/[uid]": await import("../src/pages/api/bilder/[uid].ts"),
|
||||
"geg-nachweis-wohnen/[uid]": await import("../src/pages/api/geg-nachweis-wohnen/[uid].ts"),
|
||||
"geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"),
|
||||
"geg-nachweis-gewerbe/[uid]": await import("../src/pages/api/geg-nachweis-gewerbe/[uid].ts"),
|
||||
"geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"),
|
||||
"geg-nachweis-wohnen/[uid]": await import("../src/pages/api/geg-nachweis-wohnen/[uid].ts"),
|
||||
"geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"),
|
||||
"objekt": await import("../src/pages/api/objekt/index.ts"),
|
||||
"rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"),
|
||||
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
|
||||
"objekt": await import("../src/pages/api/objekt/index.ts"),
|
||||
"ticket": await import("../src/pages/api/ticket/index.ts"),
|
||||
"user": await import("../src/pages/api/user/index.ts"),
|
||||
"user/self": await import("../src/pages/api/user/self.ts"),
|
||||
"ticket": await import("../src/pages/api/ticket/index.ts"),
|
||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||
"verbrauchsausweis-gewerbe/[uid]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[uid].ts"),
|
||||
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
|
||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||
"verbrauchsausweis-wohnen/[uid]": await import("../src/pages/api/verbrauchsausweis-wohnen/[uid].ts"),
|
||||
"verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"),
|
||||
"aufnahme/[uid]/bilder": await import("../src/pages/api/aufnahme/[uid]/bilder.ts"),
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { addNotification } from "#components/Notifications/shared.js";
|
||||
import { CheckCircled, CrossCircled, Image } from "radix-svelte-icons";
|
||||
import ChevronDown from "radix-svelte-icons/src/lib/icons/ChevronDown.svelte";
|
||||
import { Event } from "#lib/client/prisma";
|
||||
import { Event } from "#lib/client/prisma.js";
|
||||
import { api } from "astro-typesafe-api/client";
|
||||
import Cookies from "js-cookie";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Heizungsstatus } from "#lib/server/prisma.js";
|
||||
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016 } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { copyPage } from "./utils/copyPage.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
/* -------------------------------- Pdf Tools ------------------------------- */
|
||||
|
||||
@@ -359,7 +360,7 @@ export async function pdfDatenblattVerbrauchsausweisGewerbe(ausweis: Verbrauchsa
|
||||
let image: string = "";
|
||||
|
||||
if (bild.uid) {
|
||||
image = `<img src="${fileURLToPath(new URL(`../../../../persistent/images/${bilder[0].uid}.jpg`, import.meta.url))}" width="${(pages[2].getHeight() - 120) / 3.1}" />`
|
||||
image = `<img src="${fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bilder[0].uid}.jpg`, import.meta.url))}" width="${(pages[2].getHeight() - 120) / 3.1}" />`
|
||||
} else if (bild.data) {
|
||||
image = `<img data="${bild.data}" width="${(pages[2].getWidth() - 120) / 3.1}" height="180" />`
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import moment from "moment";
|
||||
import { BilderKategorie, Heizungsstatus } from "#lib/server/prisma";
|
||||
import { fileURLToPath } from "url";
|
||||
import { copyPage } from "./utils/copyPage.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
/* -------------------------------- Pdf Tools ------------------------------- */
|
||||
|
||||
@@ -303,7 +304,7 @@ export async function pdfDatenblattVerbrauchsausweisWohnen(ausweis: Verbrauchsau
|
||||
let img: string;
|
||||
|
||||
if (c.uid) {
|
||||
img = `<img src="${fileURLToPath(new URL(`../../../../persistent/images/${bilder[0].uid}.jpg`, import.meta.url))}" width="${(pages[2].getHeight() - 120) / 4.1}" height="${individualHeight}" />`
|
||||
img = `<img src="${fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bilder[0].uid}.jpg`, import.meta.url))}" width="${(pages[2].getHeight() - 120) / 4.1}" height="${individualHeight}" />`
|
||||
} else {
|
||||
img = `<img data="${c.data}" width="${(pages[2].getWidth() - 120) / 4.1}" height="${individualHeight}" />`
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { addCheckMark } from "./utils/checkbox.js";
|
||||
import { addText } from "./utils/text.js";
|
||||
import { addAnsichtsausweisLabel, addDatumGEG } from "./utils/helpers.js";
|
||||
import { fileURLToPath } from "url";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
|
||||
/* -------------------------------- Pdf Tools ------------------------------- */
|
||||
|
||||
@@ -85,7 +86,7 @@ export async function pdfVerbrauchsausweisWohnen(ausweis: VerbrauchsausweisWohne
|
||||
const bild = bilder && bilder.find(image => image.kategorie === Enums.BilderKategorie.Gebaeude);
|
||||
|
||||
if (bild) {
|
||||
const file = fs.readFileSync(fileURLToPath(new URL(`../../../persistent/images/${bild.uid}.jpg`, import.meta.url)))
|
||||
const file = fs.readFileSync(fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bild.uid}.jpg`, import.meta.url)))
|
||||
let image: PDFImage;
|
||||
image = await pdf.embedJpg(file)
|
||||
pages[0].drawImage(image, {
|
||||
|
||||
8
src/lib/server/constants.ts
Normal file
8
src/lib/server/constants.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import os from "os"
|
||||
import fs from "fs"
|
||||
|
||||
export const PERSISTENT_DIR = `${os.homedir()}/persistent/online-energieausweis`
|
||||
|
||||
if (!fs.existsSync(PERSISTENT_DIR)) {
|
||||
fs.mkdirSync(PERSISTENT_DIR)
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -8,6 +8,7 @@ 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({
|
||||
@@ -43,7 +44,7 @@ export const PUT = defineApiRoute({
|
||||
},
|
||||
});
|
||||
|
||||
const filePath = fileURLToPath(new URL(`../../../persistent/images/${bild.uid}.jpg`, 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 JPEG
|
||||
@@ -51,8 +52,6 @@ export const PUT = defineApiRoute({
|
||||
|
||||
writeFileSync(filePath, optimizedBuffer)
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
|
||||
// Bild wurde nicht gespeichert, wir löschen den Eintrag wieder
|
||||
await prisma.bild.delete({
|
||||
where: {
|
||||
|
||||
@@ -8,6 +8,7 @@ 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({
|
||||
@@ -67,7 +68,7 @@ export const PATCH = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
const filePath = fileURLToPath(new URL(`../../../../../persistent/images/${image.uid}.jpg`, 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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
@@ -19,7 +20,7 @@ export const GET: APIRoute = async (Astro) => {
|
||||
}
|
||||
|
||||
const path = fileURLToPath(
|
||||
new URL(`../../../persistent/images/${image.uid}.jpg`, import.meta.url)
|
||||
new URL(`${PERSISTENT_DIR}/images/${image.uid}.jpg`, import.meta.url)
|
||||
);
|
||||
|
||||
if (!fs.existsSync(path)) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user