From 66a475b0c07f9a77422388cf7b3662918f788bfd Mon Sep 17 00:00:00 2001 From: Jacob Noah <138569835+jacob-nv@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:01:26 +0200 Subject: [PATCH] create .space folder if removed (#9793) * create .space folder if removed * space folder check by api, updating drive to refresh readme * bugfix .space folder changelog * creating space config folder in composable * rename createDefaultConfigFolder to createDefaultMetaFolder * useCreateSpace fix --- .../unreleased/bugfix-hidden-space-folder | 6 +++++ .../spaces/useSpaceActionsUploadImage.ts | 14 ++++++++++- .../src/composables/spaces/useCreateSpace.ts | 25 +++++++++++-------- 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 changelog/unreleased/bugfix-hidden-space-folder diff --git a/changelog/unreleased/bugfix-hidden-space-folder b/changelog/unreleased/bugfix-hidden-space-folder new file mode 100644 index 00000000000..455d32c3717 --- /dev/null +++ b/changelog/unreleased/bugfix-hidden-space-folder @@ -0,0 +1,6 @@ +Bugfix: Create .space folder if it does not exist + +Creating .space folder and README.md in space if folder has been removed by user. + +https://github.com/owncloud/web/issues/9788 +https://github.com/owncloud/web/pull/9793 diff --git a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts index 75cf89ff54e..5ce2fe58074 100644 --- a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts +++ b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts @@ -11,6 +11,7 @@ import { import { eventBus } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' import { SpaceAction, SpaceActionOptions } from '@ownclouders/web-pkg' +import { useCreateSpace } from '@ownclouders/web-pkg' export const useSpaceActionsUploadImage = ({ store, @@ -24,6 +25,7 @@ export const useSpaceActionsUploadImage = ({ const clientService = useClientService() const loadingService = useLoadingService() const previewService = usePreviewService() + const { createDefaultMetaFolder } = useCreateSpace() let selectedSpace: SpaceResource = null const handler = ({ resources }: SpaceActionOptions) => { @@ -35,7 +37,7 @@ export const useSpaceActionsUploadImage = ({ unref(spaceImageInput)?.click() } - const uploadImageSpace = (ev) => { + const uploadImageSpace = async (ev) => { const graphClient = clientService.graphAuthenticated const file = ev.currentTarget.files[0] @@ -56,6 +58,16 @@ export const useSpaceActionsUploadImage = ({ extraHeaders['X-OC-Mtime'] = '' + file.lastModified / 1000 } + try { + await clientService.webdav.getFileInfo(selectedSpace, { path: '.space' }) + } catch (_) { + store.commit('runtime/spaces/UPDATE_SPACE_FIELD', { + id: selectedSpace.id, + field: 'spaceReadmeData', + value: (await createDefaultMetaFolder(selectedSpace)).spaceReadmeData + }) + } + return loadingService.addTask(() => { return clientService.webdav .putFileContents(selectedSpace, { diff --git a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts index c80fe9c8665..91c662d6cd9 100644 --- a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts +++ b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts @@ -1,4 +1,4 @@ -import { buildSpace } from '@ownclouders/web-client/src/helpers' +import { buildSpace, SpaceResource } from '@ownclouders/web-client/src/helpers' import { Drive } from '@ownclouders/web-client/src/generated' import { useGettext } from 'vue3-gettext' import { useClientService } from '../clientService' @@ -10,36 +10,39 @@ export const useCreateSpace = () => { const configurationManager = useConfigurationManager() const createSpace = async (name: string) => { - const { graphAuthenticated, webdav } = clientService + const { graphAuthenticated } = clientService const { data: createdSpace } = await graphAuthenticated.drives.createDrive({ name }, {}) const spaceResource = buildSpace({ ...createdSpace, serverUrl: configurationManager.serverUrl }) - await webdav.createFolder(spaceResource, { path: '.space' }) - const markdown = await webdav.putFileContents(spaceResource, { + return await createDefaultMetaFolder(spaceResource) + } + + const createDefaultMetaFolder = async (space: SpaceResource) => { + const { graphAuthenticated, webdav } = clientService + await webdav.createFolder(space, { path: '.space' }) + const file = await webdav.putFileContents(space, { path: '.space/readme.md', content: $gettext('Here you can add a description for this Space.') }) - - const { data: updatedSpace } = await graphAuthenticated.drives.updateDrive( - createdSpace.id, + const { data: updatedDriveData } = await graphAuthenticated.drives.updateDrive( + space.id as string, { special: [ { specialFolder: { name: 'readme' }, - id: markdown.id as string + id: file.id as string } ] } as Drive, {} ) - - return buildSpace({ ...updatedSpace, serverUrl: configurationManager.serverUrl }) + return buildSpace({ ...updatedDriveData, serverUrl: configurationManager.serverUrl }) } - return { createSpace } + return { createSpace, createDefaultMetaFolder } }