Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create .space folder if removed #9793

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-hidden-space-folder
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -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]

Expand All @@ -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, {
Expand Down
25 changes: 14 additions & 11 deletions packages/web-pkg/src/composables/spaces/useCreateSpace.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 }
}