Skip to content

Commit

Permalink
Fix webDavPath construction for space image and readme (#7017)
Browse files Browse the repository at this point in the history
Fix webDavPath construction for space image and readme

Needs to be a prefix match since the URL has the spaceId as nodeId in
the URL (uniform 3-part id syntax) but the space id we maintain
internally is 2-part.
  • Loading branch information
kulmann authored May 20, 2022
1 parent 1f2108f commit 9b15875
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/bugfix-space-special-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Cover image and readme in spaces

The URL construction for cover image and readme of a space was wrong and led to both not being shown. This has been fixed by making the URL construction more reliable regarding different ID formats.

https://github.com/owncloud/web/pull/7017
20 changes: 15 additions & 5 deletions packages/web-app-files/src/views/spaces/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,20 @@ export default defineComponent({
},
'space.spaceImageData': {
handler: function (val) {
if (!val) return
if (!val) {
return
}
const webDavPathComponents = this.space.spaceImageData.webDavUrl.split('/')
const idComponent = webDavPathComponents.find((c) => c.startsWith(this.space.id))
if (!idComponent) {
return
}
const path = webDavPathComponents
.slice(webDavPathComponents.indexOf(this.space.id) + 1)
.slice(webDavPathComponents.indexOf(idComponent) + 1)
.join('/')
this.$client.files
.fileInfo(buildWebDavSpacesPath(this.space.id, decodeURIComponent(path)))
.fileInfo(buildWebDavSpacesPath(idComponent, decodeURIComponent(path)))
.then((data) => {
const resource = buildResource(data)
loadPreview({
Expand All @@ -289,12 +295,16 @@ export default defineComponent({
return
}
const webDavPathComponents = this.space.spaceReadmeData.webDavUrl.split('/')
const idComponent = webDavPathComponents.find((c) => c.startsWith(this.space.id))
if (!idComponent) {
return
}
const path = webDavPathComponents
.slice(webDavPathComponents.indexOf(this.space.id) + 1)
.slice(webDavPathComponents.indexOf(idComponent) + 1)
.join('/')
this.$client.files
.getFileContents(buildWebDavSpacesPath(this.space.id, decodeURIComponent(path)))
.getFileContents(buildWebDavSpacesPath(idComponent, decodeURIComponent(path)))
.then((fileContents) => {
if (this.markdownResizeObserver && this.$refs.markdownContainer) {
this.markdownResizeObserver.unobserve(this.$refs.markdownContainer)
Expand Down
8 changes: 6 additions & 2 deletions packages/web-app-files/src/views/spaces/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,16 @@ export default defineComponent({
}
const webDavPathComponents = space.spaceImageData.webDavUrl.split('/')
const idComponent = webDavPathComponents.find((c) => c.startsWith(space.id))
if (!idComponent) {
return
}
const path = webDavPathComponents
.slice(webDavPathComponents.indexOf(space.id) + 1)
.slice(webDavPathComponents.indexOf(idComponent) + 1)
.join('/')
this.$client.files
.fileInfo(buildWebDavSpacesPath(space.id, decodeURIComponent(path)))
.fileInfo(buildWebDavSpacesPath(idComponent, decodeURIComponent(path)))
.then((fileInfo) => {
const resource = buildResource(fileInfo)
loadPreview({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ const spaceMocks = {
special: [
{
specialFolder: { name: 'readme' },
webDavUrl: '/',
webDavUrl: 'https://owncloud.test/dav/spaces/1/readme.md',
file: { mimeType: 'text/plain' }
},
{
specialFolder: { name: 'image' },
webDavUrl: '/',
webDavUrl: 'https://owncloud.test/dav/spaces/1/image.png',
file: { mimeType: 'image/png' }
}
]
Expand Down

0 comments on commit 9b15875

Please sign in to comment.