|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2014 Robin Appelman <[email protected]> |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. |
|
6
|
|
|
* See the COPYING-README file. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
OCP\JSON::checkAppEnabled('files_sharing'); |
|
10
|
|
|
|
|
11
|
|
|
if (!isset($_GET['t'])) { |
|
12
|
|
|
\OC_Response::setStatus(400); //400 Bad Request |
|
13
|
|
|
exit; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
$token = $_GET['t']; |
|
17
|
|
|
|
|
18
|
|
|
$password = null; |
|
19
|
|
|
if (isset($_POST['password'])) { |
|
20
|
|
|
$password = $_POST['password']; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$relativePath = null; |
|
24
|
|
|
if (isset($_GET['dir'])) { |
|
25
|
|
|
$relativePath = $_GET['dir']; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); |
|
29
|
|
|
|
|
30
|
|
|
$linkItem = $data['linkItem']; |
|
31
|
|
|
// Load the files |
|
32
|
|
|
$path = $data['realPath']; |
|
33
|
|
|
|
|
34
|
|
|
$isWritable = $linkItem['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE); |
|
35
|
|
|
if (!$isWritable) { |
|
36
|
|
|
\OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) { |
|
37
|
|
|
return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage)); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$rootInfo = \OC\Files\Filesystem::getFileInfo($path); |
|
42
|
|
|
$rootView = new \OC\Files\View(''); |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \OCP\Files\FileInfo $dir |
|
46
|
|
|
* @param \OC\Files\View $view |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
function getChildInfo($dir, $view) { |
|
50
|
|
|
$children = $view->getDirectoryContent($dir->getPath()); |
|
51
|
|
|
$result = array(); |
|
52
|
|
|
foreach ($children as $child) { |
|
53
|
|
|
$formated = \OCA\Files\Helper::formatFileInfo($child); |
|
54
|
|
|
if ($child->getType() === 'dir') { |
|
55
|
|
|
$formated['children'] = getChildInfo($child, $view); |
|
56
|
|
|
} |
|
57
|
|
|
$formated['mtime'] = $formated['mtime'] / 1000; |
|
58
|
|
|
$result[] = $formated; |
|
59
|
|
|
} |
|
60
|
|
|
return $result; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$result = \OCA\Files\Helper::formatFileInfo($rootInfo); |
|
64
|
|
|
$result['mtime'] = $result['mtime'] / 1000; |
|
65
|
|
|
if ($rootInfo->getType() === 'dir') { |
|
66
|
|
|
$result['children'] = getChildInfo($rootInfo, $rootView); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
OCP\JSON::success(array('data' => $result)); |
|
70
|
|
|
|