diff options
author | Azul <azul@riseup.net> | 2021-11-10 18:00:00 +0300 |
---|---|---|
committer | Azul <azul@riseup.net> | 2021-11-11 12:06:12 +0300 |
commit | 72fe3c6cb8f8dabd4efaf67c5c8a94216bdea7f7 (patch) | |
tree | 94a0b24b872aa7db6ab39959e2dd9776024bcd08 /src | |
parent | 04fc4835b8e1d238fda1ecc2cb258f0444233191 (diff) |
fix: handling of preview urls and tests
Preserve urls that start with `core/preview` no matter if `hasPreview` is in there or not.
Also do not add a duplicate `/` in dav urls.
`this.filePath` already starts with a `/`.
Add a test for dav paths and fix some others that were broken by #1800.
Signed-off-by: Azul <azul@riseup.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/nodes/ImageView.vue | 19 | ||||
-rw-r--r-- | src/tests/nodes/ImageView.spec.js | 17 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/nodes/ImageView.vue b/src/nodes/ImageView.vue index f3d230de2..df8f58b60 100644 --- a/src/nodes/ImageView.vue +++ b/src/nodes/ImageView.vue @@ -104,8 +104,8 @@ export default { davUrl() { if (getCurrentUser()) { const uid = getCurrentUser().uid - const encoded = encodeURI(path.normalize(this.filePath)) - return generateRemoteUrl(`dav/files/${uid}/${encoded}`) + const encoded = encodeURI(this.filePath) + return generateRemoteUrl(`dav/files/${uid}${encoded}`) } else { return generateUrl('/s/{token}/download?path={dirname}&files={basename}', { @@ -116,7 +116,7 @@ export default { } }, imageUrl() { - if (this.src.startsWith('http://') || this.src.startsWith('https://')) { + if (this.isRemoteUrl || this.isPreviewUrl) { return this.src } if (this.hasPreview && this.mime !== 'image/gif') { @@ -124,6 +124,14 @@ export default { } return this.davUrl }, + isRemoteUrl() { + return this.src.startsWith('http://') + || this.src.startsWith('https://') + }, + isPreviewUrl() { + return this.src.match(/^(\/index.php)?\/core\/preview/) + || this.src.match(/^(\/index.php)?\/apps\/files_sharing\/publicpreview\//) + }, basename() { return decodeURI(this.src.split('?')[0]) }, @@ -141,11 +149,6 @@ export default { return getQueryVariable(this.src, 'hasPreview') === 'true' }, previewUrl() { - if (this.src.match(/^(\/index.php)?\/core\/preview/) - || this.src.match(/^(\/index.php)?\/apps\/files_sharing\/publicpreview\//) - ) { - return this.src - } const fileQuery = (this.fileId) ? `?fileId=${this.fileId}&file=${encodeURIComponent(this.filePath)}` : `?file=${encodeURIComponent(this.filePath)}` diff --git a/src/tests/nodes/ImageView.spec.js b/src/tests/nodes/ImageView.spec.js index 5c524c4d5..13a0b2456 100644 --- a/src/tests/nodes/ImageView.spec.js +++ b/src/tests/nodes/ImageView.spec.js @@ -36,17 +36,26 @@ describe('Image View src attribute based on markdown', () => { }) test('fileId is used for preview url', () => { - const wrapper = factory({src: '/Media/photo-1498855592392-af2bf1e0a4c7.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true'}) + const src = '/Media/photo.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true' + const wrapper = factory({src}) expect(wrapper.vm.fileId).toBe('7') expect(wrapper.find('.image__main').attributes('src')) - .toBe('/core/preview?fileId=7&x=1024&y=1024&a=true') + .toContain('/core/preview?fileId=7') + }) + + test('use dav paths for gifs so they are animated', () => { + const src = '/Media/giffy.gif?fileId=7#mimetype=image%2Fgif&hasPreview=true' + const wrapper = factory({src}) + expect(wrapper.vm.options.currentDirectory).toBe('/current') + expect(wrapper.find('.image__main').attributes('src')) + .toContain("remote.php/dav/files/user1/current/Media/giffy.gif") }) test('without fileId relative path is used in file based preview url', () => { - const wrapper = factory({src: 'sub/asdf.jpg'}) + const wrapper = factory({src: 'sub/asdf.jpg?hasPreview=true'}) expect(wrapper.vm.isSupportedImage).toBe(true) expect(wrapper.find('.image__main').attributes('src')) - .toBe('/core/preview.png?file=%2Fcurrent%2Fsub%2Fasdf.jpg&x=1024&y=1024&a=true') + .toBe('/core/preview?file=%2Fcurrent%2Fsub%2Fasdf.jpg&x=1024&y=1024&a=true') }) test('public share link previews are just used as they are', () => { |