Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derpgon cz fix/stable23/image data urls #2210

Merged
merged 3 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default {
}
},
imageUrl() {
if (this.isRemoteUrl || this.isPreviewUrl) {
if (this.isRemoteUrl || this.isPreviewUrl || this.isDataUrl) {
return this.src
}
if (this.hasPreview && this.mime !== 'image/gif') {
Expand All @@ -132,6 +132,9 @@ export default {
return this.src.match(/^(\/index.php)?\/core\/preview/)
|| this.src.match(/^(\/index.php)?\/apps\/files_sharing\/publicpreview\//)
},
isDataUrl() {
return this.src.startsWith('data:')
},
basename() {
return decodeURI(this.src.split('?')[0])
},
Expand Down Expand Up @@ -218,7 +221,6 @@ export default {
return
}
const img = new Image()
img.src = this.imageUrl
img.onload = () => {
this.imageLoaded = true
}
Expand All @@ -227,6 +229,7 @@ export default {
this.imageLoaded = false
this.loaded = true
}
img.src = this.imageUrl
},
methods: {
updateAlt() {
Expand Down
6 changes: 6 additions & 0 deletions src/tests/nodes/ImageView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ describe('Image View src attribute based on markdown', () => {
expect(wrapper.find('.image__main').attributes('src'))
.toBe('https://nextcloud/index.php/apps/files_sharing/publicpreview/CSYoWifBzrsMWeA?file=/deck11-calendar.png&x=1760&y=990&a=true')
})

test('data urls are used as is', () => {
const src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='
const wrapper = factory({src})
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
})
})