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.3KB

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