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

[wip] id-based webdav requests #11180

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions packages/web-app-external/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export default defineWebApplication({
throw new Error(`An error has occurred: ${response.status}`)
}

const path = join(currentFolder.path, fileName) || ''
return clientService.webdav.getFileInfo(space, { path })
const fileId = response.data['file_id']
return clientService.webdav.getFileInfo(space, { fileId })
}
}
})
Expand Down
6 changes: 2 additions & 4 deletions packages/web-app-files/src/HandleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as uuid from 'uuid'
import { Language } from 'vue3-gettext'
import { Ref, unref } from 'vue'
import { RouteLocationNormalizedLoaded } from 'vue-router'
import { SpaceResource } from '@ownclouders/web-client'
import { extractNodeId, SpaceResource } from '@ownclouders/web-client'
import { urlJoin } from '@ownclouders/web-client'
import { UploadResourceConflict } from './helpers/resource'
import {
Expand Down Expand Up @@ -142,9 +142,7 @@ export class HandleUpload extends BasePlugin {
topLevelFolderId = topLevelFolderIds[topLevelDirectory]
}

const webDavUrl = unref(this.space).getWebDavUrl({
path: currentFolderPath.split('/').map(encodeURIComponent).join('/')
})
const webDavUrl = unref(this.space).getWebDavUrl(currentFolderId)

let endpoint = urlJoin(webDavUrl, directory.split('/').map(encodeURIComponent).join('/'))
if (!this.uppy.getPlugin('Tus')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default defineComponent({
const sharedAncestor = computed(() => {
return Object.values(unref(ancestorMetaData)).find(
(a) =>
a.path !== unref(resource).path &&
a.id !== unref(resource).id &&
ShareTypes.containsAnyValue(ShareTypes.authenticated, a.shareTypes)
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/components/Spaces/SpaceHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ export default defineComponent({
}

const fileContentsResponse = await getFileContents(props.space, {
path: `.space/${props.space.spaceReadmeData.name}`
fileId: props.space.spaceReadmeData.id
})

const fileInfoResponse = await getFileInfo(props.space, {
path: `.space/${props.space.spaceReadmeData.name}`
fileId: props.space.spaceReadmeData.id
})

unobserveMarkdownContainerResize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
usePreviewService,
useUserStore,
useMessages,
useSpacesStore
useSpacesStore,
useSpaceHelpers
} from '@ownclouders/web-pkg'
import { eventBus } from '@ownclouders/web-pkg'
import { useGettext } from 'vue3-gettext'
Expand All @@ -24,6 +25,7 @@ export const useSpaceActionsUploadImage = ({ spaceImageInput }: { spaceImageInpu
const previewService = usePreviewService()
const spacesStore = useSpacesStore()
const { createDefaultMetaFolder } = useCreateSpace()
const { getDefaultMetaFolder } = useSpaceHelpers()

let selectedSpace: SpaceResource = null
const handler = ({ resources }: SpaceActionOptions) => {
Expand All @@ -47,10 +49,9 @@ export const useSpaceActionsUploadImage = ({ spaceImageInput }: { spaceImageInpu
return showErrorMessage({ title: $gettext('The file type is unsupported') })
}

try {
await clientService.webdav.getFileInfo(selectedSpace, { path: '.space' })
} catch (_) {
await createDefaultMetaFolder(selectedSpace)
let metaFolder = await getDefaultMetaFolder(selectedSpace)
if (!metaFolder) {
metaFolder = await createDefaultMetaFolder(selectedSpace, metaFolder.id)
}

return loadingService.addTask(async () => {
Expand All @@ -69,7 +70,8 @@ export const useSpaceActionsUploadImage = ({ spaceImageInput }: { spaceImageInpu

try {
const { fileId } = await clientService.webdav.putFileContents(selectedSpace, {
path: `/.space/${file.name}`,
fileId: metaFolder.id,
fileName: file.name,
content,
headers,
overwrite: true
Expand Down
16 changes: 13 additions & 3 deletions packages/web-app-files/src/services/folder/loaderSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
isPersonalSpaceResource,
isPublicSpaceResource,
isShareSpaceResource,
SpaceResource
SpaceResource,
urlJoin
} from '@ownclouders/web-client'
import { unref } from 'vue'
import { FolderLoaderOptions } from './types'
import { authService } from 'web-runtime/src/services/auth'
import { useFileRouteReplace } from '@ownclouders/web-pkg'
import { IncomingShareResource } from '@ownclouders/web-client'
import { getIndicators } from '@ownclouders/web-pkg'
import { getIndicators, useResourcePath } from '@ownclouders/web-pkg'

export class FolderLoaderSpace implements FolderLoader {
public isEnabled(): boolean {
Expand All @@ -36,6 +37,7 @@ export class FolderLoaderSpace implements FolderLoader {
const { router, clientService, resourcesStore, userStore } = context
const { webdav } = clientService
const { replaceInvalidFileRoute } = useFileRouteReplace({ router })
const { getResourcePath } = useResourcePath({ router })

return useTask(function* (
signal1,
Expand Down Expand Up @@ -68,7 +70,7 @@ export class FolderLoaderSpace implements FolderLoader {
} as IncomingShareResource
} else if (!isPersonalSpaceResource(space) && !isPublicSpaceResource(space)) {
// note: in the future we might want to show the space as root for personal spaces as well (to show quota and the like). Currently not needed.
currentFolder = space
currentFolder = { ...space, parentFolderId: currentFolder.parentFolderId }
}
}

Expand All @@ -91,6 +93,14 @@ export class FolderLoaderSpace implements FolderLoader {
resources.forEach((r) => (r.remoteItemId = space.id))
}

/**
* Inject full paths into the resources since id-based requests return no path.
* This currently acts as a fall-back because some webdav operations still require
* to work with full paths. Ideally we remove this or only use it where needed.
**/
currentFolder.path = getResourcePath(space, currentFolder)
resources.forEach((r) => (r.path = urlJoin(currentFolder.path, r.name)))

resourcesStore.initResourceList({ currentFolder, resources })
} catch (error) {
resourcesStore.setCurrentFolder(null)
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/views/spaces/DriveResolver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default defineComponent({
if (internalSpace) {
const resource = await clientService.webdav.getFileInfo(
internalSpace,
{ path },
{ fileId: unref(fileId) },
{ headers: { Authorization: `Bearer ${authStore.accessToken}` } }
)

Expand Down
31 changes: 23 additions & 8 deletions packages/web-app-files/src/views/spaces/GenericSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import {
} from 'vue'
import { RouteLocationNamedRaw } from 'vue-router'
import { useGettext } from 'vue3-gettext'
import { Resource } from '@ownclouders/web-client'
import { Resource, urlJoin } from '@ownclouders/web-client'
import {
isPersonalSpaceResource,
isProjectSpaceResource,
Expand Down Expand Up @@ -266,8 +266,13 @@ export default defineComponent({

const resourcesStore = useResourcesStore()
const { removeResources, resetSelection, updateResourceField } = resourcesStore
const { currentFolder, totalResourcesCount, totalResourcesSize, areHiddenFilesShown } =
storeToRefs(resourcesStore)
const {
currentFolder,
totalResourcesCount,
totalResourcesSize,
areHiddenFilesShown,
ancestorMetaData
} = storeToRefs(resourcesStore)

let loadResourcesEventToken: string

Expand All @@ -285,10 +290,15 @@ export default defineComponent({
})

const resourceTargetRouteCallback = ({
path,
fileId
fileId,
resource
}: CreateTargetRouteOptions): RouteLocationNamedRaw => {
const { params, query } = createFileRouteOptions(unref(space), { path, fileId })
const latest = Object.values(unref(ancestorMetaData))?.pop()
const { params, query } = createFileRouteOptions(unref(space), {
path: urlJoin(latest?.path || '', resource.name),
fileId
})

if (isPublicSpaceResource(unref(space))) {
return createLocationPublic('files-public-link', { params, query })
}
Expand Down Expand Up @@ -392,8 +402,12 @@ export default defineComponent({
return concatBreadcrumbs(
...rootBreadcrumbItems,
spaceBreadcrumbItem,
// FIXME: needs file ids for each parent folder path
...breadcrumbsFromPath({ route: unref(route), space, resourcePath: props.item })
...breadcrumbsFromPath({
route: unref(route),
space,
resourcePath: props.item,
ancestorMetaData
})
)
})

Expand Down Expand Up @@ -554,6 +568,7 @@ export default defineComponent({
const path = decodeURIComponent(fileTarget.path.slice(splitIndex, fileTarget.path.length))

try {
// we only have path info here because that comes from the breadcrumb
targetFolder = await clientService.webdav.getFileInfo(unref(space), { path })
} catch (e) {
console.error(e)
Expand Down
11 changes: 8 additions & 3 deletions packages/web-app-preview/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ import {
sortHelper,
useRoute,
useRouteQuery,
useRouter
useRouter,
useResourcePath
} from '@ownclouders/web-pkg'
import { createFileRouteOptions } from '@ownclouders/web-pkg'
import MediaControls from './components/MediaControls.vue'
Expand Down Expand Up @@ -127,6 +128,7 @@ export default defineComponent({
const router = useRouter()
const route = useRoute()
const appsStore = useAppsStore()
const { getResourcePath } = useResourcePath()
const contextRouteQuery = useRouteQuery('contextRouteQuery') as unknown as Ref<
Record<string, string>
>
Expand Down Expand Up @@ -281,7 +283,8 @@ export default defineComponent({
onPanZoomChanged,
preloadImageCount,
preview,
loading
loading,
getResourcePath
}
},
computed: {
Expand Down Expand Up @@ -343,9 +346,11 @@ export default defineComponent({

methods: {
setActiveFile(driveAliasAndItem: string) {
const space = unref(this.currentFileContext.space)

for (let i = 0; i < this.filteredFiles.length; i++) {
if (
unref(this.currentFileContext.space)?.getDriveAliasAndItem(this.filteredFiles[i]) ===
space?.getDriveAliasAndItem(this.getResourcePath(space, this.filteredFiles[i])) ===
driveAliasAndItem
) {
this.activeIndex = i
Expand Down
29 changes: 15 additions & 14 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default defineComponent({
const addMissingDriveAliasAndItem = async () => {
const id = unref(fileId)
const { space, path } = await getResourceContext(id)
const driveAliasAndItem = space.getDriveAliasAndItem({ path } as Resource)
const driveAliasAndItem = space.getDriveAliasAndItem(path)

if (isPersonalSpaceResource(space)) {
return router.push({
Expand Down Expand Up @@ -343,10 +343,14 @@ export default defineComponent({
const saveFileTask = useTask(function* () {
const newContent = unref(currentContent)
try {
const putFileContentsResponse = yield putFileContents(currentFileContext, {
content: newContent,
previousEntityTag: unref(currentETag)
})
const putFileContentsResponse = yield putFileContents(
currentFileContext,
{
content: newContent,
previousEntityTag: unref(currentETag)
},
unref(resource).parentFolderId
)
serverContent.value = newContent
currentETag.value = putFileContentsResponse.etag
resourcesStore.upsertResource(putFileContentsResponse)
Expand Down Expand Up @@ -405,15 +409,12 @@ export default defineComponent({
}
const editorOptions = configStore.options.editor
if (editorOptions.autosaveEnabled) {
autosaveIntervalId = setInterval(
async () => {
if (isDirty.value) {
await save()
autosavePopup()
}
},
(editorOptions.autosaveInterval || 120) * 1000
)
autosaveIntervalId = setInterval(async () => {
if (isDirty.value) {
await save()
autosavePopup()
}
}, (editorOptions.autosaveInterval || 120) * 1000)
}
})
onBeforeUnmount(() => {
Expand Down
8 changes: 4 additions & 4 deletions packages/web-pkg/src/components/CreateShortcutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ export default defineComponent({
unref(activeDropItemIndex) !== null
? unref(activeDropItemIndex)
: previous
? elements.length
: -1
? elements.length
: -1
const increment = previous ? -1 : 1

do {
Expand Down Expand Up @@ -367,9 +367,9 @@ export default defineComponent({
})

const content = `[InternetShortcut]\nURL=${sanitizedUrl}`
const path = urlJoin(unref(currentFolder).path, `${unref(inputFilename)}.url`)
const resource = await clientService.webdav.putFileContents(props.space, {
path,
fileId: unref(currentFolder).id,
fileName: `${unref(inputFilename)}.url`,
content
})
resourcesStore.upsertResource(resource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
>
<slot name="image" :resource="item" />
<resource-list-item
:key="`${item.path}-${resourceDomSelector(item)}-${item.thumbnail}`"
:key="`${item.id}-${resourceDomSelector(item)}-${item.thumbnail}`"
:resource="item"
:path-prefix="getPathPrefix(item)"
:is-path-displayed="arePathsDisplayed"
Expand Down
10 changes: 4 additions & 6 deletions packages/web-pkg/src/components/FilesList/ResourceTiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ import {
useResourcesStore,
useViewSizeMax,
useEmbedMode,
useCanBeOpenedWithSecureView
useCanBeOpenedWithSecureView,
useFolderLink
} from '../../composables'

type ResourceTileRef = ComponentPublicInstance<typeof ResourceTile>
Expand Down Expand Up @@ -223,6 +224,7 @@ export default defineComponent({
const { $gettext } = useGettext()
const resourcesStore = useResourcesStore()
const { canBeOpenedWithSecureView } = useCanBeOpenedWithSecureView()
const { getFolderLink } = useFolderLink()
const { emit } = context
const {
isEnabled: isEmbedModeEnabled,
Expand Down Expand Up @@ -267,11 +269,7 @@ export default defineComponent({
)
}
if (resource.type === 'folder') {
return resourceRouteResolver.createFolderLink({
path: resource.path,
fileId: resource.fileId,
resource: resource
})
return getFolderLink(resource)
}
return { path: '' }
}
Expand Down
Loading