diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-05-23 10:50:44 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-20 08:53:37 +0200 |
commit | 366981fba6d01167c1ac38f559bd611062d8e534 (patch) | |
tree | 0025a9def17d24615e4cfa6f512870aa6d6b59fb /apps/files_sharing/lib/Controller/PublicPreviewController.php | |
parent | 53a1b9a84e452bebfc701c93f32f44aefea87a2f (diff) | |
download | nextcloud-server-366981fba6d01167c1ac38f559bd611062d8e534.tar.gz nextcloud-server-366981fba6d01167c1ac38f559bd611062d8e534.zip |
Move public preview endpoint over
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/lib/Controller/PublicPreviewController.php')
-rw-r--r-- | apps/files_sharing/lib/Controller/PublicPreviewController.php | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/Controller/PublicPreviewController.php b/apps/files_sharing/lib/Controller/PublicPreviewController.php index 0870995fc7b..b13c0a64b0e 100644 --- a/apps/files_sharing/lib/Controller/PublicPreviewController.php +++ b/apps/files_sharing/lib/Controller/PublicPreviewController.php @@ -27,15 +27,18 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\AppFramework\PublicShareController; use OCP\Constants; use OCP\Files\Folder; use OCP\Files\NotFoundException; use OCP\IPreview; use OCP\IRequest; +use OCP\ISession; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager as ShareManager; +use OCP\Share\IShare; -class PublicPreviewController extends Controller { +class PublicPreviewController extends PublicShareController { /** @var ShareManager */ private $shareManager; @@ -43,16 +46,38 @@ class PublicPreviewController extends Controller { /** @var IPreview */ private $previewManager; - public function __construct($appName, + /** @var IShare */ + private $share; + + public function __construct(string $appName, IRequest $request, ShareManager $shareManger, + ISession $session, IPreview $previewManager) { - parent::__construct($appName, $request); + parent::__construct($appName, $request, $session); $this->shareManager = $shareManger; $this->previewManager = $previewManager; } + protected function getPasswordHash(): string { + return $this->share->getPassword(); + } + + public function isValidToken(): bool { + try { + $this->share = $this->shareManager->getShareByToken($this->getToken()); + return true; + } catch (ShareNotFound $e) { + return false; + } + } + + protected function isPasswordProtected(): bool { + return $this->share->getPassword() !== null; + } + + /** * @PublicPage * @NoCSRFRequired @@ -60,24 +85,23 @@ class PublicPreviewController extends Controller { * @param string $file * @param int $x * @param int $y - * @param string $t * @param bool $a * @return DataResponse|FileDisplayResponse */ public function getPreview( - $file = '', - $x = 32, - $y = 32, - $t = '', + string $token, + string $file = '', + int $x = 32, + int $y = 32, $a = false ) { - if ($t === '' || $x === 0 || $y === 0) { + if ($token === '' || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } try { - $share = $this->shareManager->getShareByToken($t); + $share = $this->shareManager->getShareByToken($token); } catch (ShareNotFound $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } |