tatorte only available via token

This commit is contained in:
2025-06-23 14:46:09 +02:00
parent 5be47343c4
commit bb98c3656e
10 changed files with 48 additions and 67 deletions

View File

@@ -19,7 +19,7 @@ export const checkIfExactDirectoryExists = (dir: string): Promise<boolean> => {
});
};
export const getContentofTextObject = async (bucket: string, objPath: string) => {
export const getContentOfTextObject = async (bucket: string, objPath: string) => {
const res = await client.getObject(bucket, objPath);
const text = await new Response(res).text();

View File

@@ -1,6 +1,6 @@
import { fail } from '@sveltejs/kit';
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
import { checkIfExactDirectoryExists, getContentofTextObject } from './s3ClientService';
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
/**
* Get Vorgang and corresponend list of tatorte
@@ -17,12 +17,18 @@ export const getVorgangByCaseId = async (caseId: string) => {
const splittedNameParts = chunk.name.split('/');
const prefix = splittedNameParts[0];
const name = splittedNameParts[1];
if (name === CONFIGFILENAME || name === TOKENFILENAME) continue;
list.push({ ...chunk, name: name, prefix: prefix, show_button: true });
}
return list;
};
/**
* Fetches list of vorgänge from s3 bucket
* @returns list of available cases
*/
export const getListOfVorgänge = async () => {
const stream = client.listObjectsV2(BUCKET, '', false, '');
@@ -30,7 +36,7 @@ export const getListOfVorgänge = async () => {
for await (const chunk of stream) {
const objPath = `${chunk.prefix}${TOKENFILENAME}`;
const token = await getContentofTextObject(BUCKET, objPath);
const token = await getContentOfTextObject(BUCKET, objPath);
const cleanedChunkPrefix = chunk.prefix.replace(/\/$/, '');
list.push({ name: cleanedChunkPrefix, token: token });
@@ -43,7 +49,7 @@ export const getListOfVorgänge = async () => {
* @param request
* @returns fail or true
*/
export const checkIfVorgangExists = async (caseId: string) => {
export const checkIfVorgangExists = async (caseId: string | null) => {
if (!caseId) {
return fail(400, {
success: false,
@@ -68,21 +74,12 @@ export const hasValidToken = async (caseId: string, caseToken: string) => {
try {
if (!caseToken) {
return fail(400, {
success: false,
caseId,
error: { message: 'Bitte Zugangscode eingeben!' }
});
return false;
}
const token = await getContentofTextObject(BUCKET, objPath);
const token = await getContentOfTextObject(BUCKET, objPath);
if (!token || token !== caseToken) {
return fail(400, {
success: false,
caseId,
error: { message: 'Der Token ist ungültig.' }
});
return false;
}
return true;