Merge pull request #7455 from owncloud/rawlist-fileinfo
Update rawlist to work with new fileinfo object
This commit is contained in:
commit
8a93a2e7d5
2 changed files with 29 additions and 32 deletions
|
@ -1,12 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// only need filesystem apps
|
// only need filesystem apps
|
||||||
$RUNTIME_APPTYPES=array('filesystem');
|
$RUNTIME_APPTYPES = array('filesystem');
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
|
|
||||||
// Load the files
|
// Load the files
|
||||||
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
|
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
||||||
$mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : '';
|
$mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : '';
|
||||||
|
|
||||||
// Clean up duplicates from array and deal with non-array requests
|
// Clean up duplicates from array and deal with non-array requests
|
||||||
|
@ -18,43 +18,40 @@ if (is_array($mimetypes)) {
|
||||||
|
|
||||||
// make filelist
|
// make filelist
|
||||||
$files = array();
|
$files = array();
|
||||||
|
/**
|
||||||
|
* @var \OCP\Files\FileInfo[] $files
|
||||||
|
*/
|
||||||
// If a type other than directory is requested first load them.
|
// If a type other than directory is requested first load them.
|
||||||
if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
|
if ($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
|
||||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, 'httpd/unix-directory'));
|
||||||
$file['directory'] = $dir;
|
|
||||||
$file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
|
|
||||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
|
||||||
$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
|
|
||||||
$files[] = $file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($mimetypes) && count($mimetypes)) {
|
if (is_array($mimetypes) && count($mimetypes)) {
|
||||||
foreach ($mimetypes as $mimetype) {
|
foreach ($mimetypes as $mimetype) {
|
||||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, $mimetype));
|
||||||
$file['directory'] = $dir;
|
|
||||||
$file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
|
|
||||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
|
||||||
$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
|
|
||||||
$files[] = $file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir));
|
||||||
$file['directory'] = $dir;
|
}
|
||||||
$file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
|
|
||||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
$result = array();
|
||||||
$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
|
foreach ($files as $file) {
|
||||||
$files[] = $file;
|
$fileData = array();
|
||||||
}
|
$fileData['directory'] = $dir;
|
||||||
|
$fileData['name'] = $file->getName();
|
||||||
|
$fileData['type'] = $file->getType();
|
||||||
|
$fileData['path'] = $file['path'];
|
||||||
|
$fileData['id'] = $file->getId();
|
||||||
|
$fileData['size'] = $file->getSize();
|
||||||
|
$fileData['mtime'] = $file->getMtime();
|
||||||
|
$fileData['mimetype'] = $file->getMimetype();
|
||||||
|
$fileData['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file->getMimetype());
|
||||||
|
$fileData["date"] = OCP\Util::formatDate($file->getMtime());
|
||||||
|
$fileData['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
|
||||||
|
$result[] = $fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by name
|
// Sort by name
|
||||||
usort($files, function ($a, $b) {
|
usort($result, array('\OCA\Files\Helper', 'fileCmp'));
|
||||||
if ($a['name'] === $b['name']) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ($a['name'] < $b['name']) ? -1 : 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
OC_JSON::success(array('data' => $files));
|
OC_JSON::success(array('data' => $result));
|
||||||
|
|
|
@ -761,7 +761,7 @@ class Filesystem {
|
||||||
*
|
*
|
||||||
* @param string $directory path under datadirectory
|
* @param string $directory path under datadirectory
|
||||||
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
|
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
|
||||||
* @return array
|
* @return \OC\Files\FileInfo[]
|
||||||
*/
|
*/
|
||||||
public static function getDirectoryContent($directory, $mimetype_filter = '') {
|
public static function getDirectoryContent($directory, $mimetype_filter = '') {
|
||||||
return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
|
return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
|
||||||
|
|
Loading…
Reference in a new issue