Skip to content

Commit

Permalink
chore(attachments): Remove special-handling for preview URLs
Browse files Browse the repository at this point in the history
We don't remember a legitimate reason why they would end up in a text
document. Probably something that predate the attachments directory
era.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Dec 5, 2023
1 parent 411b456 commit c710cf3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
30 changes: 2 additions & 28 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,6 @@ import { emit } from '@nextcloud/event-bus'
import { NodeViewWrapper } from '@tiptap/vue-2'
import { Image as ImageIcon, Delete as DeleteIcon } from '../components/icons.js'
/*
const getQueryVariable = (src, variable) => {
const query = src.split('?')[1]
if (typeof query === 'undefined') {
return
}
const vars = query.split(/[&#]/)
if (typeof vars === 'undefined') {
return
}
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (decodeURIComponent(pair[0]) === variable) {
return decodeURIComponent(pair[1])
}
}
}
*/
class LoadImageError extends Error {
constructor(reason, imageUrl) {
Expand Down Expand Up @@ -219,12 +200,9 @@ export default {
return this.loaded && this.imageLoaded
},
/*
imageFileId() {
return getQueryVariable(this.src, 'fileId')
},
internalLinkOrImage() {
if (this.imageFileId) {
return generateUrl('/f/' + this.imageFileId)
if (this.attachment.fileId) {
return generateUrl('/f/' + this.attachment.fileId)
}
return this.src
},
Expand All @@ -249,10 +227,6 @@ export default {
})
},
},
token() {
return document.getElementById('sharingToken')
&& document.getElementById('sharingToken').value
},
},
beforeMount() {
this.isEditable = this.editor.isEditable
Expand Down
11 changes: 4 additions & 7 deletions src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class AttachmentResolver {
return attachment
}

// Direct URLs
if (isDirectUrl(src)) {
return {
isImage: true,
Expand All @@ -87,7 +88,7 @@ export default class AttachmentResolver {
}
}

// Fallback: Return DAV url
// Fallback: Return DAV url (e.g. for relative paths to images)
return {
isImage: true,
previewUrl: this.#davUrl(src),
Expand Down Expand Up @@ -134,17 +135,13 @@ export default class AttachmentResolver {
}

/**
* Check if a url can be loaded directly - i.e. is one of
* - remote url
* - data url
* - preview url
* Check if src is a direct URL.
* Full URLs only work for images on the same Nextcloud instance (due to CORS restrictions).
*
* @param {string} src - the url to check
*/
function isDirectUrl(src) {
return src.startsWith('http://')
|| src.startsWith('https://')
|| src.startsWith('data:')
|| src.match(/^(\/index.php)?\/core\/preview/)
|| src.match(/^(\/index.php)?\/apps\/files_sharing\/publicpreview\//)
}

0 comments on commit c710cf3

Please sign in to comment.