diff --git a/EMS/core-bundle/src/Controller/ContentManagement/FileController.php b/EMS/core-bundle/src/Controller/ContentManagement/FileController.php index 37a293bf6..edf4d2de9 100644 --- a/EMS/core-bundle/src/Controller/ContentManagement/FileController.php +++ b/EMS/core-bundle/src/Controller/ContentManagement/FileController.php @@ -58,13 +58,7 @@ public function extractFileContentForced(Request $request, string $sha1): Respon public function extractFileContent(Request $request, string $sha1, bool $forced = false): Response { - if ($request->hasSession()) { - $session = $request->getSession(); - - if ($session->isStarted()) { - $session->save(); - } - } + $this->closeSession($request); try { $data = $this->assetExtractorService->extractData($sha1, null, $forced); @@ -178,15 +172,25 @@ public function indexImagesAction(): Response ]); } - public function icon(int $size): Response + public function icon(Request $request, int $size): Response { + $this->closeSession($request); $color = new Color($this->themeColor); $image = $this->fileService->generateImage('@EMSCoreBundle/Resources/public/images/big-logo.png', [ '_width' => $size, '_height' => $size, '_quality' => 0, '_background' => $this->themeColor, - '_color' => $color->contrastRatio(new Color('black')) > $color->contrastRatio(new Color('white')) ? 'black' : 'white', + '_color' => $color->contrastRatio(new Color('black')) > $color->contrastRatio(new Color('white')) ? 'black' : 'white', + ]); + + $response = new BinaryFileResponse($image); + $response->setCache([ + 'etag' => \hash_file('sha1', $image), + 'max_age' => 3600, + 's_maxage' => 36000, + 'public' => true, + 'private' => false, ]); return new BinaryFileResponse($image); @@ -251,4 +255,16 @@ private function getUsername(): string return $userObject->getUsername(); } + + private function closeSession(Request $request): void + { + if (!$request->hasSession()) { + return; + } + + $session = $request->getSession(); + if ($session->isStarted()) { + $session->save(); + } + } }