Dashboard, Datenblatt usw.

This commit is contained in:
Moritz Utcke
2025-02-19 18:12:48 +11:00
parent 198912c792
commit 69566f1c74
39 changed files with 1479 additions and 420 deletions

View File

@@ -2,28 +2,26 @@
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js";
import { prisma } from "@ibcornelsen/database/server";
import { APIRoute } from "astro";
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
import * as fs from "fs";
import { fileURLToPath } from "url";
export const GET = defineApiRoute({
async fetch(input, context, transfer) {
const { uid } = context.params
const token = context.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
export const GET: APIRoute = async (Astro) => {
const { uid } = Astro.params
const token = Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
if (!token) {
throw new APIError({
code: "BAD_REQUEST",
message: "Invalid access token"
return new Response(null, {
status: 400
})
}
const valid = validateAccessTokenServer(context);
const valid = validateAccessTokenServer(Astro);
if (!valid) {
throw new APIError({
code: "BAD_REQUEST",
message: "Invalid access token"
return new Response(null, {
status: 401
})
}
@@ -34,21 +32,18 @@ export const GET = defineApiRoute({
})
if (!image) {
throw new APIError({
code: "NOT_FOUND",
message: "Image could not be found."
return new Response(null, {
status: 404
})
}
const path = fileURLToPath(new URL(`../../../persistent/images/${image.uid}.webp`, import.meta.url))
const base64 = fs.readFileSync(path, "base64")
const buffer = Buffer.from(base64, "base64");
const buffer = fs.readFileSync(path)
return new Response(buffer, {
status: 200,
headers: {
"Content-Type": "image/webp"
}
});
},
})
}