diff options
author | Vincent Petry <vincent@nextcloud.com> | 2020-10-26 22:58:58 +0300 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2020-10-28 18:59:35 +0300 |
commit | 549d8902c6b86e80162a9fddb00fa03e66e6417b (patch) | |
tree | b9d720ee83d03aabe6cb638c68f6382235fd363a /src | |
parent | 805b1cfc93cfc60247a26fcbece61ffe6804cb61 (diff) |
Direct preview for GIFs + guest mode previews
Use direct URL for small GIFS.
Added preview support for guest mode.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue index a8e2a9045..7364ae4fe 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue @@ -51,7 +51,7 @@ </template> <script> -import { generateUrl, imagePath } from '@nextcloud/router' +import { generateUrl, imagePath, generateRemoteUrl } from '@nextcloud/router' import ProgressBar from '@nextcloud/vue/dist/Components/ProgressBar' import Close from 'vue-material-design-icons/Close' @@ -80,6 +80,10 @@ export default { type: String, default: '', }, + size: { + type: Number, + default: -1, + }, link: { type: String, default: '', @@ -154,20 +158,42 @@ export default { return 'preview' }, previewUrl() { + const userId = this.$store.getters.getUserId() if (this.hasTemporaryImageUrl) { return this.localUrl } - if (this.previewAvailable !== 'yes' || this.$store.getters.getUserId() === null) { + if (this.previewAvailable !== 'yes') { return OC.MimeType.getIconUrl(this.mimetype) } + // TODO: make this maximum configurable + if (this.mimetype === 'image/gif' && this.size <= 3145728) { + // return direct image so it can be animated + if (userId === null) { + // guest mode, use public link download URL + return this.link + '/download/' + this.name + } else { + // use direct DAV URL + return generateRemoteUrl(`dav/files/${userId}`) + this.internalAbsolutePath + } + } + const previewSize = Math.ceil(this.previewSize * window.devicePixelRatio) - // expand width but keep a max height - return generateUrl('/core/preview?fileId={fileId}&x=-1&y={height}&a=1', { - fileId: this.id, - height: previewSize, - }) + if (userId === null) { + // guest mode: grab token from the link URL + // FIXME: use a cleaner way... + const token = this.link.substr(this.link.lastIndexOf('/') + 1) + return generateUrl('/apps/files_sharing/publicpreview/{token}?x=-1&y={height}&a=1', { + token: token, + height: previewSize, + }) + } else { + return generateUrl('/core/preview?fileId={fileId}&x=-1&y={height}&a=1', { + fileId: this.id, + height: previewSize, + }) + } }, isViewerAvailable() { if (!OCA.Viewer) { |