Skip to content

Commit

Permalink
create .space folder if removed (#9793)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jacob-nv authored and AlexAndBear committed Dec 13, 2023
1 parent 82c2eff commit 66a475b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
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 }
}

0 comments on commit 66a475b

Please sign in to comment.