Browse Source
Merge pull request #34450 from nextcloud/fix/noid/opengraph-preview-without-cache
Fix reference preview when no server-side cache configured
pull/34135/head
Joas Schilling
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
7 additions and
4 deletions
-
core/Controller/ReferenceController.php
|
|
|
@ -48,18 +48,21 @@ class ReferenceController extends Controller { |
|
|
|
/** |
|
|
|
* @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); |
|
|
|
} |
|
|
|
|