list.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. \OC::$session->close();
  4. $l = OC_L10N::get('files');
  5. // Load the files
  6. $dir = isset($_GET['dir']) ? $_GET['dir'] : '';
  7. $dir = \OC\Files\Filesystem::normalizePath($dir);
  8. try {
  9. $dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
  10. if (!$dirInfo || !$dirInfo->getType() === 'dir') {
  11. header("HTTP/1.0 404 Not Found");
  12. exit();
  13. }
  14. $data = array();
  15. $baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir=';
  16. $permissions = $dirInfo->getPermissions();
  17. $sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name';
  18. $sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
  19. // make filelist
  20. $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
  21. $data['directory'] = $dir;
  22. $data['files'] = \OCA\Files\Helper::formatFileInfos($files);
  23. $data['permissions'] = $permissions;
  24. OCP\JSON::success(array('data' => $data));
  25. } catch (\OCP\Files\StorageNotAvailableException $e) {
  26. OCP\JSON::error(array(
  27. 'data' => array(
  28. 'exception' => '\OCP\Files\StorageNotAvailableException',
  29. 'message' => $l->t('Storage not available')
  30. )
  31. ));
  32. } catch (\OCP\Files\StorageInvalidException $e) {
  33. OCP\JSON::error(array(
  34. 'data' => array(
  35. 'exception' => '\OCP\Files\StorageInvalidException',
  36. 'message' => $l->t('Storage invalid')
  37. )
  38. ));
  39. } catch (\Exception $e) {
  40. OCP\JSON::error(array(
  41. 'data' => array(
  42. 'exception' => '\Exception',
  43. 'message' => $l->t('Unknown error')
  44. )
  45. ));
  46. }