cms/app/Http/Controllers/ThemeAssetController.php

39 lines
1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Symfony\Component\HttpFoundation\Response;
class ThemeAssetController extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request, string $theme, string $path)
{
$themePath = base_path("themes/{$theme}/{$path}");
if (! File::exists($themePath)) {
abort(404);
}
$extension = pathinfo($path, PATHINFO_EXTENSION);
$mimeType = match ($extension) {
'css' => 'text/css',
'js' => 'application/javascript',
'png' => 'image/png',
'jpg', 'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'webp' => 'image/webp',
default => File::mimeType($themePath) ?: 'text/plain',
};
return response(File::get($themePath), 200, [
'Content-Type' => $mimeType,
]);
}
}