summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-09-21 11:37:37 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-09-25 16:18:50 +0200
commit7d8c5f73f551c0d7224bccef6af4b272c124b7e9 (patch)
treed9e1d8d7b7a9444c8abd4b10fe8f73eb79365b7f /apps
parent29fb315ffcbfb910a36b58ca99cdefb1fe531423 (diff)
downloadnextcloud-server-7d8c5f73f551c0d7224bccef6af4b272c124b7e9.tar.gz
nextcloud-server-7d8c5f73f551c0d7224bccef6af4b272c124b7e9.zip
Add direct preview link to single shared image files
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/Controller/PublicPreviewController.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/PublicPreviewController.php b/apps/files_sharing/lib/Controller/PublicPreviewController.php
index 49e48993f5c..b3c1db8e504 100644
--- a/apps/files_sharing/lib/Controller/PublicPreviewController.php
+++ b/apps/files_sharing/lib/Controller/PublicPreviewController.php
@@ -101,4 +101,50 @@ class PublicPreviewController extends Controller {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
}
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ *
+ * @param $token
+ * @return DataResponse|FileDisplayResponse
+ */
+ public function directLink($token) {
+ // No token no image
+ if ($token === '') {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+
+ // No share no image
+ try {
+ $share = $this->shareManager->getShareByToken($token);
+ } catch (ShareNotFound $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ // No permissions no image
+ if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ }
+
+ // Password protected shares have no direct link!
+ if ($share->getPassword() !== null) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ }
+
+ try {
+ $node = $share->getNode();
+ if ($node instanceof Folder) {
+ // Direct link only works for single files
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+
+ $f = $this->previewManager->getPreview($node, -1, -1, false);
+ return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
+ } catch (NotFoundException $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ } catch (\InvalidArgumentException $e) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+ }
}