2011-03-04 01:08:54 +03:00
|
|
|
<?php
|
2015-03-26 13:44:34 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2018-01-26 01:16:13 +03:00
|
|
|
|
|
|
|
use OCP\Files\StorageNotAvailableException;
|
|
|
|
use OCP\Files\StorageInvalidException;
|
|
|
|
|
2018-03-22 15:19:29 +03:00
|
|
|
\OC_JSON::checkLoggedIn();
|
2014-07-16 21:40:22 +04:00
|
|
|
\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
|
2015-02-13 15:33:20 +03:00
|
|
|
$dir = isset($_GET['dir']) ? (string)$_GET['dir'] : '';
|
2014-07-01 16:58:17 +04:00
|
|
|
$dir = \OC\Files\Filesystem::normalizePath($dir);
|
2014-06-30 18:12:12 +04:00
|
|
|
|
2014-07-01 16:58:17 +04:00
|
|
|
try {
|
2014-06-30 18:12:12 +04:00
|
|
|
$dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
|
|
|
|
if (!$dirInfo || !$dirInfo->getType() === 'dir') {
|
2018-06-26 11:32:50 +03:00
|
|
|
http_response_code(404);
|
2014-06-30 18:12:12 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array();
|
2018-03-14 00:04:08 +03:00
|
|
|
$baseUrl = \OC::$server->getURLGenerator()->linkTo('files', 'index.php') . '?dir=';
|
2014-06-30 18:12:12 +04:00
|
|
|
|
|
|
|
$permissions = $dirInfo->getPermissions();
|
|
|
|
|
2015-02-13 15:33:20 +03:00
|
|
|
$sortAttribute = isset($_GET['sort']) ? (string)$_GET['sort'] : 'name';
|
2014-06-30 18:12:12 +04:00
|
|
|
$sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
|
2015-04-13 11:35:45 +03:00
|
|
|
$mimetypeFilters = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes']) : '';
|
2014-06-30 18:12:12 +04:00
|
|
|
|
2015-04-13 11:35:45 +03:00
|
|
|
$files = [];
|
|
|
|
// Clean up duplicates from array
|
|
|
|
if (is_array($mimetypeFilters) && count($mimetypeFilters)) {
|
|
|
|
$mimetypeFilters = array_unique($mimetypeFilters);
|
|
|
|
|
|
|
|
if (!in_array('httpd/unix-directory', $mimetypeFilters)) {
|
|
|
|
// append folder filter to be able to browse folders
|
|
|
|
$mimetypeFilters[] = 'httpd/unix-directory';
|
|
|
|
}
|
|
|
|
|
|
|
|
// create filelist with mimetype filter - as getFiles only supports on
|
|
|
|
// mimetype filter at once we will filter this folder for each
|
|
|
|
// mimetypeFilter
|
|
|
|
foreach ($mimetypeFilters as $mimetypeFilter) {
|
|
|
|
$files = array_merge($files, \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection, $mimetypeFilter));
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort the files accordingly
|
|
|
|
$files = \OCA\Files\Helper::sortFiles($files, $sortAttribute, $sortDirection);
|
|
|
|
} else {
|
|
|
|
// create file list without mimetype filter
|
|
|
|
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
|
|
|
|
}
|
2014-06-30 18:12:12 +04:00
|
|
|
|
|
|
|
$data['directory'] = $dir;
|
|
|
|
$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
|
|
|
|
$data['permissions'] = $permissions;
|
|
|
|
|
2018-03-22 15:19:29 +03:00
|
|
|
\OC_JSON::success(array('data' => $data));
|
2014-06-30 18:12:12 +04:00
|
|
|
} catch (\OCP\Files\StorageNotAvailableException $e) {
|
2018-03-12 20:10:59 +03:00
|
|
|
\OC::$server->getLogger()->logException($e, ['app' => 'files']);
|
2018-03-22 15:19:29 +03:00
|
|
|
\OC_JSON::error([
|
2016-09-19 13:17:06 +03:00
|
|
|
'data' => [
|
2018-01-26 01:16:13 +03:00
|
|
|
'exception' => StorageNotAvailableException::class,
|
2016-09-19 13:17:06 +03:00
|
|
|
'message' => $l->t('Storage is temporarily not available')
|
|
|
|
]
|
|
|
|
]);
|
2014-07-01 16:58:17 +04:00
|
|
|
} catch (\OCP\Files\StorageInvalidException $e) {
|
2018-03-12 20:10:59 +03:00
|
|
|
\OC::$server->getLogger()->logException($e, ['app' => 'files']);
|
2018-03-22 15:19:29 +03:00
|
|
|
\OC_JSON::error(array(
|
2014-07-01 16:58:17 +04:00
|
|
|
'data' => array(
|
2018-01-26 01:16:13 +03:00
|
|
|
'exception' => StorageInvalidException::class,
|
2014-07-01 16:58:17 +04:00
|
|
|
'message' => $l->t('Storage invalid')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
} catch (\Exception $e) {
|
2018-03-12 20:10:59 +03:00
|
|
|
\OC::$server->getLogger()->logException($e, ['app' => 'files']);
|
2018-03-22 15:19:29 +03:00
|
|
|
\OC_JSON::error(array(
|
2014-07-01 16:58:17 +04:00
|
|
|
'data' => array(
|
2018-01-26 01:16:13 +03:00
|
|
|
'exception' => \Exception::class,
|
2014-07-01 16:58:17 +04:00
|
|
|
'message' => $l->t('Unknown error')
|
|
|
|
)
|
|
|
|
));
|
2013-08-17 15:07:18 +04:00
|
|
|
}
|