DirectEditingViewController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\NoCSRFRequired;
  10. use OCP\AppFramework\Http\Attribute\OpenAPI;
  11. use OCP\AppFramework\Http\Attribute\PublicPage;
  12. use OCP\AppFramework\Http\Attribute\UseSession;
  13. use OCP\AppFramework\Http\NotFoundResponse;
  14. use OCP\AppFramework\Http\Response;
  15. use OCP\DirectEditing\IManager;
  16. use OCP\DirectEditing\RegisterDirectEditorEvent;
  17. use OCP\EventDispatcher\IEventDispatcher;
  18. use OCP\IRequest;
  19. use Psr\Log\LoggerInterface;
  20. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  21. class DirectEditingViewController extends Controller {
  22. public function __construct(
  23. $appName,
  24. IRequest $request,
  25. private IEventDispatcher $eventDispatcher,
  26. private IManager $directEditingManager,
  27. private LoggerInterface $logger,
  28. ) {
  29. parent::__construct($appName, $request);
  30. }
  31. /**
  32. * @param string $token
  33. * @return Response
  34. */
  35. #[PublicPage]
  36. #[NoCSRFRequired]
  37. #[UseSession]
  38. public function edit(string $token): Response {
  39. $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
  40. try {
  41. return $this->directEditingManager->edit($token);
  42. } catch (Exception $e) {
  43. $this->logger->error($e->getMessage(), ['exception' => $e]);
  44. return new NotFoundResponse();
  45. }
  46. }
  47. }