Blame view

sources/apps/files/ajax/list.php 1.45 KB
03e52840d   Kload   Init
1
  <?php
03e52840d   Kload   Init
2
  OCP\JSON::checkLoggedIn();
6d9380f96   Cédric Dupont   Update sources OC...
3
4
  \OC::$session->close();
  $l = OC_L10N::get('files');
03e52840d   Kload   Init
5
6
  
  // Load the files
6d9380f96   Cédric Dupont   Update sources OC...
7
  $dir = isset($_GET['dir']) ? $_GET['dir'] : '';
31b7f2792   Kload   Upgrade to ownclo...
8
  $dir = \OC\Files\Filesystem::normalizePath($dir);
03e52840d   Kload   Init
9

6d9380f96   Cédric Dupont   Update sources OC...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  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);
  	$data['directory'] = $dir;
  	$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
  	$data['permissions'] = $permissions;
  
  	OCP\JSON::success(array('data' => $data));
  } catch (\OCP\Files\StorageNotAvailableException $e) {
  	OCP\JSON::error(array(
  		'data' => array(
  			'exception' => '\OCP\Files\StorageNotAvailableException',
  			'message' => $l->t('Storage not available')
  		)
  	));
  } catch (\OCP\Files\StorageInvalidException $e) {
  	OCP\JSON::error(array(
  		'data' => array(
  			'exception' => '\OCP\Files\StorageInvalidException',
  			'message' => $l->t('Storage invalid')
  		)
  	));
  } catch (\Exception $e) {
  	OCP\JSON::error(array(
  		'data' => array(
  			'exception' => '\Exception',
  			'message' => $l->t('Unknown error')
  		)
  	));
03e52840d   Kload   Init
54
  }