Skip to content

Commit

Permalink
fix(attachments): Open non-image attachments in viewer/new tab
Browse files Browse the repository at this point in the history
When viewer is available, not in use and supports the mimetype, let's
open the attachment in viewer. Otherwise, open the file app URL in
a new tab.

Fixes: #3849, #4723

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Nov 27, 2023
1 parent 210e458 commit d2dfb69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 1 addition & 5 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,13 @@ public function getAttachmentList(int $documentId, ?string $userId = null, ?Sess
'mimetype' => $node->getMimeType(),
'mtime' => $node->getMTime(),
'isImage' => $isImage,
'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)))
: ''),
*/
];
}

Expand Down
21 changes: 12 additions & 9 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div v-if="isMediaAttachment"
contenteditable="false"
class="media"
@click="handleImageClick">
@click="handleAttachmentClick">
<div class="media__wrapper">
<img v-show="loaded"
:src="imageUrl"
Expand Down Expand Up @@ -201,14 +201,6 @@ export default {

return this.loaded && this.imageLoaded
},
/*
internalLinkOrImage() {
if (this.attachment.fileId) {
return generateUrl('/f/' + this.attachment.fileId)
}
return this.src
},
*/
src: {
get() {
return this.node.attrs.src || ''
Expand Down Expand Up @@ -277,6 +269,17 @@ export default {
onLoaded() {
this.loaded = true
},
async handleAttachmentClick() {
// Open in viewer
if (OCA.Viewer && !OCA.Viewer.file && OCA.Viewer.mimetypes.indexOf(this.attachment.mimetype) !== -1 && this.attachment.davPath) {
// Viewer exists, is not in use and supports mimetype
OCA.Viewer.open({ path: this.attachment.davPath })
return
}

// Download file
window.location.assign(this.attachment.fullUrl)
},
async handleImageClick() {
this.imageIndex = this.imageAttachments.findIndex(i => (i.isImage && i.fileId === this.attachment.fileId))
if (this.imageIndex !== -1) {
Expand Down
5 changes: 4 additions & 1 deletion src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export default class AttachmentResolver {
attachment = findAttachment(imageFileName)
}

return attachment
if (attachment) {
return attachment
}

}

// Direct URLs
Expand Down

0 comments on commit d2dfb69

Please sign in to comment.