diff --git a/ajax/download.php b/ajax/download.php new file mode 100644 index 00000000..de013238 --- /dev/null +++ b/ajax/download.php @@ -0,0 +1,18 @@ +sendResponse(); \ No newline at end of file diff --git a/ajax/sessionController.php b/ajax/sessionController.php index b8b715ba..0f458c37 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -90,7 +90,6 @@ class SessionController extends Controller{ self::preDispatchGuest(); } - list($view, $path) = $file->getOwnerViewAndPath(); $isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path); diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 398a409f..e202155f 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -54,7 +54,7 @@ var odfViewer = { var location = filename; } else { //Public page, files app, etc - var location = fileDownloadPath($('#dir').val(), filename); + var location = OC.filePath('documents', 'ajax', 'download.php') + '?path=' + $('#dir').val() + encodeURIComponent(filename); OC.addStyle('documents', '3rdparty/webodf/editor'); } diff --git a/lib/download/range.php b/lib/download/range.php index d7ab37e0..5aabb2ac 100644 --- a/lib/download/range.php +++ b/lib/download/range.php @@ -38,29 +38,33 @@ class Download_Range extends \OCA\Documents\Download { if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){ $this->sendNotSatisfiable(); } + + $mimetype = $this->getMimeType(); + $content = $this->view->file_get_contents($this->filepath); + $data = Filter::read($content, $mimetype); + $size = strlen($data['content']); + $ranges = explode(',', substr($_SERVER['HTTP_RANGE'], 6)); foreach ($ranges as $range){ $parts = explode('-', $range); $start = isset($parts[0]) ? $parts[0] : 0; - $end = isset($parts[1]) ? $parts[1] : $this->getFilesize() - 1; + $end = isset($parts[1]) ? $parts[1] : $size - 1; if ($start > $end){ $this->sendNotSatisfiable(); } - $handle = $this->view->fopen($this->filepath, 'rb'); - \fseek($handle, $start); - $buffer = \fread($handle, $end - $start); + $buffer = substr($data['content'], $start, $end - $start); $md5Sum = md5($buffer); - \fclose($handle); + // send the headers and data header("Content-Length: " . $end - $start); header("Content-md5: " . $md5Sum); header("Accept-Ranges: bytes"); - header('Content-Range: bytes ' . $start . '-' . ($end) . '/' . $this->getFilesize()); + header('Content-Range: bytes ' . $start . '-' . ($end) . '/' . $size); header("Connection: close"); - header("Content-type: " . $this->getMimeType()); + header("Content-type: " . $data['mimetype']); header('Content-Disposition: attachment; filename=' . $this->getFilename()); \OC_Util::obEnd(); echo $buffer; diff --git a/lib/download/simple.php b/lib/download/simple.php index 61255e1d..db955ecb 100644 --- a/lib/download/simple.php +++ b/lib/download/simple.php @@ -25,7 +25,11 @@ class Download_Simple extends \OCA\Documents\Download { * Send the whole file content as a response */ public function sendResponse(){ - header( 'Content-Type:' . $this->getMimeType() ); + $mimetype = $this->getMimeType(); + $content = $this->view->file_get_contents($this->filepath); + $data = Filter::read($content, $mimetype); + + header( 'Content-Type:' . $data['mimetype'] ); $encodedName = rawurlencode($this->getFilename()); if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])){ @@ -37,9 +41,10 @@ class Download_Simple extends \OCA\Documents\Download { . '; filepath="' . $encodedName . '"'); } - header('Content-Length: ' . $this->view->filesize($this->filepath)); + header('Content-Length: ' . strlen($data['content'])); \OC_Util::obEnd(); - $this->view->readfile($this->filepath); + + echo $data['content']; } }