diff options
Diffstat (limited to 'apps/files/ajax')
-rw-r--r-- | apps/files/ajax/list.php | 22 | ||||
-rw-r--r-- | apps/files/ajax/newfile.php | 16 | ||||
-rw-r--r-- | apps/files/ajax/newfolder.php | 4 | ||||
-rw-r--r-- | apps/files/ajax/rawlist.php | 54 | ||||
-rw-r--r-- | apps/files/ajax/upload.php | 47 |
5 files changed, 29 insertions, 114 deletions
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index 3bb35579d5f..2d76b685018 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -7,37 +7,21 @@ OCP\JSON::checkLoggedIn(); $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; $dir = \OC\Files\Filesystem::normalizePath($dir); $dirInfo = \OC\Files\Filesystem::getFileInfo($dir); -if (!$dirInfo->getType() === 'dir') { +if (!$dirInfo || !$dirInfo->getType() === 'dir') { header("HTTP/1.0 404 Not Found"); exit(); } -$doBreadcrumb = isset($_GET['breadcrumb']); $data = array(); $baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir='; $permissions = $dirInfo->getPermissions(); -// Make breadcrumb -if($doBreadcrumb) { - $breadcrumb = \OCA\Files\Helper::makeBreadcrumb($dir); - - $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); - $breadcrumbNav->assign('breadcrumb', $breadcrumb, false); - $breadcrumbNav->assign('baseURL', $baseUrl); - - $data['breadcrumb'] = $breadcrumbNav->fetchPage(); -} - // make filelist $files = \OCA\Files\Helper::getFiles($dir); -$list = new OCP\Template("files", "part.list", ""); -$list->assign('files', $files, false); -$list->assign('baseURL', $baseUrl, false); -$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); -$list->assign('isPublic', false); -$data['files'] = $list->fetchPage(); +$data['directory'] = $dir; +$data['files'] = \OCA\Files\Helper::formatFileInfos($files); $data['permissions'] = $permissions; OCP\JSON::success(array('data' => $data)); diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 1234cf11394..7d6be59beab 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -112,9 +112,8 @@ if($source) { } if($result) { $meta = \OC\Files\Filesystem::getFileInfo($target); - $mime=$meta['mimetype']; - $id = $meta['fileid']; - $eventSource->send('success', array('mime' => $mime, 'size' => \OC\Files\Filesystem::filesize($target), 'id' => $id, 'etag' => $meta['etag'])); + $data = \OCA\Files\Helper::formatFileInfo($meta); + $eventSource->send('success', $data); } else { $eventSource->send('error', array('message' => $l10n->t('Error while downloading %s to %s', array($source, $target)))); } @@ -139,16 +138,7 @@ if($source) { if($success) { $meta = \OC\Files\Filesystem::getFileInfo($target); - $id = $meta['fileid']; - $mime = $meta['mimetype']; - $size = $meta['size']; - OCP\JSON::success(array('data' => array( - 'id' => $id, - 'mime' => $mime, - 'size' => $size, - 'content' => $content, - 'etag' => $meta['etag'], - ))); + OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta))); exit(); } } diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php index 032447460f3..89c241189d7 100644 --- a/apps/files/ajax/newfolder.php +++ b/apps/files/ajax/newfolder.php @@ -58,8 +58,8 @@ if(\OC\Files\Filesystem::mkdir($target)) { $path = '/'.$foldername; } $meta = \OC\Files\Filesystem::getFileInfo($path); - $id = $meta['fileid']; - OCP\JSON::success(array('data' => array('id' => $id))); + $meta['type'] = 'dir'; // missing ?! + OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta))); exit(); } diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php deleted file mode 100644 index f18bbffb74a..00000000000 --- a/apps/files/ajax/rawlist.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -OCP\JSON::checkLoggedIn(); -\OC::$session->close(); - -// Load the files -$dir = isset($_GET['dir']) ? $_GET['dir'] : ''; -$mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : ''; - -// Clean up duplicates from array and deal with non-array requests -if (is_array($mimetypes)) { - $mimetypes = array_unique($mimetypes); -} elseif (is_null($mimetypes)) { - $mimetypes = array($_GET['mimetypes']); -} - -// make filelist -$files = array(); -/** - * @var \OCP\Files\FileInfo[] $files - */ -// If a type other than directory is requested first load them. -if ($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { - $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, 'httpd/unix-directory')); -} - -if (is_array($mimetypes) && count($mimetypes)) { - foreach ($mimetypes as $mimetype) { - $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, $mimetype)); - } -} else { - $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir)); -} -// Sort by name -usort($files, array('\OCA\Files\Helper', 'fileCmp')); - -$result = array(); -foreach ($files as $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; -} - -OC_JSON::success(array('data' => $result)); diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 4ed51c52775..b21a9dfba2e 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -20,6 +20,10 @@ if (empty($_POST['dirToken'])) { die(); } } else { + // TODO: ideally this code should be in files_sharing/ajax/upload.php + // and the upload/file transfer code needs to be refactored into a utility method + // that could be used there + // return only read permissions for public upload $allowedPermissions = OCP\PERMISSION_READ; $public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/'; @@ -141,19 +145,14 @@ if (strpos($dir, '..') === false) { $error = $l->t('The target folder has been moved or deleted.'); $errorCode = 'targetnotfound'; } else { - $result[] = array('status' => 'success', - 'mime' => $meta['mimetype'], - 'mtime' => $meta['mtime'], - 'size' => $meta['size'], - 'id' => $meta['fileid'], - 'name' => basename($target), - 'etag' => $meta['etag'], - 'originalname' => $files['tmp_name'][$i], - 'uploadMaxFilesize' => $maxUploadFileSize, - 'maxHumanFilesize' => $maxHumanFileSize, - 'permissions' => $meta['permissions'] & $allowedPermissions, - 'directory' => $directory, - ); + $data = \OCA\Files\Helper::formatFileInfo($meta); + $data['status'] = 'success'; + $data['originalname'] = $files['tmp_name'][$i]; + $data['uploadMaxFilesize'] = $maxUploadFileSize; + $data['maxHumanFilesize'] = $maxHumanFileSize; + $data['permissions'] = $meta['permissions'] & $allowedPermissions; + $data['directory'] = $directory; + $result[] = $data; } } else { @@ -169,19 +168,15 @@ if (strpos($dir, '..') === false) { if ($meta === false) { $error = $l->t('Upload failed. Could not get file info.'); } else { - $result[] = array('status' => 'existserror', - 'mime' => $meta['mimetype'], - 'mtime' => $meta['mtime'], - 'size' => $meta['size'], - 'id' => $meta['fileid'], - 'name' => basename($target), - 'etag' => $meta['etag'], - 'originalname' => $files['tmp_name'][$i], - 'uploadMaxFilesize' => $maxUploadFileSize, - 'maxHumanFilesize' => $maxHumanFileSize, - 'permissions' => $meta['permissions'] & $allowedPermissions, - 'directory' => $directory, - ); + $data = \OCA\Files\Helper::formatFileInfo($meta); + $data['permissions'] = $data['permissions'] & $allowedPermissions; + $data['status'] = 'existserror'; + $data['originalname'] = $files['tmp_name'][$i]; + $data['uploadMaxFilesize'] = $maxUploadFileSize; + $data['maxHumanFilesize'] = $maxHumanFileSize; + $data['permissions'] = $meta['permissions'] & $allowedPermissions; + $data['directory'] = $directory; + $result[] = $data; } } } |