diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-11-20 09:06:47 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-12-19 13:05:09 +0100 |
commit | 9e5d6114d54479724bc7552cccd276fc691b1c37 (patch) | |
tree | 08202ba6c7777bce6bf1e373729bbf0b30655cdc /lib | |
parent | 5a986f02a33bd1f54fd951af7dc5a1fed02b8340 (diff) | |
download | nextcloud-server-9e5d6114d54479724bc7552cccd276fc691b1c37.tar.gz nextcloud-server-9e5d6114d54479724bc7552cccd276fc691b1c37.zip |
Use files node API for single file downloads
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/legacy/files.php | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index be433f3382d..28396a9d076 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -284,30 +284,44 @@ class OC_Files { */ private static function getSingleFile($view, $dir, $name, $params) { $filename = $dir . '/' . $name; + $file = null; + + try { + $userFolder = \OC::$server->getRootFolder()->get(\OC\Files\Filesystem::getRoot()); + $file = $userFolder->get($filename); + if(!$file instanceof \OC\Files\Node\File || !$file->isReadable()) { + http_response_code(403); + die('403 Forbidden'); + } + $fileSize = $file->getSize(); + } catch (\OCP\Files\NotPermittedException $e) { + http_response_code(403); + die('403 Forbidden'); + } catch (\OCP\Files\InvalidPathException $e) { + http_response_code(403); + die('403 Forbidden'); + } catch (\OCP\Files\NotFoundException $e) { + http_response_code(404); + $tmpl = new OC_Template('', '404', 'guest'); + $tmpl->printPage(); + exit(); + } + OC_Util::obEnd(); $view->lockFile($filename, ILockingProvider::LOCK_SHARED); $rangeArray = array(); if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') { - $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), - \OC\Files\Filesystem::filesize($filename)); - } - - if (\OC\Files\Filesystem::isReadable($filename)) { - self::sendHeaders($filename, $name, $rangeArray); - } elseif (!\OC\Files\Filesystem::file_exists($filename)) { - http_response_code(404); - $tmpl = new OC_Template('', '404', 'guest'); - $tmpl->printPage(); - exit(); - } else { - http_response_code(403); - die('403 Forbidden'); + $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), $fileSize); } + + self::sendHeaders($filename, $name, $rangeArray); + if (isset($params['head']) && $params['head']) { return; } + if (!empty($rangeArray)) { try { if (count($rangeArray) == 1) { |