Skip to content

Commit

Permalink
fix: open non-image attachment
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Mar 27, 2023
1 parent 43ad16c commit 0d1ccb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default {
const src = dirname + '/'
+ encodeURIComponent(name).replace(/[!'()*]/g, (c) => {
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
})
}) + '?fileId=' + fileId + '&mimeType=' + encodeURIComponent(mimeType)
// simply get rid of brackets to make sure link text is valid
// as it does not need to be unique and matching the real file name
const alt = name.replaceAll(/[[\]]/g, '')
Expand Down
55 changes: 26 additions & 29 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@
<transition name="fade">
<template v-if="!failed">
<div v-if="isMediaAttachment"
class="media"
@click="handleImageClick(src)">
class="media">
<div class="media__wrapper">
<img v-show="loaded"
:src="imageUrl"
class="image__main"
@load="onLoaded">
<div class="metadata">
<span class="name">{{ alt }}</span>
<span class="size">{{ attachmentMetadata.size }}</span>
</div>
<a :href="internalLinkOrImage"
target="_blank">
<img v-show="loaded"
:src="imageUrl"
class="image__main"
@load="onLoaded">
<div class="metadata">
<span class="name">{{ alt }}</span>
<span class="size">{{ attachmentMetadata.size }}</span>
</div>
</a>
</div>
<div v-if="showDeleteIcon"
class="buttons">
Expand Down Expand Up @@ -215,26 +217,19 @@ export default {
return this.showDeleteIcon && !this.isMediaAttachment
},
canDisplayImage() {
if (!this.isSupportedImage) {
return false
}

if (this.failed && this.loaded) {
return true
}

return this.loaded && this.imageLoaded
},
imageFileId() {
return getQueryVariable(this.src, 'fileId')
},
isSupportedImage() {
return typeof this.mime === 'undefined'
|| IMAGE_MIMES.indexOf(this.mime) !== -1
return typeof this.mimeType === 'undefined'
|| IMAGE_MIMES.indexOf(this.mimeType) !== -1
},
internalLinkOrImage() {
if (this.imageFileId) {
return generateUrl('/f/' + this.imageFileId)
if (this.fileId) {
return generateUrl('/apps/files/f/' + this.fileId)
}
return this.src
},
Expand All @@ -258,6 +253,12 @@ export default {
})
},
},
fileId() {
return getQueryVariable(this.src, 'fileId')
},
mimeType() {
return getQueryVariable(this.src, 'mimeType')
},
t() {
return (a, s) => window.t(a, s)
},
Expand All @@ -267,14 +268,6 @@ export default {
},
},
beforeMount() {
if (!this.isSupportedImage) {
// TODO check if hasPreview and render a file preview if available
this.failed = true
this.imageLoaded = false
this.loaded = true
this.errorMessage = t('text', 'Unsupported image type')
return
}
this.init()
.catch(this.onImageLoadFailure)
},
Expand Down Expand Up @@ -464,6 +457,10 @@ export default {
border-radius: var(--border-radius-large);
padding: 8px;

a {
display: contents;
}

img {
width: 44px;
height: 44px;
Expand Down

0 comments on commit 0d1ccb5

Please sign in to comment.