|
|
|
@ -12,12 +12,26 @@
|
|
|
|
|
namespace OCA\Office;
|
|
|
|
|
|
|
|
|
|
class Download {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filesystem view
|
|
|
|
|
* @var \OC\Files\View
|
|
|
|
|
*/
|
|
|
|
|
protected $view;
|
|
|
|
|
// File to be served
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Path to the File to be served, relative to the view
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $filepath;
|
|
|
|
|
|
|
|
|
|
protected $instance;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build download model according to the headers
|
|
|
|
|
* @param type $view - filesystem view
|
|
|
|
|
* @param type $filepath - path to the file relative to this view root
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($view, $filepath){
|
|
|
|
|
$this->filepath = $filepath;
|
|
|
|
|
$this->view = $view;
|
|
|
|
@ -29,6 +43,9 @@ class Download {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send the requested content
|
|
|
|
|
*/
|
|
|
|
|
public function sendResponse(){
|
|
|
|
|
\OCP\Response::disableCaching();
|
|
|
|
|
|
|
|
|
@ -40,22 +57,40 @@ class Download {
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the name of the requested file
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
protected function getFilename(){
|
|
|
|
|
return basename($this->filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the size of the requested file
|
|
|
|
|
*/
|
|
|
|
|
protected function getFilesize(){
|
|
|
|
|
return $this->view->filesize($this->filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the mimetype of the requested file
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getMimeType(){
|
|
|
|
|
return $this->view->getMimeType($this->filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the requested file exists
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function fileExists(){
|
|
|
|
|
return $this->view->file_exists($this->filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send 404 Response
|
|
|
|
|
*/
|
|
|
|
|
protected function sendNotFound(){
|
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
|
$tmpl = new OCP\Template('', '404', 'guest');
|
|
|
|
|