Use files node API for single file downloads

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-11-20 09:06:47 +01:00 committed by Arthur Schiwon
parent 5a986f02a3
commit 9e5d6114d5
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 28 additions and 14 deletions

View File

@ -284,30 +284,44 @@ class OC_Files {
*/ */
private static function getSingleFile($view, $dir, $name, $params) { private static function getSingleFile($view, $dir, $name, $params) {
$filename = $dir . '/' . $name; $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(); OC_Util::obEnd();
$view->lockFile($filename, ILockingProvider::LOCK_SHARED); $view->lockFile($filename, ILockingProvider::LOCK_SHARED);
$rangeArray = array(); $rangeArray = array();
if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') { if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') {
$rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), $fileSize);
\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');
} }
self::sendHeaders($filename, $name, $rangeArray);
if (isset($params['head']) && $params['head']) { if (isset($params['head']) && $params['head']) {
return; return;
} }
if (!empty($rangeArray)) { if (!empty($rangeArray)) {
try { try {
if (count($rangeArray) == 1) { if (count($rangeArray) == 1) {