27 lines
979 B
TypeScript
27 lines
979 B
TypeScript
import { error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { requireUser } from '#lib/server/auth.js';
|
|
import { getPiece } from '#lib/server/content.js';
|
|
import { fetchPresentationImage } from '#lib/server/presentation.js';
|
|
|
|
export const GET: RequestHandler = async ({ locals, params }) => {
|
|
requireUser(locals.user);
|
|
const piece = getPiece(params.id);
|
|
if (!piece?.presentationImageUrl) error(404, 'Vorschaubild nicht verfügbar');
|
|
try {
|
|
const image = await fetchPresentationImage(piece.presentationImageUrl);
|
|
return new Response(new Uint8Array(image.data), {
|
|
headers: {
|
|
'Content-Type': image.mimeType,
|
|
'Content-Length': String(image.data.byteLength),
|
|
'Cache-Control': 'private, max-age=300',
|
|
'X-Content-Type-Options': 'nosniff',
|
|
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
'Content-Security-Policy': "default-src 'none'; sandbox"
|
|
}
|
|
});
|
|
} catch {
|
|
error(404, 'Vorschaubild nicht verfügbar');
|
|
}
|
|
};
|