nextcloud/apps/files/ajax/list.php

60 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2014-07-01 16:58:17 +04:00
OCP\JSON::checkLoggedIn();
\OC::$server->getSession()->close();
2014-08-31 12:05:59 +04:00
$l = \OC::$server->getL10N('files');
2014-07-01 16:58:17 +04:00
// Load the files
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
2014-07-01 16:58:17 +04:00
try {
$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();
$sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name';
$sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
// make filelist
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
$files = \OCA\Files\Helper::populateTags($files);
$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 23:40:32 +04:00
\OCP\Util::logException('files', $e);
OCP\JSON::error(array(
'data' => array(
'exception' => '\OCP\Files\StorageNotAvailableException',
'message' => $l->t('Storage not available')
)
));
2014-07-01 16:58:17 +04:00
} catch (\OCP\Files\StorageInvalidException $e) {
2014-09-29 23:40:32 +04:00
\OCP\Util::logException('files', $e);
2014-07-01 16:58:17 +04:00
OCP\JSON::error(array(
'data' => array(
'exception' => '\OCP\Files\StorageInvalidException',
'message' => $l->t('Storage invalid')
)
));
} catch (\Exception $e) {
2014-09-29 23:40:32 +04:00
\OCP\Util::logException('files', $e);
2014-07-01 16:58:17 +04:00
OCP\JSON::error(array(
'data' => array(
'exception' => '\Exception',
'message' => $l->t('Unknown error')
)
));
}