diff --git a/changelog/unreleased/bugfix-space-special-files b/changelog/unreleased/bugfix-space-special-files new file mode 100644 index 00000000000..b88d2e48084 --- /dev/null +++ b/changelog/unreleased/bugfix-space-special-files @@ -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 diff --git a/packages/web-app-files/src/views/spaces/Project.vue b/packages/web-app-files/src/views/spaces/Project.vue index 3b1e3988ba5..63f6d08ffaa 100644 --- a/packages/web-app-files/src/views/spaces/Project.vue +++ b/packages/web-app-files/src/views/spaces/Project.vue @@ -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({ @@ -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) diff --git a/packages/web-app-files/src/views/spaces/Projects.vue b/packages/web-app-files/src/views/spaces/Projects.vue index f9d3f8ea451..ab4d5919850 100644 --- a/packages/web-app-files/src/views/spaces/Projects.vue +++ b/packages/web-app-files/src/views/spaces/Projects.vue @@ -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({ diff --git a/packages/web-app-files/tests/unit/views/spaces/Project.spec.js b/packages/web-app-files/tests/unit/views/spaces/Project.spec.js index d8191fd9db9..3212866a9b6 100644 --- a/packages/web-app-files/tests/unit/views/spaces/Project.spec.js +++ b/packages/web-app-files/tests/unit/views/spaces/Project.spec.js @@ -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' } } ]