Api.php 2.5 KB

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