From 9943ce5b426a9342f8a0e79abd0c4a584ebf70d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 30 Dec 2022 12:15:10 +0100 Subject: [PATCH] fix: Add fallback values for reading editors relative path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/Editor/MediaHandler.vue | 2 +- src/components/Menu/ActionInsertLink.vue | 7 +++++-- src/helpers/links.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Editor/MediaHandler.vue b/src/components/Editor/MediaHandler.vue index 2d7c251eba1..3c324ab3ecb 100644 --- a/src/components/Editor/MediaHandler.vue +++ b/src/components/Editor/MediaHandler.vue @@ -91,7 +91,7 @@ export default { }, computed: { initialFilePath() { - return this.lastFilePath ?? getDir(this.$file.relativePath) + return this.lastFilePath ?? getDir(this.$file?.relativePath ?? '/') }, }, methods: { diff --git a/src/components/Menu/ActionInsertLink.vue b/src/components/Menu/ActionInsertLink.vue index 50e19a34f8c..5beb5428da3 100644 --- a/src/components/Menu/ActionInsertLink.vue +++ b/src/components/Menu/ActionInsertLink.vue @@ -109,6 +109,9 @@ export default { activeClass() { return this.state.active ? 'is-active' : '' }, + relativePath() { + return this.$file?.relativePath ?? '/' + }, }, methods: { /** @@ -117,7 +120,7 @@ export default { */ linkFile() { if (this.startPath === null) { - this.startPath = this.$file.relativePath.split('/').slice(0, -1).join('/') + this.startPath = this.relativePath.split('/').slice(0, -1).join('/') } const filePicker = new FilePicker( @@ -133,7 +136,7 @@ export default { filePicker.pick().then((file) => { const client = OC.Files.getClient() client.getFileInfo(file).then((_status, fileInfo) => { - const path = optimalPath(this.$file.relativePath, `${fileInfo.path}/${fileInfo.name}`) + const path = optimalPath(this.relativePath, `${fileInfo.path}/${fileInfo.name}`) const encodedPath = path.split('/').map(encodeURIComponent).join('/') + (fileInfo.type === 'dir' ? '/' : '') const href = `${encodedPath}?fileId=${fileInfo.id}` this.setLink(href, fileInfo.name) diff --git a/src/helpers/links.js b/src/helpers/links.js index 6c02f18cb89..776b8316e1d 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -65,7 +65,7 @@ const domHref = function(node, relativePath) { const match = ref.match(/^([^?]*)\?fileId=(\d+)/) if (match) { const [, relPath, id] = match - const currentDir = basedir(relativePath || OCA.Viewer.file) + const currentDir = basedir(relativePath || OCA.Viewer?.file || '/') const dir = absolutePath(currentDir, basedir(relPath)) if (relPath.length > 1 && relPath.endsWith('/')) { // is directory