Capabilities.php 2.3 KB

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