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.

shareinfo.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. OCP\JSON::checkAppEnabled('files_sharing');
  25. if (!isset($_GET['t'])) {
  26. \OC_Response::setStatus(400); //400 Bad Request
  27. exit;
  28. }
  29. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
  30. \OC_Response::setStatus(404); // 404 not found
  31. exit;
  32. }
  33. $token = $_GET['t'];
  34. $password = null;
  35. if (isset($_POST['password'])) {
  36. $password = $_POST['password'];
  37. }
  38. $relativePath = null;
  39. if (isset($_GET['dir'])) {
  40. $relativePath = $_GET['dir'];
  41. }
  42. $data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
  43. $linkItem = $data['linkItem'];
  44. // Load the files
  45. $path = $data['realPath'];
  46. $isWritable = $linkItem['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  47. if (!$isWritable) {
  48. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  49. return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
  50. });
  51. }
  52. $rootInfo = \OC\Files\Filesystem::getFileInfo($path);
  53. $rootView = new \OC\Files\View('');
  54. /**
  55. * @param \OCP\Files\FileInfo $dir
  56. * @param \OC\Files\View $view
  57. * @return array
  58. */
  59. function getChildInfo($dir, $view) {
  60. $children = $view->getDirectoryContent($dir->getPath());
  61. $result = array();
  62. foreach ($children as $child) {
  63. $formated = \OCA\Files\Helper::formatFileInfo($child);
  64. if ($child->getType() === 'dir') {
  65. $formated['children'] = getChildInfo($child, $view);
  66. }
  67. $formated['mtime'] = $formated['mtime'] / 1000;
  68. $result[] = $formated;
  69. }
  70. return $result;
  71. }
  72. $result = \OCA\Files\Helper::formatFileInfo($rootInfo);
  73. $result['mtime'] = $result['mtime'] / 1000;
  74. if ($rootInfo->getType() === 'dir') {
  75. $result['children'] = getChildInfo($rootInfo, $rootView);
  76. }
  77. OCP\JSON::success(array('data' => $result));