DirectEditingViewController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files\Controller;
  7. use Exception;
  8. use OCP\AppFramework\Controller;
  9. use OCP\AppFramework\Http\Attribute\OpenAPI;
  10. use OCP\AppFramework\Http\NotFoundResponse;
  11. use OCP\AppFramework\Http\Response;
  12. use OCP\DirectEditing\IManager;
  13. use OCP\DirectEditing\RegisterDirectEditorEvent;
  14. use OCP\EventDispatcher\IEventDispatcher;
  15. use OCP\IRequest;
  16. use Psr\Log\LoggerInterface;
  17. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  18. class DirectEditingViewController extends Controller {
  19. public function __construct(
  20. $appName,
  21. IRequest $request,
  22. private IEventDispatcher $eventDispatcher,
  23. private IManager $directEditingManager,
  24. private LoggerInterface $logger,
  25. ) {
  26. parent::__construct($appName, $request);
  27. }
  28. /**
  29. * @PublicPage
  30. * @NoCSRFRequired
  31. * @UseSession
  32. *
  33. * @param string $token
  34. * @return Response
  35. */
  36. public function edit(string $token): Response {
  37. $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
  38. try {
  39. return $this->directEditingManager->edit($token);
  40. } catch (Exception $e) {
  41. $this->logger->error($e->getMessage(), ['exception' => $e]);
  42. return new NotFoundResponse();
  43. }
  44. }
  45. }