You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Capabilities.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 OC\OCM\Model\OCMProvider;
  28. use OC\OCM\Model\OCMResource;
  29. use OCP\Capabilities\ICapability;
  30. use OCP\IURLGenerator;
  31. use OCP\OCM\Exceptions\OCMArgumentException;
  32. class Capabilities implements ICapability {
  33. public const API_VERSION = '1.0-proposal1';
  34. public function __construct(
  35. private IURLGenerator $urlGenerator,
  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. $provider = new OCMProvider();
  58. $provider->setEnabled(true);
  59. $provider->setApiVersion(self::API_VERSION);
  60. $pos = strrpos($url, '/');
  61. if (false === $pos) {
  62. throw new OCMArgumentException('generated route should contains a slash character');
  63. }
  64. $provider->setEndPoint(substr($url, 0, $pos));
  65. $resource = new OCMResource();
  66. $resource->setName('file')
  67. ->setShareTypes(['user', 'group'])
  68. ->setProtocols(['webdav' => '/public.php/webdav/']);
  69. $provider->setResourceTypes([$resource]);
  70. return ['ocm' => $provider->jsonSerialize()];
  71. }
  72. }