1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Morris Jobke <[email protected]> |
5
|
|
|
* @author Robin Appelman <[email protected]> |
6
|
|
|
* @author Vincent Petry <[email protected]> |
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
|
|
|
|
25
|
|
|
OCP\JSON::checkAppEnabled('files_sharing'); |
26
|
|
|
|
27
|
|
|
if (!isset($_GET['t'])) { |
28
|
|
|
\OC_Response::setStatus(400); //400 Bad Request |
29
|
|
|
exit; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) { |
33
|
|
|
\OC_Response::setStatus(404); // 404 not found |
34
|
|
|
exit; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$token = $_GET['t']; |
38
|
|
|
|
39
|
|
|
$password = null; |
40
|
|
|
if (isset($_POST['password'])) { |
41
|
|
|
$password = $_POST['password']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$relativePath = null; |
45
|
|
|
if (isset($_GET['dir'])) { |
46
|
|
|
$relativePath = $_GET['dir']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); |
50
|
|
|
|
51
|
|
|
$linkItem = $data['linkItem']; |
52
|
|
|
// Load the files |
53
|
|
|
$path = $data['realPath']; |
54
|
|
|
|
55
|
|
|
$isWritable = $linkItem['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE); |
56
|
|
|
if (!$isWritable) { |
57
|
|
|
\OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) { |
58
|
|
|
return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage)); |
59
|
|
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$rootInfo = \OC\Files\Filesystem::getFileInfo($path); |
63
|
|
|
$rootView = new \OC\Files\View(''); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param \OCP\Files\FileInfo $dir |
67
|
|
|
* @param \OC\Files\View $view |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
function getChildInfo($dir, $view) { |
71
|
|
|
$children = $view->getDirectoryContent($dir->getPath()); |
72
|
|
|
$result = array(); |
73
|
|
|
foreach ($children as $child) { |
74
|
|
|
$formated = \OCA\Files\Helper::formatFileInfo($child); |
75
|
|
|
if ($child->getType() === 'dir') { |
76
|
|
|
$formated['children'] = getChildInfo($child, $view); |
77
|
|
|
} |
78
|
|
|
$formated['mtime'] = $formated['mtime'] / 1000; |
79
|
|
|
$result[] = $formated; |
80
|
|
|
} |
81
|
|
|
return $result; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$result = \OCA\Files\Helper::formatFileInfo($rootInfo); |
85
|
|
|
$result['mtime'] = $result['mtime'] / 1000; |
86
|
|
|
if ($rootInfo->getType() === 'dir') { |
87
|
|
|
$result['children'] = getChildInfo($rootInfo, $rootView); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
OCP\JSON::success(array('data' => $result)); |
91
|
|
|
|