diff options
Diffstat (limited to 'apps/files_trashbin/lib/Controller/PreviewController.php')
-rw-r--r-- | apps/files_trashbin/lib/Controller/PreviewController.php | 92 |
1 files changed, 31 insertions, 61 deletions
diff --git a/apps/files_trashbin/lib/Controller/PreviewController.php b/apps/files_trashbin/lib/Controller/PreviewController.php index 22ca56d8f36..a4e911d88ef 100644 --- a/apps/files_trashbin/lib/Controller/PreviewController.php +++ b/apps/files_trashbin/lib/Controller/PreviewController.php @@ -3,36 +3,19 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Jakub Onderka <ahoj@jakubonderka.cz> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author simonspa <1677436+simonspa@users.noreply.github.com> - * - * @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: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Files_Trashbin\Controller; use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\NoCSRFRequired; +use OCP\AppFramework\Http\Attribute\OpenAPI; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; @@ -42,55 +25,42 @@ use OCP\IPreview; use OCP\IRequest; use OCP\IUserSession; +#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] class PreviewController extends Controller { - /** @var IRootFolder */ - private $rootFolder; - - /** @var ITrashManager */ - private $trashManager; - - /** @var IUserSession */ - private $userSession; - - /** @var IMimeTypeDetector */ - private $mimeTypeDetector; - - /** @var IPreview */ - private $previewManager; - - /** @var ITimeFactory */ - private $time; - public function __construct( string $appName, IRequest $request, - IRootFolder $rootFolder, - ITrashManager $trashManager, - IUserSession $userSession, - IMimeTypeDetector $mimeTypeDetector, - IPreview $previewManager, - ITimeFactory $time + private IRootFolder $rootFolder, + private ITrashManager $trashManager, + private IUserSession $userSession, + private IMimeTypeDetector $mimeTypeDetector, + private IPreview $previewManager, + private ITimeFactory $time, ) { parent::__construct($appName, $request); - - $this->trashManager = $trashManager; - $this->rootFolder = $rootFolder; - $this->userSession = $userSession; - $this->mimeTypeDetector = $mimeTypeDetector; - $this->previewManager = $previewManager; - $this->time = $time; } /** - * @NoAdminRequired - * @NoCSRFRequired + * Get the preview for a file + * + * @param int $fileId ID of the file + * @param int $x Width of the preview + * @param int $y Height of the preview + * @param bool $a Whether to not crop the preview + * + * @return Http\FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, list<empty>, array{}> * - * @return DataResponse|Http\FileDisplayResponse + * 200: Preview returned + * 400: Getting preview is not possible + * 404: Preview not found */ + #[NoAdminRequired] + #[NoCSRFRequired] public function getPreview( int $fileId = -1, - int $x = 128, - int $y = 128 + int $x = 32, + int $y = 32, + bool $a = false, ) { if ($fileId === -1 || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); @@ -118,8 +88,8 @@ class PreviewController extends Controller { $mimeType = $this->mimeTypeDetector->detectPath($file->getName()); } - $f = $this->previewManager->getPreview($file, $x, $y, true, IPreview::MODE_FILL, $mimeType); - $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); + $f = $this->previewManager->getPreview($file, $x, $y, !$a, IPreview::MODE_FILL, $mimeType); + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); // Cache previews for 24H $response->cacheFor(3600 * 24); |