Add docstrings to download classes
This commit is contained in:
parent
35837010ae
commit
2982f78b45
@ -12,12 +12,26 @@
|
|||||||
namespace OCA\Office;
|
namespace OCA\Office;
|
||||||
|
|
||||||
class Download {
|
class Download {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filesystem view
|
||||||
|
* @var \OC\Files\View
|
||||||
|
*/
|
||||||
protected $view;
|
protected $view;
|
||||||
// File to be served
|
|
||||||
|
/**
|
||||||
|
* Path to the File to be served, relative to the view
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $filepath;
|
protected $filepath;
|
||||||
|
|
||||||
protected $instance;
|
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){
|
public function __construct($view, $filepath){
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
@ -29,6 +43,9 @@ class Download {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the requested content
|
||||||
|
*/
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
\OCP\Response::disableCaching();
|
\OCP\Response::disableCaching();
|
||||||
|
|
||||||
@ -40,22 +57,40 @@ class Download {
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the requested file
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
protected function getFilename(){
|
protected function getFilename(){
|
||||||
return basename($this->filepath);
|
return basename($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the size of the requested file
|
||||||
|
*/
|
||||||
protected function getFilesize(){
|
protected function getFilesize(){
|
||||||
return $this->view->filesize($this->filepath);
|
return $this->view->filesize($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mimetype of the requested file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function getMimeType(){
|
protected function getMimeType(){
|
||||||
return $this->view->getMimeType($this->filepath);
|
return $this->view->getMimeType($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the requested file exists
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function fileExists(){
|
protected function fileExists(){
|
||||||
return $this->view->file_exists($this->filepath);
|
return $this->view->file_exists($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send 404 Response
|
||||||
|
*/
|
||||||
protected function sendNotFound(){
|
protected function sendNotFound(){
|
||||||
header("HTTP/1.0 404 Not Found");
|
header("HTTP/1.0 404 Not Found");
|
||||||
$tmpl = new OCP\Template('', '404', 'guest');
|
$tmpl = new OCP\Template('', '404', 'guest');
|
||||||
|
@ -18,11 +18,19 @@ class Range extends \OCA\Office\Download {
|
|||||||
// End of the range
|
// End of the range
|
||||||
protected $end;
|
protected $end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build download model to serve HTTP_RANGE
|
||||||
|
* @param type $view - filesystem view
|
||||||
|
* @param type $filepath - path to the file relative to this view root
|
||||||
|
*/
|
||||||
public function __construct($view, $filepath){
|
public function __construct($view, $filepath){
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the requested parts of the file
|
||||||
|
*/
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
|
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
|
||||||
$this->sendNotSatisfiable();
|
$this->sendNotSatisfiable();
|
||||||
@ -57,6 +65,9 @@ class Range extends \OCA\Office\Download {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send 416 if we can't satisfy the requested ranges
|
||||||
|
*/
|
||||||
protected function sendNotSatisfiable(){
|
protected function sendNotSatisfiable(){
|
||||||
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
||||||
header('Content-Range: bytes */' . $this->getFilesize()); // Required in 416.
|
header('Content-Range: bytes */' . $this->getFilesize()); // Required in 416.
|
||||||
|
@ -10,15 +10,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Office\Download;
|
namespace OCA\Office\Download;
|
||||||
use OCA\Office\View;
|
|
||||||
|
|
||||||
class Simple extends \OCA\Office\Download {
|
class Simple extends \OCA\Office\Download {
|
||||||
|
|
||||||
|
|
||||||
public function __construct($view, $filepath){
|
public function __construct($view, $filepath){
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the whole file content as a response
|
||||||
|
*/
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
header( 'Content-Type:' . $this->getMimeType() );
|
header( 'Content-Type:' . $this->getMimeType() );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user