Skip to content

Commit

Permalink
Merge pull request #34594 from nextcloud/backport/34450/stable25
Browse files Browse the repository at this point in the history
[stable25] Fix reference preview when no server-side cache configured
  • Loading branch information
nickvergessen authored Oct 19, 2022
2 parents 7a38af2 + 5345896 commit b568587
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 b568587

Please sign in to comment.