diff --git a/ajax/download.php b/ajax/download.php deleted file mode 100644 index 0146514c..00000000 --- a/ajax/download.php +++ /dev/null @@ -1,30 +0,0 @@ -getId()); - $genesis = new Genesis($file); - $fullPath = $genesis->getPath(); - } else { - $fullPath = '/files' . $path; - } - $download = new Download(\OCP\User::getUser(), $fullPath); - $download->sendResponse(); -} -exit(); \ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php index a6ef87c5..f023407d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -28,6 +28,7 @@ $application->registerRoutes($this, array( array('name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => array('GET', 'HEAD')), array('name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'), array('name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'), + array('name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => array('GET', 'HEAD')), //settings array('name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'), array('name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'), @@ -37,9 +38,6 @@ $application->registerRoutes($this, array( /** @var $this \OC\Route\Router */ -$this->create('documents_ajax_download', 'ajax/download.php') - ->actionInclude('documents/ajax/download.php'); - $this->create('documents_ajax_mimes', 'ajax/mimes.php') ->actionInclude('documents/ajax/mimes.php'); diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index 7bf6e422..ae671ec8 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -21,6 +21,8 @@ use \OCA\Documents\Db; use \OCA\Documents\Helper; use \OCA\Documents\Storage; use \OCA\Documents\Download; +use \OCA\Documents\File; +use OCA\Documents\Genesis; class DocumentController extends Controller{ @@ -86,6 +88,24 @@ class DocumentController extends Controller{ $download->sendResponse(); } + /** + * @NoAdminRequired + */ + public function download($path){ + if ($path){ + if (\OC\Files\Filesystem::getMimeType($path) !== \OCA\Documents\Filter\Office::NATIVE_MIMETYPE){ + $fileInfo = \OC\Files\Filesystem::getFileInfo($path); + $file = new File($fileInfo->getId()); + $genesis = new Genesis($file); + $fullPath = $genesis->getPath(); + } else { + $fullPath = '/files' . $path; + } + $download = new Download($this->uid, $fullPath); + $download->sendResponse(); + } + } + /** * @NoAdminRequired */ diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 12aa7e35..ef00d014 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -63,7 +63,8 @@ var odfViewer = { } else { //Public page, files app, etc var dirName = $('#dir').val()!='/' ? $('#dir').val() + '/' : '/'; - var location = OC.filePath('documents', 'ajax', 'download.php') + '?path=' + dirName + encodeURIComponent(filename); + var location = OC.filePath('documents', 'ajax', 'download.php') + '?path=' + dirName + encodeURIComponent(filename) + + '&requesttoken=' + oc_requesttoken; OC.addStyle('documents', '3rdparty/webodf/editor'); }