vorgang accessible via url
This commit is contained in:
@@ -8,3 +8,4 @@ import config from '$lib/config';
|
||||
export const client = new Client(config.minio);
|
||||
|
||||
export const BUCKET = 'tatort';
|
||||
export const TOKENFILENAME = '__perm__';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { BUCKET, client } from '$lib/minio';
|
||||
import { BUCKET, client, TOKENFILENAME } from '$lib/minio';
|
||||
import { checkIfExactDirectoryExists } from './s3ClientService';
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ export const redirectIfVorgangExists = async (request: Request) => {
|
||||
});
|
||||
}
|
||||
|
||||
redirect(303, `/list/${caseId}`);
|
||||
redirect(303, `/list/${caseId}?token=${caseToken}`);
|
||||
};
|
||||
|
||||
export const getVorgangByCaseId = ({ params }) => {
|
||||
@@ -76,14 +76,13 @@ export const getVorgangByCaseId = ({ params }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const hasValidToken = async (caseId: string, caseToken: string) => {
|
||||
const tokenFileName = '__perm__';
|
||||
const objPath = `${caseId}/${tokenFileName}`;
|
||||
export const hasValidToken = async (caseId: string, caseToken: string) => {
|
||||
const objPath = `${caseId}/${TOKENFILENAME}`;
|
||||
|
||||
try {
|
||||
if (!caseToken) return false;
|
||||
|
||||
const res = await client.getObject('tatort', objPath);
|
||||
const res = await client.getObject(BUCKET, objPath);
|
||||
|
||||
const savedToken = await new Response(res).text();
|
||||
|
||||
|
||||
18
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
18
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { hasValidToken } from '$lib/server/vorgangService';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from '../../view/$types';
|
||||
|
||||
export const load: PageServerLoad = ({params, url}) => {
|
||||
const caseID = params.vorgang;
|
||||
const token = url.searchParams.get('token');
|
||||
|
||||
let isTokenValid
|
||||
|
||||
if (typeof token === 'string' && caseID) {
|
||||
isTokenValid = hasValidToken(caseID, token);
|
||||
}
|
||||
|
||||
if(!isTokenValid) {
|
||||
redirect(303, '/anmeldung');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user