2025-01-13 14:30:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BookStack\Theming;
|
|
|
|
|
|
|
|
|
|
use BookStack\Facades\Theme;
|
|
|
|
|
use BookStack\Http\Controller;
|
|
|
|
|
use BookStack\Util\FilePathNormalizer;
|
2026-02-01 11:53:46 +00:00
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
2025-01-13 14:30:53 +00:00
|
|
|
|
|
|
|
|
class ThemeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Serve a public file from the configured theme.
|
|
|
|
|
*/
|
2026-02-01 11:53:46 +00:00
|
|
|
public function publicFile(string $theme, string $path): StreamedResponse
|
2025-01-13 14:30:53 +00:00
|
|
|
{
|
|
|
|
|
$cleanPath = FilePathNormalizer::normalize($path);
|
|
|
|
|
if ($theme !== Theme::getTheme() || !$cleanPath) {
|
|
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 11:53:46 +00:00
|
|
|
$filePath = Theme::findFirstFile("public/{$cleanPath}");
|
|
|
|
|
if (!$filePath) {
|
2025-01-13 14:30:53 +00:00
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = $this->download()->streamedFileInline($filePath);
|
|
|
|
|
$response->setMaxAge(86400);
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
}
|