Skip to content

Commit

Permalink
fix: Add fallback values for reading editors relative path
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Dec 30, 2022
1 parent bfcddd9 commit 9943ce5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
},
computed: {
initialFilePath() {
return this.lastFilePath ?? getDir(this.$file.relativePath)
return this.lastFilePath ?? getDir(this.$file?.relativePath ?? '/')
},
},
methods: {
Expand Down
7 changes: 5 additions & 2 deletions src/components/Menu/ActionInsertLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export default {
activeClass() {
return this.state.active ? 'is-active' : ''
},
relativePath() {
return this.$file?.relativePath ?? '/'
},
},
methods: {
/**
Expand All @@ -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(
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9943ce5

Please sign in to comment.