2011-03-03 22:08:54 +00:00
|
|
|
<?php
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-07-01 12:58:17 +00:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2014-07-16 17:40:22 +00:00
|
|
|
\OC::$server->getSession()->close();
|
2014-08-31 08:05:59 +00:00
|
|
|
$l = \OC::$server->getL10N('files');
|
2014-07-01 12:58:17 +00:00
|
|
|
|
|
|
|
// Load the files
|
2015-02-13 12:33:20 +00:00
|
|
|
$dir = isset($_GET['dir']) ? (string)$_GET['dir'] : '';
|
2014-07-01 12:58:17 +00:00
|
|
|
$dir = \OC\Files\Filesystem::normalizePath($dir);
|
2014-06-30 14:12:12 +00:00
|
|
|
|
2014-07-01 12:58:17 +00:00
|
|
|
try {
|
2014-06-30 14:12:12 +00:00
|
|
|
$dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
|
|
|
|
if (!$dirInfo || !$dirInfo->getType() === 'dir') {
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir=';
|
|
|
|
|
|
|
|
$permissions = $dirInfo->getPermissions();
|
|
|
|
|
2015-02-13 12:33:20 +00:00
|
|
|
$sortAttribute = isset($_GET['sort']) ? (string)$_GET['sort'] : 'name';
|
2014-06-30 14:12:12 +00:00
|
|
|
$sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
|
|
|
|
|
|
|
|
// make filelist
|
|
|
|
|
|
|
|
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
|
2014-12-18 14:36:18 +00:00
|
|
|
$files = \OCA\Files\Helper::populateTags($files);
|
2014-06-30 14:12:12 +00:00
|
|
|
$data['directory'] = $dir;
|
|
|
|
$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
|
|
|
|
$data['permissions'] = $permissions;
|
|
|
|
|
|
|
|
OCP\JSON::success(array('data' => $data));
|
|
|
|
} catch (\OCP\Files\StorageNotAvailableException $e) {
|
2014-09-29 19:40:32 +00:00
|
|
|
\OCP\Util::logException('files', $e);
|
2014-06-30 14:12:12 +00:00
|
|
|
OCP\JSON::error(array(
|
|
|
|
'data' => array(
|
|
|
|
'exception' => '\OCP\Files\StorageNotAvailableException',
|
|
|
|
'message' => $l->t('Storage not available')
|
|
|
|
)
|
|
|
|
));
|
2014-07-01 12:58:17 +00:00
|
|
|
} catch (\OCP\Files\StorageInvalidException $e) {
|
2014-09-29 19:40:32 +00:00
|
|
|
\OCP\Util::logException('files', $e);
|
2014-07-01 12:58:17 +00:00
|
|
|
OCP\JSON::error(array(
|
|
|
|
'data' => array(
|
|
|
|
'exception' => '\OCP\Files\StorageInvalidException',
|
|
|
|
'message' => $l->t('Storage invalid')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
} catch (\Exception $e) {
|
2014-09-29 19:40:32 +00:00
|
|
|
\OCP\Util::logException('files', $e);
|
2014-07-01 12:58:17 +00:00
|
|
|
OCP\JSON::error(array(
|
|
|
|
'data' => array(
|
|
|
|
'exception' => '\Exception',
|
|
|
|
'message' => $l->t('Unknown error')
|
|
|
|
)
|
|
|
|
));
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|