|
@@ -1,6 +1,7 @@ |
|
|
<?php |
|
|
<?php |
|
|
namespace OCA\Raw\Controller; |
|
|
namespace OCA\Raw\Controller; |
|
|
|
|
|
|
|
|
|
|
|
use \Exception; |
|
|
use OCP\IRequest; |
|
|
use OCP\IRequest; |
|
|
use OCP\Share\IManager; |
|
|
use OCP\Share\IManager; |
|
|
use OCP\AppFramework\Controller; |
|
|
use OCP\AppFramework\Controller; |
|
@@ -28,9 +29,33 @@ class PubPageController extends Controller { |
|
|
public function getByToken($token) { |
|
|
public function getByToken($token) { |
|
|
$share = $this->manager->getShareByToken($token); |
|
|
$share = $this->manager->getShareByToken($token); |
|
|
$node = $share->getNode(); |
|
|
$node = $share->getNode(); |
|
|
// if ($node->getType() === 'dir') { TODO } |
|
|
|
|
|
|
|
|
if ($node->getType() === 'dir') { |
|
|
|
|
|
// Is there some reasonable thing to return for a directory? An html index? A tarball? |
|
|
|
|
|
throw new Exception("Requested share is a directory, not a file."); |
|
|
|
|
|
} |
|
|
$content = $node->getContent(); |
|
|
$content = $node->getContent(); |
|
|
$mimetype = $node->getMimeType(); |
|
|
$mimetype = $node->getMimeType(); |
|
|
$this->returnRawResponse($content, $mimetype); |
|
|
$this->returnRawResponse($content, $mimetype); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @PublicPage |
|
|
|
|
|
* @NoAdminRequired |
|
|
|
|
|
* @NoCSRFRequired |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getByTokenAndPath($token, $path) { |
|
|
|
|
|
$share = $this->manager->getShareByToken($token); |
|
|
|
|
|
$dirNode = $share->getNode(); |
|
|
|
|
|
if ($dirNode->getType() !== 'dir') { |
|
|
|
|
|
throw new Exception("Received a sub-path for a share that is not a directory"); |
|
|
|
|
|
} |
|
|
|
|
|
$fileNode = $dirNode->get($path); |
|
|
|
|
|
if ($fileNode->getType() === 'dir') { |
|
|
|
|
|
// Is there some reasonable thing to return for a directory? An html index? A tarball? |
|
|
|
|
|
throw new Exception("Requested share is a directory, not a file."); |
|
|
|
|
|
} |
|
|
|
|
|
$content = $fileNode->getContent(); |
|
|
|
|
|
$mimetype = $fileNode->getMimeType(); |
|
|
|
|
|
$this->returnRawResponse($content, $mimetype); |
|
|
|
|
|
} |
|
|
} |
|
|
} |