Skip to content

Commit

Permalink
fix: close session and active http cache
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Oct 10, 2023
1 parent 9590bf4 commit 27d346f
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 27d346f

Please sign in to comment.