aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/ReferenceController.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Controller/ReferenceController.php')
-rw-r--r--core/Controller/ReferenceController.php59
1 files changed, 28 insertions, 31 deletions
diff --git a/core/Controller/ReferenceController.php b/core/Controller/ReferenceController.php
index a892de03e79..6ed15e2d2f1 100644
--- a/core/Controller/ReferenceController.php
+++ b/core/Controller/ReferenceController.php
@@ -2,66 +2,63 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Controller;
-use OCP\AppFramework\Http\Response;
-use OCP\Collaboration\Reference\IReferenceManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\FrontpageRoute;
+use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
+use OCP\AppFramework\Http\Attribute\OpenAPI;
+use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\DataResponse;
+use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IRequest;
class ReferenceController extends Controller {
- private IReferenceManager $referenceManager;
- private IAppDataFactory $appDataFactory;
-
- public function __construct(string $appName, IRequest $request, IReferenceManager $referenceManager, IAppDataFactory $appDataFactory) {
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ private IReferenceManager $referenceManager,
+ private IAppDataFactory $appDataFactory,
+ ) {
parent::__construct($appName, $request);
- $this->referenceManager = $referenceManager;
- $this->appDataFactory = $appDataFactory;
}
/**
- * @PublicPage
- * @NoCSRFRequired
+ * Get a preview for a reference
+ *
* @param string $referenceId the reference cache key
- * @return Response
+ * @return DataDownloadResponse<Http::STATUS_OK, string, array{}>|DataResponse<Http::STATUS_NOT_FOUND, '', array{}>
+ *
+ * 200: Preview returned
+ * 404: Reference not found
*/
- public function preview(string $referenceId): Response {
+ #[PublicPage]
+ #[NoCSRFRequired]
+ #[FrontpageRoute(verb: 'GET', url: '/core/references/preview/{referenceId}')]
+ #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
+ public function preview(string $referenceId): DataDownloadResponse|DataResponse {
$reference = $this->referenceManager->getReferenceByCacheKey($referenceId);
try {
$appData = $this->appDataFactory->get('core');
$folder = $appData->getFolder('opengraph');
$file = $folder->getFile($referenceId);
+ $contentType = $reference === null || $reference->getImageContentType() === null
+ ? $file->getMimeType()
+ : $reference->getImageContentType();
$response = new DataDownloadResponse(
$file->getContent(),
$referenceId,
- $reference === null ? $file->getMimeType() : $reference->getImageContentType()
+ $contentType
);
} catch (NotFoundException|NotPermittedException $e) {
$response = new DataResponse('', Http::STATUS_NOT_FOUND);