mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-01 19:59:13 +00:00
593645acfe
Allows files to be placed within a "public" folder within a theme directory which the contents of will served by BookStack for access. - Only "web safe" content-types are provided. - A static 1 day cache time it set on served files. For #3904
31 lines
740 B
PHP
31 lines
740 B
PHP
<?php
|
|
|
|
namespace BookStack\Theming;
|
|
|
|
use BookStack\Facades\Theme;
|
|
use BookStack\Http\Controller;
|
|
use BookStack\Util\FilePathNormalizer;
|
|
|
|
class ThemeController extends Controller
|
|
{
|
|
/**
|
|
* Serve a public file from the configured theme.
|
|
*/
|
|
public function publicFile(string $theme, string $path)
|
|
{
|
|
$cleanPath = FilePathNormalizer::normalize($path);
|
|
if ($theme !== Theme::getTheme() || !$cleanPath) {
|
|
abort(404);
|
|
}
|
|
|
|
$filePath = theme_path("public/{$cleanPath}");
|
|
if (!file_exists($filePath)) {
|
|
abort(404);
|
|
}
|
|
|
|
$response = $this->download()->streamedFileInline($filePath);
|
|
$response->setMaxAge(86400);
|
|
|
|
return $response;
|
|
}
|
|
}
|