import { client } from '$lib/minio';

/** @type {import('./$types').RequestHandler} */
export async function GET() {
	var stream = client.listObjectsV2('tatort', '', true);
	const result = new ReadableStream({
		start(controller) {
			stream.on('data', (data) => {
				//console.log(data);
				controller.enqueue(`${JSON.stringify(data)}\n`);
			});
			stream.on('end', () => {
				controller.close();
			});
		},
		cancel() {
			stream.destroy();
		}
	});

	return new Response(result, {
		headers: {
			'content-type': 'text/event-stream'
		}
	});
}
