Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e903edf
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
8682d60
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
75ec895
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
264aa76
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
2f78829
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
b288c85
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
13cea83
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
d8842a6
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
0bc3556
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
0f2b874
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
9b9e876
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
d95d6b2
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
337724d
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
7a32d8e
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
597b8d5
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
98a47c3
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
adf5fe8
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
88c8810
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
6864890
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
6a46001
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
e632d72
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
b3be90a
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
e391298
reactor(ImageView): Simplify attachmentType/isMediaAttachment logic
mejo- Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
mejo- authored and backportbot-nextcloud[bot] committed Nov 29, 2023
commit d95d6b2cc5b4917c3af95e335055cff2246ca726
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