1
0

Capabilities.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\CloudFederationAPI;
  8. use OCP\Capabilities\ICapability;
  9. use OCP\IURLGenerator;
  10. use OCP\OCM\Exceptions\OCMArgumentException;
  11. use OCP\OCM\IOCMProvider;
  12. class Capabilities implements ICapability {
  13. public const API_VERSION = '1.0-proposal1';
  14. public function __construct(
  15. private IURLGenerator $urlGenerator,
  16. private IOCMProvider $provider,
  17. ) {
  18. }
  19. /**
  20. * Function an app uses to return the capabilities
  21. *
  22. * @return array{
  23. * ocm: array{
  24. * enabled: bool,
  25. * apiVersion: string,
  26. * endPoint: string,
  27. * resourceTypes: list<array{
  28. * name: string,
  29. * shareTypes: list<string>,
  30. * protocols: array<string, string>
  31. * }>,
  32. * },
  33. * }
  34. * @throws OCMArgumentException
  35. */
  36. public function getCapabilities() {
  37. $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
  38. $this->provider->setEnabled(true);
  39. $this->provider->setApiVersion(self::API_VERSION);
  40. $pos = strrpos($url, '/');
  41. if ($pos === false) {
  42. throw new OCMArgumentException('generated route should contains a slash character');
  43. }
  44. $this->provider->setEndPoint(substr($url, 0, $pos));
  45. $resource = $this->provider->createNewResourceType();
  46. $resource->setName('file')
  47. ->setShareTypes(['user', 'group'])
  48. ->setProtocols(['webdav' => '/public.php/webdav/']);
  49. $this->provider->addResourceType($resource);
  50. return ['ocm' => $this->provider->jsonSerialize()];
  51. }
  52. }