PrivatePageController.php 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace OCA\Raw\Controller;
  3. use OCP\IRequest;
  4. use OCP\IServerContainer;
  5. use OCP\AppFramework\Http\NotFoundResponse;
  6. use OCP\AppFramework\Controller;
  7. use OCP\Files\Folder;
  8. use OCP\Files\NotFoundException;
  9. class PrivatePageController extends Controller {
  10. use RawResponse;
  11. private $userFolder;
  12. public function __construct(
  13. $AppName,
  14. $UserId,
  15. IRequest $request,
  16. IServerContainer $serverContainer
  17. ) {
  18. parent::__construct($AppName, $request);
  19. $this->userFolder = $serverContainer->getUserFolder($UserId);
  20. }
  21. /**
  22. * @NoAdminRequired
  23. * @NoCSRFRequired
  24. */
  25. public function getByPath($path) {
  26. if (!$this->userFolder) {
  27. return new NotFoundResponse();
  28. }
  29. try {
  30. $node = $this->userFolder->get($path);
  31. } catch (NotFoundException $e) {
  32. return new NotFoundResponse();
  33. }
  34. $content = $node->getContent();
  35. $mimetype = $node->getMimeType();
  36. $this->returnRawResponse($content, $mimetype);
  37. }
  38. }