No more missing files in page load.
This commit is contained in:
parent
1378e95f81
commit
5d8b35b05d
1 changed files with 18 additions and 2 deletions
|
|
@ -116,16 +116,32 @@ abstract class AbstractController
|
|||
protected function returnFile(Filesystem $filesystem, string $filename): Response
|
||||
{
|
||||
$response = new Response();
|
||||
|
||||
if (!$filesystem->has($filename)) {
|
||||
!\Kint::dump($filesystem->listContents(), $filesystem->has($filename));
|
||||
exit;
|
||||
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
//\Kint::dump($filesystem->getMimetype($assetName));exit;
|
||||
// Crappy detection of content-type
|
||||
$path = $filesystem->getMetadata($filename)['path'];
|
||||
if (str_ends_with($path, '.css')) {
|
||||
$response = $response->withHeader('Content-Type', 'text/css');
|
||||
} elseif (str_ends_with($path, '.js')) {
|
||||
$response = $response->withHeader('Content-Type', 'text/javascript');
|
||||
} elseif (str_ends_with($path, '.png')) {
|
||||
$response = $response->withHeader('Content-Type', 'image/png');
|
||||
} elseif (str_ends_with($path, '.jpg')) {
|
||||
$response = $response->withHeader('Content-Type', 'image/jpeg');
|
||||
} elseif (str_ends_with($path, '.svg')) {
|
||||
$response = $response->withHeader('Content-Type', 'image/svg+xml');
|
||||
}
|
||||
|
||||
$response->getBody()
|
||||
->write($filesystem->read($filename))
|
||||
;
|
||||
|
||||
return $response->withHeader('Content-type', $filesystem->getMimetype($filename));
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue