Capabilities.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  5. *
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Kate Döen <kate.doeen@nextcloud.com>
  8. * @author Maxence Lange <maxence@artificial-owl.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\CloudFederationAPI;
  27. use OCP\Capabilities\ICapability;
  28. use OCP\IURLGenerator;
  29. use OCP\OCM\Exceptions\OCMArgumentException;
  30. use OCP\OCM\IOCMProvider;
  31. class Capabilities implements ICapability {
  32. public const API_VERSION = '1.0-proposal1';
  33. public function __construct(
  34. private IURLGenerator $urlGenerator,
  35. private IOCMProvider $provider,
  36. ) {
  37. }
  38. /**
  39. * Function an app uses to return the capabilities
  40. *
  41. * @return array{
  42. * ocm: array{
  43. * enabled: bool,
  44. * apiVersion: string,
  45. * endPoint: string,
  46. * resourceTypes: array{
  47. * name: string,
  48. * shareTypes: string[],
  49. * protocols: array<string, string>
  50. * }[],
  51. * },
  52. * }
  53. * @throws OCMArgumentException
  54. */
  55. public function getCapabilities() {
  56. $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
  57. $this->provider->setEnabled(true);
  58. $this->provider->setApiVersion(self::API_VERSION);
  59. $pos = strrpos($url, '/');
  60. if (false === $pos) {
  61. throw new OCMArgumentException('generated route should contains a slash character');
  62. }
  63. $this->provider->setEndPoint(substr($url, 0, $pos));
  64. $resource = $this->provider->createNewResourceType();
  65. $resource->setName('file')
  66. ->setShareTypes(['user', 'group'])
  67. ->setProtocols(['webdav' => '/public.php/webdav/']);
  68. $this->provider->addResourceType($resource);
  69. return ['ocm' => $this->provider->jsonSerialize()];
  70. }
  71. }