PubPageController.php 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace OCA\Raw\Controller;
  3. use \Exception;
  4. use OCP\IRequest;
  5. use OCP\Share\IManager;
  6. use OCP\AppFramework\Controller;
  7. use OCP\AppFramework\Http\NotFoundResponse;
  8. use OCP\Files\NotFoundException;
  9. class PubPageController extends Controller {
  10. use RawResponse;
  11. private $shareManager;
  12. public function __construct(
  13. $AppName,
  14. IRequest $request,
  15. IManager $shareManager
  16. ) {
  17. parent::__construct($AppName, $request);
  18. $this->shareManager = $shareManager;
  19. }
  20. /**
  21. * @PublicPage
  22. * @NoAdminRequired
  23. * @NoCSRFRequired
  24. */
  25. public function getByToken($token) {
  26. $share = $this->shareManager->getShareByToken($token);
  27. $node = $share->getNode();
  28. $this->returnRawResponse($node);
  29. }
  30. /**
  31. * @PublicPage
  32. * @NoAdminRequired
  33. * @NoCSRFRequired
  34. */
  35. public function getByTokenAndPath($token, $path) {
  36. $share = $this->shareManager->getShareByToken($token);
  37. $dirNode = $share->getNode();
  38. if ($dirNode->getType() !== 'dir') {
  39. throw new Exception("Received a sub-path for a share that is not a directory");
  40. }
  41. try {
  42. $fileNode = $dirNode->get($path);
  43. } catch (NotFoundException $e) {
  44. return new NotFoundResponse();
  45. }
  46. $this->returnRawResponse($fileNode);
  47. }
  48. }