Skip to content

Commit

Permalink
fix: use the right url to fetch raw images
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 Jan 17, 2023
1 parent 132f88f commit 14ca32b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
45 changes: 15 additions & 30 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ import ShowImageModal from '../components/ImageView/ShowImageModal.vue'
import store from './../mixins/store.js'
import { useAttachmentResolver } from './../components/Editor.provider.js'
import { mimetypesImages as IMAGE_MIMES } from '../helpers/mime.js'
import { generateDavUrl, xmlResponseToFilesList } from '../helpers/dav.js'
import { generateUrl } from '@nextcloud/router'
import { NodeViewWrapper } from '@tiptap/vue-2'
import { logger } from '../helpers/logger.js'
Expand Down Expand Up @@ -340,36 +339,22 @@ export default {
this.loaded = true
},
handleImageClick(src) {
const data = `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
<d:prop>
<d:getlastmodified />
<d:getetag />
<d:getcontenttype />
<d:resourcetype />
<oc:fileid />
<oc:permissions />
<oc:size />
<d:getcontentlength />
<nc:has-preview />
<oc:favorite />
<oc:comments-unread />
<oc:owner-display-name />
<oc:share-types />
<nc:contained-folder-count />
<nc:contained-file-count />
</d:prop>
</d:propfind>
`
axios({
method: 'PROPFIND',
url: generateDavUrl(src.split('/').shift()),
data,
}).then((response) => {
this.embeddedImagesList = xmlResponseToFilesList(response.data)
this.startImageIndex = this.embeddedImagesList.findIndex(image => image.filename === src)
this.showImageModal = true
const imageViews = Array.from(document.querySelectorAll('div[data-component="image-view"].image-view'))
let basename,
relativePath

imageViews.map(imgv => {
relativePath = imgv.getAttribute('data-src')
basename = relativePath.split('/').slice(-1).join()
const { url: source } = this.$attachmentResolver.resolve(relativePath, true).shift()
this.embeddedImagesList.push({
source,
basename,
relativePath,
})
})
this.startImageIndex = this.embeddedImagesList.findIndex(image => image.relativePath === src)
this.showImageModal = true
},
},
}
Expand Down
9 changes: 5 additions & 4 deletions src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ export default class AttachmentResolver {
/*
* Resolve a given src.
* @param { string } the original src in the node.
* @param { bool } choose to fetch the raw image or a preview | default = false
* @returns { Array<Object> } - resolved candidates to try.
*
* Currently returns either one or two urls.
*/
resolve(src) {
resolve(src, preferRawImage = false) {
if (this.#session && src.startsWith('text://')) {
const imageFileName = getQueryVariable(src, 'imageFileName')
return [{
type: this.ATTACHMENT_TYPE_IMAGE,
url: this.#getImageAttachmentUrl(imageFileName),
url: this.#getImageAttachmentUrl(imageFileName, preferRawImage),
}]
}

Expand All @@ -66,7 +67,7 @@ export default class AttachmentResolver {
return [
{
type: this.ATTACHMENT_TYPE_IMAGE,
url: this.#getImageAttachmentUrl(imageFileName),
url: this.#getImageAttachmentUrl(imageFileName, preferRawImage),
},
{
type: this.ATTACHMENT_TYPE_MEDIA,
Expand Down Expand Up @@ -102,7 +103,7 @@ export default class AttachmentResolver {
},
{
type: this.ATTACHMENT_TYPE_IMAGE,
url: this.#getImageAttachmentUrl(imageFileName),
url: this.#getImageAttachmentUrl(imageFileName, preferRawImage),
},
{
type: this.ATTACHMENT_TYPE_MEDIA,
Expand Down

0 comments on commit 14ca32b

Please sign in to comment.