Skip to content

Commit

Permalink
fix(attachments): Open non-image attachments in viewer or download
Browse files Browse the repository at this point in the history
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 <jonas@freesources.org>
  • Loading branch information
mejo- committed Nov 28, 2023
1 parent 8386f89 commit b22167e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
7 changes: 2 additions & 5 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
: ''),
*/
];
}

Expand Down
29 changes: 20 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,25 @@ export default {
onLoaded() {
this.loaded = true
},
async handleAttachmentClick() {
// Open in viewer if possible
if (OCA.Viewer
// Viewer is not in use
&& !OCA.Viewer.file
// Viewer supports mimetype
&& OCA.Viewer.mimetypes.indexOf(this.attachment.mimetype) !== -1
// Attachment has davPath (i.e. is native attachment)
&& this.attachment.davPath
// Not in share (in public share we probably don't have DAV access)
&& !this.attachment.shareToken) {
// 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 b22167e

Please sign in to comment.