Skip to content

Commit

Permalink
fix reference preview endpoint when no server-side cache configured
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier authored and juliusknorr committed Oct 18, 2022
1 parent 20ea9a2 commit 5345896
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/Controller/ReferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,21 @@ public function __construct(string $appName, IRequest $request, IReferenceManage
/**
* @PublicPage
* @NoCSRFRequired
* @param string $referenceId the reference cache key
* @return Response
*/
public function preview(string $referenceId): Response {
$reference = $this->referenceManager->getReferenceByCacheKey($referenceId);
if ($reference === null) {
return new DataResponse('', Http::STATUS_NOT_FOUND);
}

try {
$appData = $this->appDataFactory->get('core');
$folder = $appData->getFolder('opengraph');
$file = $folder->getFile($referenceId);
$response = new DataDownloadResponse($file->getContent(), $referenceId, $reference->getImageContentType());
$response = new DataDownloadResponse(
$file->getContent(),
$referenceId,
$reference === null ? $file->getMimeType() : $reference->getImageContentType()
);
} catch (NotFoundException|NotPermittedException $e) {
$response = new DataResponse('', Http::STATUS_NOT_FOUND);
}
Expand Down

0 comments on commit 5345896

Please sign in to comment.