diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-12 20:17:44 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-08-31 16:20:06 +0200 |
commit | 0ce0d37ac18456092702a6ed4410ec7e61bdfc07 (patch) | |
tree | d0f327f6d9473ef628b155980bcaa0f374827078 /core/Controller/ReferenceController.php | |
parent | f58218deeab3a56d5a6a1dfb2047901155daa74d (diff) | |
download | nextcloud-server-0ce0d37ac18456092702a6ed4410ec7e61bdfc07.tar.gz nextcloud-server-0ce0d37ac18456092702a6ed4410ec7e61bdfc07.zip |
Implement image caching
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'core/Controller/ReferenceController.php')
-rw-r--r-- | core/Controller/ReferenceController.php | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/core/Controller/ReferenceController.php b/core/Controller/ReferenceController.php index 1d61bb0f772..dda213db54d 100644 --- a/core/Controller/ReferenceController.php +++ b/core/Controller/ReferenceController.php @@ -24,59 +24,42 @@ declare(strict_types=1); namespace OC\Core\Controller; -use OCP\AppFramework\Http\DataResponse; use OC\Collaboration\Reference\ReferenceManager; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataDownloadResponse; +use OCP\AppFramework\Http\DataResponse; +use OCP\Files\AppData\IAppDataFactory; +use OCP\Files\NotFoundException; use OCP\IRequest; -class ReferenceController extends \OCP\AppFramework\OCSController { +class ReferenceController extends \OCP\AppFramework\Controller { private ReferenceManager $referenceManager; - public function __construct($appName, IRequest $request, ReferenceManager $referenceManager) { + public function __construct($appName, IRequest $request, ReferenceManager $referenceManager, IAppDataFactory $appDataFactory) { parent::__construct($appName, $request); $this->referenceManager = $referenceManager; + $this->appDataFactory = $appDataFactory; } /** - * @NoAdminRequired - * - * @param string $text - * @param bool $resolve - * @return DataResponse + * @PublicPage + * @NoCSRFRequired + * @param $referenceId + * @throws \OCP\Files\NotFoundException */ - public function extract(string $text, bool $resolve = false, int $limit = 1): DataResponse { - $references = $this->referenceManager->extractReferences($text); - - $result = []; - $index = 0; - foreach ($references as $reference) { - if ($index++ < $limit) { - $result[$reference] = $resolve ? $this->referenceManager->resolveReference($reference) : null; - } + public function preview($referenceId) { + $reference = $this->referenceManager->getReferenceByCacheKey($referenceId); + if ($reference === null) { + return new DataResponse('', Http::STATUS_NOT_FOUND); } - return new DataResponse([ - 'references' => $result - ]); - } - - - /** - * @NoAdminRequired - * - * @param array $references - * @return DataResponse - */ - public function resolve(array $references, int $limit = 1): DataResponse { - $result = []; - $index = 0; - foreach ($references as $reference) { - if ($index++ < $limit) { - $result[$reference] = $this->referenceManager->resolveReference($reference); - } + try { + $appData = $this->appDataFactory->get('core'); + $folder = $appData->getFolder('opengraph'); + $file = $folder->getFile($referenceId); + } catch (NotFoundException $e) { + return new DataResponse('', Http::STATUS_NOT_FOUND); } - - return new DataResponse([ - 'references' => array_filter($result) - ]); + return new DataDownloadResponse($file->getContent(), $referenceId, $reference->getImageContentType()); } } |