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.

Api.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @author Jesús Macias <jmacias@solidgear.es>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin McCorkell <robin@mccorkell.me.uk>
  7. * @author Vincent Petry <pvince81@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2016, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_External\Lib;
  26. class Api {
  27. /**
  28. * Formats the given mount config to a mount entry.
  29. *
  30. * @param string $mountPoint mount point name, relative to the data dir
  31. * @param array $mountConfig mount config to format
  32. *
  33. * @return array entry
  34. */
  35. private static function formatMount($mountPoint, $mountConfig) {
  36. // strip "/$user/files" from mount point
  37. $mountPoint = explode('/', trim($mountPoint, '/'), 3);
  38. $mountPoint = $mountPoint[2];
  39. // split path from mount point
  40. $path = dirname($mountPoint);
  41. if ($path === '.') {
  42. $path = '';
  43. }
  44. $isSystemMount = !$mountConfig['personal'];
  45. $permissions = \OCP\Constants::PERMISSION_READ;
  46. // personal mounts can be deleted
  47. if (!$isSystemMount) {
  48. $permissions |= \OCP\Constants::PERMISSION_DELETE;
  49. }
  50. $entry = array(
  51. 'name' => basename($mountPoint),
  52. 'path' => $path,
  53. 'type' => 'dir',
  54. 'backend' => $mountConfig['backend'],
  55. 'scope' => ( $isSystemMount ? 'system' : 'personal' ),
  56. 'permissions' => $permissions,
  57. 'id' => $mountConfig['id'],
  58. 'class' => $mountConfig['class']
  59. );
  60. return $entry;
  61. }
  62. /**
  63. * Returns the mount points visible for this user.
  64. *
  65. * @param array $params
  66. * @return \OC_OCS_Result share information
  67. */
  68. public static function getUserMounts($params) {
  69. $entries = array();
  70. $user = \OC::$server->getUserSession()->getUser()->getUID();
  71. $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
  72. foreach($mounts as $mountPoint => $mount) {
  73. $entries[] = self::formatMount($mountPoint, $mount);
  74. }
  75. return new \OC_OCS_Result($entries);
  76. }
  77. }