]> BookStack Code Mirror - bookstack/blob - app/Theming/ThemeController.php
Lexical: Media form improvements
[bookstack] / app / Theming / ThemeController.php
1 <?php
2
3 namespace BookStack\Theming;
4
5 use BookStack\Facades\Theme;
6 use BookStack\Http\Controller;
7 use BookStack\Util\FilePathNormalizer;
8
9 class ThemeController extends Controller
10 {
11     /**
12      * Serve a public file from the configured theme.
13      */
14     public function publicFile(string $theme, string $path)
15     {
16         $cleanPath = FilePathNormalizer::normalize($path);
17         if ($theme !== Theme::getTheme() || !$cleanPath) {
18             abort(404);
19         }
20
21         $filePath = theme_path("public/{$cleanPath}");
22         if (!file_exists($filePath)) {
23             abort(404);
24         }
25
26         $response = $this->download()->streamedFileInline($filePath);
27         $response->setMaxAge(86400);
28
29         return $response;
30     }
31 }