<?php
	declare(strict_types = 1);
	namespace Kimendisch\Sbgg_Jetzt;
	use Flake\Project;
	use Flake\Excuse;
	
	// GET REQUESTED FILENAME //
	// get from url parameter
	$filename = Project::param("filename");
	
	// resolve to storage path
	$__file_path = ([
		"logo-1024.png" => "./asset/logo-1024.png",
		"logo-2048.png" => "./asset/logo-2048.png",
		"logo-256.png" => "./asset/logo-256.png",
		"logo-512.png" => "./asset/logo-512.png",
		"logo-bg-1024.png" => "./asset/logo-bg-1024.png",
		"logo-bg-2048.png" => "./asset/logo-bg-2048.png",
		"logo-bg-256.png" => "./asset/logo-bg-256.png",
		"logo-bg-512.png" => "./asset/logo-bg-512.png",
		"logo.svg" => "./asset/logo.svg"
	])[$filename] ?? null;
	
	// validate lookup
	if($__file_path === null){
		Excuse::show("not_found");
	}
	
	
	// SERVE FILE //
	// make sure session isn't locked
	if(extension_loaded("session")) session_write_close();
	
	// general headers
	header("Access-Control-Allow-Origin: *");
	
	// content length
	header("Content-Length: " . filesize($__file_path));
	
	// mimetype
	$mime_content_type = mime_content_type($__file_path);
	header("Content-type: " . $mime_content_type);
	
	// file
	readfile($__file_path);
?>
