From 2f665d635a77caa9bfd4fa1688bf5c8a753a17e9 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 22 Nov 2023 18:20:15 +0100 Subject: [PATCH] fix(attachments): Open non-image attachments in viewer or download When viewer is available, not in use and supports the mimetype, and we're not in a public share, open the attachment in viewer. Otherwise, download the attachment. Fixes: #3849 Fixes: #4723 Fixes: #5030 Signed-off-by: Jonas --- lib/Service/AttachmentService.php | 7 ++----- src/nodes/ImageView.vue | 29 ++++++++++++++++++++--------- src/services/AttachmentResolver.js | 5 ++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 344c60a39a5..a50ec7b67fe 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -251,17 +251,14 @@ public function getAttachmentList(int $documentId, ?string $userId = null, ?Sess 'mimetype' => $node->getMimeType(), 'mtime' => $node->getMTime(), 'isImage' => $isImage, + 'shareToken' => $shareToken, + 'davPath' => '/' . implode('/', array_slice(explode('/', $node->getPath()), 3)), 'fullUrl' => $isImage ? $this->urlGenerator->linkToRouteAbsolute('text.Attachment.getImageFile') . $urlParamsBase . '&imageFileName=' . urlencode($name) . '&preferRawImage=1' : $this->urlGenerator->linkToRouteAbsolute('text.Attachment.getMediaFile') . $urlParamsBase . '&mediaFileName=' . urlencode($name), 'previewUrl' => $isImage ? $this->urlGenerator->linkToRouteAbsolute('text.Attachment.getImageFile') . $urlParamsBase . '&imageFileName=' . urlencode($name) : $this->urlGenerator->linkToRouteAbsolute('text.Attachment.getMediaFilePreview') . $urlParamsBase . '&mediaFileName=' . urlencode($name), - /* - : ($isImage - ? $this->urlGenerator->linkTo('', 'remote.php') . '/dav/files/' . $userId . '/' . implode('/', array_map('rawurlencode', array_slice(explode('/', $node->getPath()), 3))) - : ''), - */ ]; } diff --git a/src/nodes/ImageView.vue b/src/nodes/ImageView.vue index ff9484876d7..24da8be643a 100644 --- a/src/nodes/ImageView.vue +++ b/src/nodes/ImageView.vue @@ -36,7 +36,7 @@
+ @click="handleAttachmentClick">
(i.isImage && i.fileId === this.attachment.fileId)) if (this.imageIndex !== -1) { diff --git a/src/services/AttachmentResolver.js b/src/services/AttachmentResolver.js index 85d5513d71a..704422b2e2d 100644 --- a/src/services/AttachmentResolver.js +++ b/src/services/AttachmentResolver.js @@ -76,7 +76,10 @@ export default class AttachmentResolver { attachment = findAttachment(imageFileName) } - return attachment + if (attachment) { + return attachment + } + } // Direct URLs