1
0

DirectHome.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Direct;
  8. use OCA\DAV\Db\DirectMapper;
  9. use OCP\AppFramework\Db\DoesNotExistException;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\EventDispatcher\IEventDispatcher;
  12. use OCP\Files\IRootFolder;
  13. use OCP\IRequest;
  14. use OCP\Security\Bruteforce\IThrottler;
  15. use Sabre\DAV\Exception\Forbidden;
  16. use Sabre\DAV\Exception\MethodNotAllowed;
  17. use Sabre\DAV\Exception\NotFound;
  18. use Sabre\DAV\ICollection;
  19. class DirectHome implements ICollection {
  20. public function __construct(
  21. private IRootFolder $rootFolder,
  22. private DirectMapper $mapper,
  23. private ITimeFactory $timeFactory,
  24. private IThrottler $throttler,
  25. private IRequest $request,
  26. private IEventDispatcher $eventDispatcher,
  27. ) {
  28. }
  29. public function createFile($name, $data = null) {
  30. throw new Forbidden();
  31. }
  32. public function createDirectory($name) {
  33. throw new Forbidden();
  34. }
  35. public function getChild($name): DirectFile {
  36. try {
  37. $direct = $this->mapper->getByToken($name);
  38. // Expired
  39. if ($direct->getExpiration() < $this->timeFactory->getTime()) {
  40. throw new NotFound();
  41. }
  42. return new DirectFile($direct, $this->rootFolder, $this->eventDispatcher);
  43. } catch (DoesNotExistException $e) {
  44. // Since the token space is so huge only throttle on non-existing token
  45. $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress());
  46. $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink');
  47. throw new NotFound();
  48. }
  49. }
  50. public function getChildren() {
  51. throw new MethodNotAllowed('Listing members of this collection is disabled');
  52. }
  53. public function childExists($name): bool {
  54. return false;
  55. }
  56. public function delete() {
  57. throw new Forbidden();
  58. }
  59. public function getName(): string {
  60. return 'direct';
  61. }
  62. public function setName($name) {
  63. throw new Forbidden();
  64. }
  65. public function getLastModified(): int {
  66. return 0;
  67. }
  68. }